Skip to content

Commit

Permalink
fix: Fixed error in dispatching sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Oct 7, 2023
1 parent 4ecb5ba commit 0799002
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions custom_components/octopus_energy/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ async def async_setup_main_sensors(hass, entry, async_add_entities):
has_intelligent_tariff = True

should_mock_intelligent_data = await async_mock_intelligent_data(hass)
if should_mock_intelligent_data:
# Pick the first meter if we're mocking our intelligent data
for point in account_info["electricity_meter_points"]:
tariff_code = get_active_tariff_code(now, point["agreements"])
if tariff_code is not None:
for meter in point["meters"]:
intelligent_mpan = point["mpan"]
intelligent_serial_number = meter["serial_number"]
break

if has_intelligent_tariff or should_mock_intelligent_data:
coordinator = hass.data[DOMAIN][DATA_INTELLIGENT_DISPATCHES_COORDINATOR]
client: OctopusEnergyApiClient = hass.data[DOMAIN][DATA_CLIENT]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def extra_state_attributes(self):
def is_on(self):
"""Determine if OE is currently dispatching energy."""
dispatches = self.coordinator.data if self.coordinator is not None else None
rates = self.coordinator.data.rates if self.coordinator is not None and self.coordinator.data is not None else None
rates = self._rates_coordinator.data.rates if self._rates_coordinator is not None and self._rates_coordinator.data is not None else None
if (dispatches is not None):
self._attributes["planned_dispatches"] = self.coordinator.data["planned"]
self._attributes["completed_dispatches"] = self.coordinator.data["completed"]
Expand Down

0 comments on commit 0799002

Please sign in to comment.