Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality from new app version #83

Merged
merged 8 commits into from
Jul 10, 2024
Merged

Add functionality from new app version #83

merged 8 commits into from
Jul 10, 2024

Conversation

dan-r
Copy link
Owner

@dan-r dan-r commented Jul 7, 2024

PR to add functionality related to the new version of the app.

So far this includes:

  • Charge slot list is provided by Ohme directly so is now fully accurate
  • Current and next slot sensors also benefit from the above
  • Switching from max charge to smart charge (and vice versa) now works more reliably due to API changes

Can I please get some people to test the latest beta release (howto) out? Mainly:

  • @HnabrU from Slot Active sensor incorrect state #80
  • @jeldwendean for the batpred stuff, as the way slots are fetched has changed
  • @andyvee69 as a sanity check - also incase I've missed anything you think is useful from the new app. I know you've had a bit longer to play around with it than I have!
  • Any one else who sees this!

@deanjesper
Copy link

I'll upgrade and have a play tonight 😀 @dan-r

@deanjesper
Copy link

I'm getting this message for Charge Slot Active:

Screenshot_20240707-185326

@deanjesper
Copy link

Interestingly the slots are blank too:

Screenshot_20240707-185627
Screenshot_20240707-185621

@deanjesper
Copy link

And Car Charging is 'Not charging' when it is

Screenshot_20240707-190012
Screenshot_20240707-190019

Sorry for the comment spam 😂

@dan-r
Copy link
Owner Author

dan-r commented Jul 7, 2024

Any errors in the logs?

@deanjesper
Copy link

Any errors in the logs?

Yeah quite a few

`Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:727
integration: Sensor (documentation, issues)
First occurred: 18:50:21 (3 occurrences)
Last logged: 18:57:33

ohme: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 727, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1296, in async_device_update
await self.async_update()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 529, in async_update
await self.coordinator.async_request_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 262, in async_request_refresh
await self._debounced_refresh.async_call()
File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 114, in async_call
await task
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 288, in async_refresh
await self._async_refresh(log_failures=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners
update_callback()
File "/config/custom_components/ohme/sensor.py", line 414, in _handle_coordinator_update
self._state = next_slot(self.coordinator.data)['end']
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/ohme/utils.py", line 11, in next_slot
slots = slot_list(data)
^^^^^^^^^^^^^^^
File "/config/custom_components/ohme/utils.py", line 37, in slot_list
wh_tally = data['batterySocBefore']['wh'] # Get the wh value we start from
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
TypeError: 'NoneType' object is not subscriptable`

`This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/ohme/sensor.py:471
integration: Ohme (documentation, issues)
First occurred: 18:46:31 (2 occurrences)
Last logged: 18:47:01

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 255, in _handle_refresh_interval
await self._async_refresh(log_failures=True, scheduled=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners
update_callback()
File "/config/custom_components/ohme/sensor.py", line 471, in _handle_coordinator_update
self._state = reduce(lambda acc, slot: acc + f"{slot['start'].strftime('%H:%M')}-{slot['end'].strftime('%H:%M')}, ", slots, "")[:-2]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: reduce() arg 2 must support iteration`

`Logger: homeassistant.components.binary_sensor
Source: helpers/entity_platform.py:912
integration: Binary Sensor (documentation, issues)
First occurred: 18:50:21 (3 occurrences)
Last logged: 18:57:33

Error adding entity binary_sensor.ohme_slot_active for domain binary_sensor with platform ohme
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1362, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1133, in _async_write_ha_state
state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1072, in __async_calculate_state
if extra_state_attributes := self.extra_state_attributes:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/ohme/binary_sensor.py", line 299, in extra_state_attributes
"planned_dispatches": [x for x in slots if not x['end'] or x['end'] > now],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable`

@dan-r
Copy link
Owner Author

dan-r commented Jul 7, 2024

@deanjesper any better with the latest beta?

@deanjesper
Copy link

@deanjesper any better with the latest beta?

I've got a Predbat error now, looks like the completedDispatches timestamp for 18:48 has a decimal point on the seconds

Error: Exception raised time data '2024-07-07T18:48:15.663000+01:00' does not match format '%Y-%m-%dT%H:%M:%S%z'

Planned dispatches

  • start: '2024-07-07T21:15:00+01:00'
    end: '2024-07-07T21:30:00+01:00'
    charge_in_kwh: -0.744
    source: smart-charge
    location: null
  • start: '2024-07-07T21:30:00+01:00'
    end: '2024-07-07T22:00:00+01:00'
    charge_in_kwh: -1.001
    source: smart-charge
    location: null
  • start: '2024-07-07T23:00:00+01:00'
    end: '2024-07-08T05:32:08+01:00'
    charge_in_kwh: -43.068
    source: smart-charge
    location: null
    Completed dispatches
  • start: '2024-07-07T18:48:15.663000+01:00'
    end: '2024-07-07T19:00:00+01:00'
    charge_in_kwh: -0.803
    source: smart-charge
    location: null
  • start: '2024-07-07T19:15:00+01:00'
    end: '2024-07-07T20:00:00+01:00'
    charge_in_kwh: -2.543
    source: smart-charge
    location: null

@dan-r
Copy link
Owner Author

dan-r commented Jul 7, 2024

What about now?

@deanjesper
Copy link

What about now?

All good now! Nice work. I'll see how it is in the morning when I wake up and feed back!

@deanjesper
Copy link

Just woke up and my car is still charging and I've been given more slots but the integration can't see them, odd. Another error too:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/ohme/utils.py:46
integration: Ohme (documentation, issues)
First occurred: 03:02:14 (422 occurrences)
Last logged: 06:32:45

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 255, in _handle_refresh_interval
await self._async_refresh(log_failures=True, scheduled=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners
update_callback()
File "/config/custom_components/ohme/sensor.py", line 414, in _handle_coordinator_update
self._state = next_slot(self.coordinator.data)['end']
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/ohme/utils.py", line 11, in next_slot
slots = slot_list(data)
^^^^^^^^^^^^^^^
File "/config/custom_components/ohme/utils.py", line 46, in slot_list
"charge_in_kwh": -((slot['estimatedSoc']['wh'] - wh_tally) / 1000), # Work out how much we add in just this slot
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'

Screenshot_20240708-063442
Screenshot_20240708-063241
Screenshot_20240708-063249

Screenshot_20240708-063259

The car should be charged in the next few minutes so not sure why it's decided to give more slots but what's odd is the integration thinks there are no more.

@deanjesper
Copy link

Another error when I paused the charge in the Ohme app and reloaded the integration in HA

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:727
integration: Sensor (documentation, issues)
First occurred: 06:37:26 (1 occurrences)
Last logged: 06:37:26

ohme: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 727, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1296, in async_device_update
await self.async_update()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 529, in async_update
await self.coordinator.async_request_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 262, in async_request_refresh
await self._debounced_refresh.async_call()
File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 114, in async_call
await task
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 288, in async_refresh
await self._async_refresh(log_failures=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners
update_callback()
File "/config/custom_components/ohme/sensor.py", line 414, in _handle_coordinator_update
self._state = next_slot(self.coordinator.data)['end']
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/ohme/utils.py", line 11, in next_slot
slots = slot_list(data)
^^^^^^^^^^^^^^^
File "/config/custom_components/ohme/utils.py", line 46, in slot_list
"charge_in_kwh": -((slot['estimatedSoc']['wh'] - wh_tally) / 1000), # Work out how much we add in just this slot
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'

@dan-r
Copy link
Owner Author

dan-r commented Jul 8, 2024

Right that should be fixed now

@deanjesper
Copy link

Right that should be fixed now

I'll give it a go tonight 😊

@deanjesper
Copy link

Right that should be fixed now

I'll give it a go tonight 😊

All good, no errors!

@dan-r
Copy link
Owner Author

dan-r commented Jul 10, 2024

Thanks for your testing! I'll publish that now look out for feedback once more people start to use it.

@dan-r dan-r merged commit 7bd0d37 into main Jul 10, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants