From 31360056bc8d95098a85fe6bc349c8a3bb84f415 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Fri, 3 Nov 2023 18:29:42 +0000 Subject: [PATCH] feat: Updated saving session sensor to include account id. This is to support future functionality BREAKING CHANGE: Any references to saving session entities will need to be updated based on name change --- custom_components/octopus_energy/binary_sensor.py | 3 ++- .../octopus_energy/saving_sessions/saving_sessions.py | 8 +++++--- .../octopus_energy/target_rates/target_rate.py | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/custom_components/octopus_energy/binary_sensor.py b/custom_components/octopus_energy/binary_sensor.py index c8fbcbf4..3726c665 100644 --- a/custom_components/octopus_energy/binary_sensor.py +++ b/custom_components/octopus_energy/binary_sensor.py @@ -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"]: diff --git a/custom_components/octopus_energy/saving_sessions/saving_sessions.py b/custom_components/octopus_energy/saving_sessions/saving_sessions.py index ba7fd387..f8c3453e 100644 --- a/custom_components/octopus_energy/saving_sessions/saving_sessions.py +++ b/custom_components/octopus_energy/saving_sessions/saving_sessions.py @@ -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 = { @@ -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): diff --git a/custom_components/octopus_energy/target_rates/target_rate.py b/custom_components/octopus_energy/target_rates/target_rate.py index 1917d847..d433fa55 100644 --- a/custom_components/octopus_energy/target_rates/target_rate.py +++ b/custom_components/octopus_energy/target_rates/target_rate.py @@ -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,