diff --git a/custom_components/ohme/api_client.py b/custom_components/ohme/api_client.py index 1dc3b79..096d472 100644 --- a/custom_components/ohme/api_client.py +++ b/custom_components/ohme/api_client.py @@ -200,8 +200,10 @@ async def async_apply_session_rule(self, max_price=None, target_time=None, targe """Apply rule to ongoing charge/stop max charge.""" # Check every property. If we've provided it, use that. If not, use the existing. if max_price is None: - max_price = self._last_rule['settings'][0]['enabled'] if 'settings' in self._last_rule and len( - self._last_rule['settings']) > 1 else False + if 'settings' in self._last_rule and self._last_rule['settings'] is not None and len(self._last_rule['settings']) > 1: + max_price = self._last_rule['settings'][0]['enabled'] + else: + max_price = False if target_percent is None: target_percent = self._last_rule['targetPercent'] if 'targetPercent' in self._last_rule else 80 diff --git a/custom_components/ohme/const.py b/custom_components/ohme/const.py index 946790f..0aa3744 100644 --- a/custom_components/ohme/const.py +++ b/custom_components/ohme/const.py @@ -1,7 +1,7 @@ """Component constants""" DOMAIN = "ohme" USER_AGENT = "dan-r-homeassistant-ohme" -INTEGRATION_VERSION = "0.8.1" +INTEGRATION_VERSION = "0.8.3" CONFIG_VERSION = 1 ENTITY_TYPES = ["sensor", "binary_sensor", "switch", "button", "number", "time"] diff --git a/custom_components/ohme/number.py b/custom_components/ohme/number.py index af6a608..e076b5e 100644 --- a/custom_components/ohme/number.py +++ b/custom_components/ohme/number.py @@ -252,7 +252,10 @@ def icon(self): def _handle_coordinator_update(self) -> None: """Get value from data returned from API by coordinator""" if self.coordinator.data is not None: - self._state = self.coordinator.data["userSettings"]["chargeSettings"][0]["value"] + try: + self._state = self.coordinator.data["userSettings"]["chargeSettings"][0]["value"] + except: + self._state = None self.async_write_ha_state() @property diff --git a/custom_components/ohme/sensor.py b/custom_components/ohme/sensor.py index 091e29b..803ebb8 100644 --- a/custom_components/ohme/sensor.py +++ b/custom_components/ohme/sensor.py @@ -525,10 +525,11 @@ def icon(self): def _handle_coordinator_update(self) -> None: """Get value from data returned from API by coordinator""" if self.coordinator.data and self.coordinator.data['car'] and self.coordinator.data['car']['batterySoc']: - new_state = self.coordinator.data['car']['batterySoc']['percent'] or self.coordinator.data['batterySoc']['percent'] + self._state = self.coordinator.data['car']['batterySoc']['percent'] or self.coordinator.data['batterySoc']['percent'] - # Don't let it go backwards unless to 0 - self._state = 0 if new_state == 0 else max(new_state, self._state or 0) + # Don't allow negatives + if isinstance(self._state, int) and self._state < 0: + self._state = 0 self._last_updated = utcnow() self.async_write_ha_state()