Skip to content

Commit

Permalink
feat: Updated saving session sensor to include account id. This is to…
Browse files Browse the repository at this point in the history
… support future functionality

BREAKING CHANGE:
Any references to saving session entities will need to be updated based on name change
  • Loading branch information
BottlecapDave committed Nov 3, 2023
1 parent 57e3d79 commit 3136005
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion custom_components/octopus_energy/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ async def async_setup_main_sensors(hass, entry, async_add_entities):
await saving_session_coordinator.async_config_entry_first_refresh()

account_info = hass.data[DOMAIN][DATA_ACCOUNT]
account_id = hass.data[DOMAIN][DATA_ACCOUNT_ID]

now = utcnow()
has_intelligent_tariff = False
intelligent_mpan = None
intelligent_serial_number = None
entities = [OctopusEnergySavingSessions(hass, saving_session_coordinator)]
entities = [OctopusEnergySavingSessions(hass, saving_session_coordinator, account_id)]
if len(account_info["electricity_meter_points"]) > 0:

for point in account_info["electricity_meter_points"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
current_saving_sessions_event,
get_next_saving_sessions_event
)
from ..utils import account_id_to_unique_key

_LOGGER = logging.getLogger(__name__)

class OctopusEnergySavingSessions(CoordinatorEntity, BinarySensorEntity, RestoreEntity):
"""Sensor for determining if a saving session is active."""

def __init__(self, hass: HomeAssistant, coordinator):
def __init__(self, hass: HomeAssistant, coordinator, account_id: str):
"""Init sensor."""

CoordinatorEntity.__init__(self, coordinator)

self._account_id = account_id
self._state = None
self._events = []
self._attributes = {
Expand All @@ -39,12 +41,12 @@ def __init__(self, hass: HomeAssistant, coordinator):
@property
def unique_id(self):
"""The id of the sensor."""
return f"octopus_energy_saving_sessions"
return f"octopus_energy_{account_id_to_unique_key(self._account_id)}_saving_sessions"

@property
def name(self):
"""Name of the sensor."""
return f"Octopus Energy Saving Session"
return f"Octopus Energy {self._account_id} Saving Session"

@property
def icon(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
CONFIG_TARGET_TYPE,
CONFIG_TARGET_START_TIME,
CONFIG_TARGET_END_TIME,
CONFIG_TARGET_MPAN,
CONFIG_TARGET_ROLLING_TARGET,
CONFIG_TARGET_LAST_RATES,
CONFIG_TARGET_INVERT_TARGET_RATES,
Expand Down

0 comments on commit 3136005

Please sign in to comment.