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 d946220..21428d1 100644 --- a/custom_components/hsem/custom_sensors/house_consumption_power_sensor.py +++ b/custom_components/hsem/custom_sensors/house_consumption_power_sensor.py @@ -4,9 +4,9 @@ from homeassistant.components.sensor import SensorEntity from homeassistant.helpers.event import async_track_state_change_event -from ..const import DOMAIN, ICON,DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER +from ..const import DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER, DOMAIN, ICON from ..entity import HSEMEntity -from ..utils.misc import get_config_value, convert_to_float, convert_to_boolean +from ..utils.misc import convert_to_boolean, convert_to_float, get_config_value _LOGGER = logging.getLogger(__name__) @@ -24,7 +24,9 @@ def __init__(self, config_entry, hour_start, hour_end): self._hsem_ev_charger_power = None self._hsem_ev_charger_power_state = 0.0 self._hsem_house_power_includes_ev_charger_power = None - self._hsem_house_power_includes_ev_charger_power_state = DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER + self._hsem_house_power_includes_ev_charger_power_state = ( + DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER + ) self._hour_start = hour_start self._hour_end = hour_end self._unique_id = ( @@ -88,7 +90,9 @@ def _update_settings(self): get_config_value(self._config_entry, "hsem_ev_charger_power") ) self.set_hsem_house_power_includes_ev_charger_power( - get_config_value(self._config_entry, "hsem_house_power_includes_ev_charger_power") + get_config_value( + self._config_entry, "hsem_house_power_includes_ev_charger_power" + ) ) async def async_added_to_hass(self): @@ -142,14 +146,15 @@ async def _handle_update(self, event): convert_to_float(state.state), 2 ) else: - _LOGGER.warning( - f"Sensor {self._hsem_ev_charger_power} not found." - ) + _LOGGER.warning(f"Sensor {self._hsem_ev_charger_power} not found.") state = None if now.hour == self._hour_start: if self._hsem_house_power_includes_ev_charger_power: - self._state = float(self._hsem_house_consumption_power_state - self._hsem_ev_charger_power_state) + self._state = float( + self._hsem_house_consumption_power_state + - self._hsem_ev_charger_power_state + ) else: self._state = float(self._hsem_house_consumption_power_state) diff --git a/custom_components/hsem/sensor.py b/custom_components/hsem/sensor.py index d4ffa50..06167be 100644 --- a/custom_components/hsem/sensor.py +++ b/custom_components/hsem/sensor.py @@ -114,7 +114,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # Wait for power, energy and energy average sensors to be set up power_sensors = await async_setup_power_sensors( - config_entry, hsem_house_consumption_power, hsem_ev_charger_power, hsem_house_power_includes_ev_charger_power + config_entry, + hsem_house_consumption_power, + hsem_ev_charger_power, + hsem_house_power_includes_ev_charger_power, ) energy_sensors = await async_setup_energy_sensors(config_entry) @@ -140,7 +143,12 @@ async def async_unload_entry(hass, entry): return False -async def async_setup_power_sensors(config_entry, hsem_house_consumption_power, hsem_ev_charger_power, hsem_house_power_includes_ev_charger_power): +async def async_setup_power_sensors( + config_entry, + hsem_house_consumption_power, + hsem_ev_charger_power, + hsem_house_power_includes_ev_charger_power, +): """Set up house consumption power sensors for each hour block.""" sensors = [] for hour in range(24): @@ -149,7 +157,9 @@ async def async_setup_power_sensors(config_entry, hsem_house_consumption_power, sensor = HouseConsumptionPowerSensor(config_entry, hour_start, hour_end) sensor.set_hsem_house_consumption_power(hsem_house_consumption_power) sensor.set_hsem_ev_charger_power(hsem_ev_charger_power) - sensor.set_hsem_house_power_includes_ev_charger_power(hsem_house_power_includes_ev_charger_power) + sensor.set_hsem_house_power_includes_ev_charger_power( + hsem_house_power_includes_ev_charger_power + ) sensors.append(sensor) return sensors