diff --git a/custom_components/hsem/custom_sensors/house_consumption_power_sensor.py b/custom_components/hsem/custom_sensors/house_consumption_power_sensor.py index a769c9a..7889b7d 100644 --- a/custom_components/hsem/custom_sensors/house_consumption_power_sensor.py +++ b/custom_components/hsem/custom_sensors/house_consumption_power_sensor.py @@ -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 ( @@ -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" ) diff --git a/custom_components/hsem/custom_sensors/working_mode_sensor.py b/custom_components/hsem/custom_sensors/working_mode_sensor.py index f49f9fe..d28c07c 100644 --- a/custom_components/hsem/custom_sensors/working_mode_sensor.py +++ b/custom_components/hsem/custom_sensors/working_mode_sensor.py @@ -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 @@ -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", @@ -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", diff --git a/custom_components/hsem/utils/misc.py b/custom_components/hsem/utils/misc.py index b5cd2ce..bbb0ee0 100644 --- a/custom_components/hsem/utils/misc.py +++ b/custom_components/hsem/utils/misc.py @@ -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 @@ -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."""