Skip to content

Commit

Permalink
Run formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 18, 2024
1 parent e7e1e9e commit 020e19f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
17 changes: 10 additions & 7 deletions custom_components/hsem/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
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,
DEFAULT_HSEM_MORNING_ENERGY_NEED,
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,
)
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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": {}}),

}
)

Expand Down Expand Up @@ -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"
)
Expand Down
6 changes: 4 additions & 2 deletions custom_components/hsem/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
47 changes: 22 additions & 25 deletions custom_components/hsem/custom_sensors/working_mode_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion custom_components/hsem/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 020e19f

Please sign in to comment.