Skip to content

Commit

Permalink
Remove one way on SOC and fix max_price related None issues (#81)
Browse files Browse the repository at this point in the history
* Remove one way on SOC

* Fix max_price related None issues

* Bump version

* Prevent negative SOC
  • Loading branch information
dan-r committed Jun 13, 2024
1 parent a9d2d94 commit 35968b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions custom_components/ohme/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ohme/const.py
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
5 changes: 4 additions & 1 deletion custom_components/ohme/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions custom_components/ohme/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 35968b7

Please sign in to comment.