From 020e19f82861dcdfbfbf1c8111bbf7078652506f Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 08:52:39 +0000 Subject: [PATCH] Run formatting --- custom_components/hsem/config_flow.py | 17 ++++--- custom_components/hsem/const.py | 6 ++- .../custom_sensors/working_mode_sensor.py | 47 +++++++++---------- custom_components/hsem/sensor.py | 1 - 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/custom_components/hsem/config_flow.py b/custom_components/hsem/config_flow.py index 4c3bda5..72ef0cb 100644 --- a/custom_components/hsem/config_flow.py +++ b/custom_components/hsem/config_flow.py @@ -6,11 +6,15 @@ from homeassistant.helpers.selector import selector from .const import ( + DEFAULT_HSEM_BATTERY_CONVERSION_LOSS, DEFAULT_HSEM_BATTERY_MAX_CAPACITY, DEFAULT_HSEM_ENERGI_DATA_SERVICE_EXPORT, DEFAULT_HSEM_ENERGI_DATA_SERVICE_IMPORT, + DEFAULT_HSEM_EV_CHARGER_POWER, DEFAULT_HSEM_EV_CHARGER_STATUS, DEFAULT_HSEM_HOUSE_CONSUMPTION_POWER, + DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER, + DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_MAXIMUM_CHARGING_POWER, DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_STATE_OF_CAPACITY, DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_WORKING_MODE, DEFAULT_HSEM_HUAWEI_SOLAR_INVERTER_ACTIVE_POWER_CONTROL, @@ -18,10 +22,6 @@ DEFAULT_HSEM_SOLAR_PRODUCTION_POWER, DEFAULT_HSEM_SOLCAST_PV_FORECAST_FORECAST_TODAY, DEFAULT_HSEM_SOLCAST_PV_FORECAST_FORECAST_TOMORROW, - DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER, - DEFAULT_HSEM_EV_CHARGER_POWER, - DEFAULT_HSEM_BATTERY_CONVERSION_LOSS, - DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_MAXIMUM_CHARGING_POWER, DOMAIN, NAME, ) @@ -124,7 +124,9 @@ async def async_step_huawei_solar(self, user_input=None): self._errors["hsem_huawei_solar_inverter_active_power_control"] = ( "required" ) - elif not user_input.get("hsem_huawei_solar_batteries_maximum_charging_power"): + elif not user_input.get( + "hsem_huawei_solar_batteries_maximum_charging_power" + ): self._errors["hsem_huawei_solar_batteries_maximum_charging_power"] = ( "required" ) @@ -334,7 +336,6 @@ async def async_step_misc(self, user_input=None): "hsem_house_power_includes_ev_charger_power", default=DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER, ): selector({"boolean": {}}), - } ) @@ -461,7 +462,9 @@ async def async_step_huawei_solar(self, user_input=None): self._errors["hsem_huawei_solar_inverter_active_power_control"] = ( "required" ) - elif not user_input.get("hsem_huawei_solar_batteries_maximum_charging_power"): + elif not user_input.get( + "hsem_huawei_solar_batteries_maximum_charging_power" + ): self._errors["hsem_huawei_solar_batteries_maximum_charging_power"] = ( "required" ) diff --git a/custom_components/hsem/const.py b/custom_components/hsem/const.py index 70a325e..ebd76be 100644 --- a/custom_components/hsem/const.py +++ b/custom_components/hsem/const.py @@ -74,10 +74,12 @@ DEFAULT_HSEM_HOUSE_POWER_INCLUDES_EV_CHARGER_POWER = True # Default sensor entity ID for EV charger power -DEFAULT_HSEM_EV_CHARGER_POWER = 'sensor.go_echarger_222819_nrg_12' +DEFAULT_HSEM_EV_CHARGER_POWER = "sensor.go_echarger_222819_nrg_12" # Default conversion loss for battery charging DEFAULT_HSEM_BATTERY_CONVERSION_LOSS = 10 # Default sensor entity ID for battery charging power -DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_MAXIMUM_CHARGING_POWER = 'number.battery_maximum_charging_power' +DEFAULT_HSEM_HUAWEI_SOLAR_BATTERIES_MAXIMUM_CHARGING_POWER = ( + "number.battery_maximum_charging_power" +) diff --git a/custom_components/hsem/custom_sensors/working_mode_sensor.py b/custom_components/hsem/custom_sensors/working_mode_sensor.py index ca2524d..29fb4b5 100644 --- a/custom_components/hsem/custom_sensors/working_mode_sensor.py +++ b/custom_components/hsem/custom_sensors/working_mode_sensor.py @@ -437,9 +437,9 @@ async def _handle_update(self, event): self._hsem_huawei_solar_batteries_maximum_charging_power ) if state: - self._hsem_huawei_solar_batteries_maximum_charging_power_state = round(convert_to_float( - state.state - ), 0) + self._hsem_huawei_solar_batteries_maximum_charging_power_state = round( + convert_to_float(state.state), 0 + ) else: _LOGGER.warning( f"Sensor {self._hsem_huawei_solar_batteries_maximum_charging_power} not found." @@ -448,17 +448,13 @@ async def _handle_update(self, event): # Fetch the current value from the battery maximum charging power sensor if self._hsem_ev_charger_power: - state = self.hass.states.get( - self._hsem_ev_charger_power - ) + state = self.hass.states.get(self._hsem_ev_charger_power) if state: - self._hsem_ev_charger_power_state = round(convert_to_float( - state.state - ), 2) - else: - _LOGGER.warning( - f"Sensor {self._hsem_ev_charger_power} not found." + self._hsem_ev_charger_power_state = round( + convert_to_float(state.state), 2 ) + else: + _LOGGER.warning(f"Sensor {self._hsem_ev_charger_power} not found.") state = None # Calculate the net consumption without the EV charger power @@ -467,35 +463,36 @@ async def _handle_update(self, event): self._hsem_solar_production_power_state - (self._hsem_house_consumption_power_state) ) - self._hsem_net_consumption = ( - self._hsem_solar_production_power_state - - (self._hsem_house_consumption_power_state - self._hsem_ev_charger_power_state) + self._hsem_net_consumption = self._hsem_solar_production_power_state - ( + self._hsem_house_consumption_power_state + - self._hsem_ev_charger_power_state ) else: self._hsem_net_consumption_with_ev = ( self._hsem_solar_production_power_state - - (self._hsem_house_consumption_power_state + self._hsem_ev_charger_power_state) + - ( + self._hsem_house_consumption_power_state + + self._hsem_ev_charger_power_state + ) ) self._hsem_net_consumption = ( self._hsem_solar_production_power_state - self._hsem_house_consumption_power_state ) - # Calculate the remaining battery capacity - if self._hsem_battery_max_capacity is not None and self._hsem_huawei_solar_batteries_state_of_capacity_state is not None: + if ( + self._hsem_battery_max_capacity is not None + and self._hsem_huawei_solar_batteries_state_of_capacity_state is not None + ): self._hsem_battery_remaining_charge = round( ( - ( - 100 - - - self._hsem_huawei_solar_batteries_state_of_capacity_state - - ) + (100 - self._hsem_huawei_solar_batteries_state_of_capacity_state) / 100 * self._hsem_battery_max_capacity ), - 2) + 2, + ) # calculate the hourly data from power sensors await self.async_calculate_hourly_data() diff --git a/custom_components/hsem/sensor.py b/custom_components/hsem/sensor.py index 08dbb94..3ce5384 100644 --- a/custom_components/hsem/sensor.py +++ b/custom_components/hsem/sensor.py @@ -112,7 +112,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): hsem_house_power_includes_ev_charger_power ) - # 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