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 de93c3d commit 1853b43
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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 = (
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 13 additions & 3 deletions custom_components/hsem/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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

Expand Down

0 comments on commit 1853b43

Please sign in to comment.