Skip to content

Commit

Permalink
feat: updated intelligent sensors to include account id. This is to s…
Browse files Browse the repository at this point in the history
…upport future functionality

BREAKING CHANGE:
Any references to intelligent sensors will need to be updated based on name changes
  • Loading branch information
BottlecapDave committed Nov 3, 2023
1 parent f135762 commit 57e3d79
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion custom_components/octopus_energy/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def async_setup_main_sensors(hass, entry, async_add_entities):
device = await client.async_get_intelligent_device(account_id)

electricity_rate_coordinator = hass.data[DOMAIN][DATA_ELECTRICITY_RATES_COORDINATOR_KEY.format(intelligent_mpan, intelligent_serial_number)]
entities.append(OctopusEnergyIntelligentDispatching(hass, coordinator, electricity_rate_coordinator, intelligent_mpan, device))
entities.append(OctopusEnergyIntelligentDispatching(hass, coordinator, electricity_rate_coordinator, intelligent_mpan, device, account_id))

if len(entities) > 0:
async_add_entities(entities, True)
Expand Down
5 changes: 3 additions & 2 deletions custom_components/octopus_energy/intelligent/bump_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..api_client import OctopusEnergyApiClient
from . import is_in_bump_charge
from ..coordinators.intelligent_dispatches import IntelligentDispatchesCoordinatorResult
from ..utils import account_id_to_unique_key

_LOGGER = logging.getLogger(__name__)

Expand All @@ -35,12 +36,12 @@ def __init__(self, hass: HomeAssistant, coordinator, client: OctopusEnergyApiCli
@property
def unique_id(self):
"""The id of the sensor."""
return f"octopus_energy_intelligent_bump_charge"
return f"octopus_energy_{account_id_to_unique_key(self._account_id)}_intelligent_bump_charge"

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

@property
def icon(self):
Expand Down
5 changes: 3 additions & 2 deletions custom_components/octopus_energy/intelligent/charge_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .base import OctopusEnergyIntelligentSensor
from ..api_client import OctopusEnergyApiClient
from ..coordinators.intelligent_settings import IntelligentCoordinatorResult
from ..utils import account_id_to_unique_key

_LOGGER = logging.getLogger(__name__)

Expand All @@ -36,12 +37,12 @@ def __init__(self, hass: HomeAssistant, coordinator, client: OctopusEnergyApiCli
@property
def unique_id(self):
"""The id of the sensor."""
return f"octopus_energy_intelligent_charge_limit"
return f"octopus_energy_{account_id_to_unique_key(self._account_id)}_intelligent_charge_limit"

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

@property
def icon(self):
Expand Down
8 changes: 5 additions & 3 deletions custom_components/octopus_energy/intelligent/dispatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@

from .base import OctopusEnergyIntelligentSensor
from ..coordinators.intelligent_dispatches import IntelligentDispatchesCoordinatorResult
from ..utils import account_id_to_unique_key

_LOGGER = logging.getLogger(__name__)

class OctopusEnergyIntelligentDispatching(CoordinatorEntity, BinarySensorEntity, OctopusEnergyIntelligentSensor, RestoreEntity):
"""Sensor for determining if an intelligent is dispatching."""

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

CoordinatorEntity.__init__(self, coordinator)
OctopusEnergyIntelligentSensor.__init__(self, device)

self._rates_coordinator = rates_coordinator
self._mpan = mpan
self._account_id = account_id
self._state = None
self._attributes = {
"planned_dispatches": [],
Expand All @@ -50,12 +52,12 @@ def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, mpan, de
@property
def unique_id(self):
"""The id of the sensor."""
return f"octopus_energy_intelligent_dispatching"
return f"octopus_energy_{account_id_to_unique_key(self._account_id)}_intelligent_dispatching"

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

@property
def icon(self):
Expand Down
5 changes: 3 additions & 2 deletions custom_components/octopus_energy/intelligent/ready_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .base import OctopusEnergyIntelligentSensor
from ..api_client import OctopusEnergyApiClient
from ..coordinators.intelligent_settings import IntelligentCoordinatorResult
from ..utils import account_id_to_unique_key

_LOGGER = logging.getLogger(__name__)

Expand All @@ -35,12 +36,12 @@ def __init__(self, hass: HomeAssistant, coordinator, client: OctopusEnergyApiCli
@property
def unique_id(self):
"""The id of the sensor."""
return f"octopus_energy_intelligent_ready_time"
return f"octopus_energy_{account_id_to_unique_key(self._account_id)}_intelligent_ready_time"

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

@property
def icon(self):
Expand Down
5 changes: 3 additions & 2 deletions custom_components/octopus_energy/intelligent/smart_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .base import OctopusEnergyIntelligentSensor
from ..api_client import OctopusEnergyApiClient
from ..coordinators.intelligent_settings import IntelligentCoordinatorResult
from ..utils import account_id_to_unique_key

_LOGGER = logging.getLogger(__name__)

Expand All @@ -34,12 +35,12 @@ def __init__(self, hass: HomeAssistant, coordinator, client: OctopusEnergyApiCli
@property
def unique_id(self):
"""The id of the sensor."""
return f"octopus_energy_intelligent_smart_charge"
return f"octopus_energy_{account_id_to_unique_key(self._account_id)}_intelligent_smart_charge"

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

@property
def icon(self):
Expand Down
5 changes: 4 additions & 1 deletion custom_components/octopus_energy/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ def private_rates_to_public_rates(rates: list):

new_rates.append(new_rate)

return new_rates
return new_rates

def account_id_to_unique_key(account_id: str):
return account_id.replace('-', '_')

0 comments on commit 57e3d79

Please sign in to comment.