Skip to content

Commit

Permalink
fix: ev options flow failure (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
woopstar authored Dec 18, 2024
1 parent af6147c commit d3ac134
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import logging
from datetime import datetime, timedelta

import voluptuous as vol
from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor.const import SensorDeviceClass
from homeassistant.components.utility_meter.const import (
Expand Down Expand Up @@ -184,6 +185,9 @@ def _update_settings(self):
self._config_entry, "hsem_ev_charger_power"
)

if self._hsem_ev_charger_power == vol.UNDEFINED:
self._hsem_ev_charger_power = None

self._hsem_house_power_includes_ev_charger_power = get_config_value(
self._config_entry, "hsem_house_power_includes_ev_charger_power"
)
Expand Down
9 changes: 9 additions & 0 deletions custom_components/hsem/custom_sensors/working_mode_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
from datetime import datetime, timedelta

import voluptuous as vol
from homeassistant.components.sensor import SensorEntity
from homeassistant.core import State
from homeassistant.helpers.event import async_track_time_interval
Expand Down Expand Up @@ -200,6 +201,10 @@ def _update_settings(self):
self._hsem_ev_charger_status = get_config_value(
self._config_entry, "hsem_ev_charger_status"
)

if self._hsem_ev_charger_status == vol.UNDEFINED:
self._hsem_ev_charger_status = None

self._hsem_solcast_pv_forecast_forecast_today = get_config_value(
self._config_entry,
"hsem_solcast_pv_forecast_forecast_today",
Expand All @@ -224,6 +229,10 @@ def _update_settings(self):
self._config_entry,
"hsem_ev_charger_power",
)

if self._hsem_ev_charger_power == vol.UNDEFINED:
self._hsem_ev_charger_power = None

self._hsem_batteries_conversion_loss = get_config_value(
self._config_entry,
"hsem_batteries_conversion_loss",
Expand Down
8 changes: 7 additions & 1 deletion custom_components/hsem/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import entity_registry as er
from sqlalchemy import null

from custom_components.hsem.const import DEFAULT_CONFIG_VALUES, DOMAIN

Expand Down Expand Up @@ -53,10 +54,15 @@ def get_config_value(config_entry, key):
if config_entry is None:
return None

return config_entry.options.get(
data = config_entry.options.get(
key, config_entry.data.get(key, DEFAULT_CONFIG_VALUES[key])
)

if data is null or data is None:
return DEFAULT_CONFIG_VALUES[key]

return data


def convert_to_float(state) -> float:
"""Resolve the input sensor state and cast it to a float."""
Expand Down

0 comments on commit d3ac134

Please sign in to comment.