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

Remove one way on SOC and fix max_price related None issues #81

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading