From 53db610134fbb4356603b76634c56f71304280f7 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Sun, 28 Apr 2024 08:10:02 +0100 Subject: [PATCH] fix: Accounted when intelligent device can come back with null data from OE --- custom_components/octopus_energy/__init__.py | 9 ++-- .../octopus_energy/api_client/__init__.py | 25 +++++----- .../api_client/intelligent_device.py | 29 ++++++++++++ .../octopus_energy/binary_sensor.py | 5 +- .../coordinators/intelligent_dispatches.py | 6 ++- .../octopus_energy/intelligent/__init__.py | 21 +++++---- .../octopus_energy/intelligent/base.py | 9 ++-- .../octopus_energy/intelligent/dispatching.py | 47 ++++++++++--------- custom_components/octopus_energy/number.py | 5 +- custom_components/octopus_energy/switch.py | 5 +- custom_components/octopus_energy/time.py | 5 +- ...st_async_refresh_intelligent_dispatches.py | 42 +++++++++++++++++ 12 files changed, 146 insertions(+), 62 deletions(-) create mode 100644 custom_components/octopus_energy/api_client/intelligent_device.py diff --git a/custom_components/octopus_energy/__init__.py b/custom_components/octopus_energy/__init__.py index a4ae2a01..2842cbc5 100644 --- a/custom_components/octopus_energy/__init__.py +++ b/custom_components/octopus_energy/__init__.py @@ -254,9 +254,10 @@ async def async_setup_dependencies(hass, config): else: intelligent_device = await client.async_get_intelligent_device(account_id) - hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] = intelligent_device - hass.data[DOMAIN][account_id][DATA_INTELLIGENT_MPAN] = intelligent_mpan - hass.data[DOMAIN][account_id][DATA_INTELLIGENT_SERIAL_NUMBER] = intelligent_serial_number + if intelligent_device is not None: + hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] = intelligent_device + hass.data[DOMAIN][account_id][DATA_INTELLIGENT_MPAN] = intelligent_mpan + hass.data[DOMAIN][account_id][DATA_INTELLIGENT_SERIAL_NUMBER] = intelligent_serial_number for point in account_info["electricity_meter_points"]: # We only care about points that have active agreements @@ -268,7 +269,7 @@ async def async_setup_dependencies(hass, config): is_export_meter = meter["is_export"] is_smart_meter = meter["is_smart_meter"] tariff_override = await async_get_tariff_override(hass, mpan, serial_number) - planned_dispatches_supported = get_intelligent_features(intelligent_device["provider"]).planned_dispatches_supported if intelligent_device is not None else True + planned_dispatches_supported = get_intelligent_features(intelligent_device.provider).planned_dispatches_supported if intelligent_device is not None else True await async_setup_electricity_rates_coordinator(hass, account_id, mpan, serial_number, is_smart_meter, is_export_meter, planned_dispatches_supported, tariff_override) await async_setup_account_info_coordinator(hass, account_id) diff --git a/custom_components/octopus_energy/api_client/__init__.py b/custom_components/octopus_energy/api_client/__init__.py index 01ab1661..d24d8439 100644 --- a/custom_components/octopus_energy/api_client/__init__.py +++ b/custom_components/octopus_energy/api_client/__init__.py @@ -14,6 +14,7 @@ ) +from .intelligent_device import IntelligentDevice from .octoplus import RedeemOctoplusPointsResponse from .intelligent_settings import IntelligentSettings from .intelligent_dispatches import IntelligentDispatchItem, IntelligentDispatches @@ -1203,7 +1204,7 @@ async def async_turn_off_intelligent_smart_charge( _LOGGER.warning(f'Failed to connect. Timeout of {self._timeout} exceeded.') raise TimeoutException() - async def async_get_intelligent_device(self, account_id: str): + async def async_get_intelligent_device(self, account_id: str) -> IntelligentDevice: """Get the user's intelligent dispatches""" await self.async_refresh_token() @@ -1219,17 +1220,17 @@ async def async_get_intelligent_device(self, account_id: str): if (response_body is not None and "data" in response_body and "registeredKrakenflexDevice" in response_body["data"]): device = response_body["data"]["registeredKrakenflexDevice"] - return { - "krakenflexDeviceId": device["krakenflexDeviceId"], - "provider": device["provider"], - "vehicleMake": device["vehicleMake"], - "vehicleModel": device["vehicleModel"], - "vehicleBatterySizeInKwh": float(device["vehicleBatterySizeInKwh"]) if "vehicleBatterySizeInKwh" in device and device["vehicleBatterySizeInKwh"] is not None else None, - "chargePointMake": device["chargePointMake"], - "chargePointModel": device["chargePointModel"], - "chargePointPowerInKw": float(device["chargePointPowerInKw"]) if "chargePointPowerInKw" in device and device["chargePointPowerInKw"] is not None else None, - - } + if device["krakenflexDeviceId"] is not None: + return IntelligentDevice( + device["krakenflexDeviceId"], + device["provider"], + device["vehicleMake"], + device["vehicleModel"], + float(device["vehicleBatterySizeInKwh"]) if "vehicleBatterySizeInKwh" in device and device["vehicleBatterySizeInKwh"] is not None else None, + device["chargePointMake"], + device["chargePointModel"], + float(device["chargePointPowerInKw"]) if "chargePointPowerInKw" in device and device["chargePointPowerInKw"] is not None else None + ) else: _LOGGER.error("Failed to retrieve intelligent device") diff --git a/custom_components/octopus_energy/api_client/intelligent_device.py b/custom_components/octopus_energy/api_client/intelligent_device.py new file mode 100644 index 00000000..75ea4f43 --- /dev/null +++ b/custom_components/octopus_energy/api_client/intelligent_device.py @@ -0,0 +1,29 @@ +class IntelligentDevice: + krakenflexDeviceId: str + provider: str + vehicleMake:str + vehicleModel: str + vehicleBatterySizeInKwh: float | None + chargePointMake: str + chargePointModel: str + chargePointPowerInKw: float | None + + def __init__( + self, + krakenflexDeviceId: str, + provider: str, + vehicleMake:str, + vehicleModel: str, + vehicleBatterySizeInKwh: float | None, + chargePointMake: str, + chargePointModel: str, + chargePointPowerInKw: float | None + ): + self.krakenflexDeviceId = krakenflexDeviceId + self.provider = provider + self.vehicleMake = vehicleMake + self.vehicleModel = vehicleModel + self.vehicleBatterySizeInKwh = vehicleBatterySizeInKwh + self.chargePointMake = chargePointMake + self.chargePointModel = chargePointModel + self.chargePointPowerInKw = chargePointPowerInKw \ No newline at end of file diff --git a/custom_components/octopus_energy/binary_sensor.py b/custom_components/octopus_energy/binary_sensor.py index 2fc4809c..cc54969a 100644 --- a/custom_components/octopus_energy/binary_sensor.py +++ b/custom_components/octopus_energy/binary_sensor.py @@ -12,6 +12,7 @@ from .greenness_forecast.highlighted import OctopusEnergyGreennessForecastHighlighted from .utils import get_active_tariff_code from .intelligent import get_intelligent_features +from .api_client.intelligent_device import IntelligentDevice from .const import ( CONFIG_KIND, @@ -98,11 +99,11 @@ async def async_setup_main_sensors(hass, entry, async_add_entities): entities.append(OctopusEnergyElectricityOffPeak(hass, electricity_rate_coordinator, meter, point)) - intelligent_device = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None + intelligent_device: IntelligentDevice = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None intelligent_mpan = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_MPAN] if DATA_INTELLIGENT_MPAN in hass.data[DOMAIN][account_id] else None intelligent_serial_number = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_SERIAL_NUMBER] if DATA_INTELLIGENT_SERIAL_NUMBER in hass.data[DOMAIN][account_id] else None if intelligent_device is not None and intelligent_mpan is not None and intelligent_serial_number is not None: - intelligent_features = get_intelligent_features(intelligent_device["provider"]) + intelligent_features = get_intelligent_features(intelligent_device.provider) coordinator = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DISPATCHES_COORDINATOR] electricity_rate_coordinator = hass.data[DOMAIN][account_id][DATA_ELECTRICITY_RATES_COORDINATOR_KEY.format(intelligent_mpan, intelligent_serial_number)] entities.append(OctopusEnergyIntelligentDispatching(hass, coordinator, electricity_rate_coordinator, intelligent_mpan, intelligent_device, account_id, intelligent_features.planned_dispatches_supported)) diff --git a/custom_components/octopus_energy/coordinators/intelligent_dispatches.py b/custom_components/octopus_energy/coordinators/intelligent_dispatches.py index 051fec5d..7d717a3d 100644 --- a/custom_components/octopus_energy/coordinators/intelligent_dispatches.py +++ b/custom_components/octopus_energy/coordinators/intelligent_dispatches.py @@ -10,6 +10,7 @@ from ..const import ( COORDINATOR_REFRESH_IN_SECONDS, + DATA_INTELLIGENT_DEVICE, DOMAIN, DATA_CLIENT, @@ -25,6 +26,7 @@ from ..api_client import ApiException, OctopusEnergyApiClient from ..api_client.intelligent_dispatches import IntelligentDispatches from . import BaseCoordinatorResult +from ..api_client.intelligent_device import IntelligentDevice from ..intelligent import async_mock_intelligent_data, clean_previous_dispatches, dictionary_list_to_dispatches, dispatches_to_dictionary_list, has_intelligent_tariff, mock_intelligent_dispatches @@ -58,6 +60,7 @@ async def async_refresh_intelligent_dispatches( current: datetime, client: OctopusEnergyApiClient, account_info, + intelligent_device: IntelligentDevice, existing_intelligent_dispatches_result: IntelligentDispatchesCoordinatorResult, is_data_mocked: bool, async_merge_dispatch_data: Callable[[str, list], Awaitable[list]] @@ -66,7 +69,7 @@ async def async_refresh_intelligent_dispatches( account_id = account_info["id"] if (existing_intelligent_dispatches_result is None or current >= existing_intelligent_dispatches_result.next_refresh): dispatches = None - if has_intelligent_tariff(current, account_info): + if has_intelligent_tariff(current, account_info) and intelligent_device is not None: try: dispatches = await client.async_get_intelligent_dispatches(account_id) _LOGGER.debug(f'Intelligent dispatches retrieved for account {account_id}') @@ -120,6 +123,7 @@ async def async_update_intelligent_dispatches_data(): current, client, account_info, + hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None, hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DISPATCHES] if DATA_INTELLIGENT_DISPATCHES in hass.data[DOMAIN][account_id] else None, await async_mock_intelligent_data(hass, account_id), lambda account_id, completed_dispatches: async_merge_dispatch_data(hass, account_id, completed_dispatches) diff --git a/custom_components/octopus_energy/intelligent/__init__.py b/custom_components/octopus_energy/intelligent/__init__.py index ba773245..f78e9d6e 100644 --- a/custom_components/octopus_energy/intelligent/__init__.py +++ b/custom_components/octopus_energy/intelligent/__init__.py @@ -12,6 +12,7 @@ from ..api_client.intelligent_settings import IntelligentSettings from ..api_client.intelligent_dispatches import IntelligentDispatchItem, IntelligentDispatches +from ..api_client.intelligent_device import IntelligentDevice mock_intelligent_data_key = "MOCK_INTELLIGENT_DATA" @@ -97,16 +98,16 @@ def mock_intelligent_settings(): ) def mock_intelligent_device(): - return { - "krakenflexDeviceId": "1", - "provider": FULLY_SUPPORTED_INTELLIGENT_PROVIDERS[0], - "vehicleMake": "Tesla", - "vehicleModel": "Model Y", - "vehicleBatterySizeInKwh": 75.0, - "chargePointMake": "MyEnergi", - "chargePointModel": "Zappi", - "chargePointPowerInKw": 6.5 - } + return IntelligentDevice( + "1", + FULLY_SUPPORTED_INTELLIGENT_PROVIDERS[0], + "Tesla", + "Model Y", + 75.0, + "MyEnergi", + "Zappi", + 6.5 + ) def is_intelligent_tariff(tariff_code: str): parts = get_tariff_parts(tariff_code.upper()) diff --git a/custom_components/octopus_energy/intelligent/base.py b/custom_components/octopus_energy/intelligent/base.py index d656134a..f04d6cab 100644 --- a/custom_components/octopus_energy/intelligent/base.py +++ b/custom_components/octopus_energy/intelligent/base.py @@ -3,18 +3,19 @@ from ..const import ( DOMAIN, ) +from ..api_client.intelligent_device import IntelligentDevice class OctopusEnergyIntelligentSensor: - def __init__(self, device): + def __init__(self, device: IntelligentDevice): """Init sensor""" self._device = device self._attr_device_info = DeviceInfo( identifiers={ - (DOMAIN, self._device["krakenflexDeviceId"] if "krakenflexDeviceId" in self._device and self._device["krakenflexDeviceId"] is not None else "charger-1") + (DOMAIN, self._device.krakenflexDeviceId if self._device.krakenflexDeviceId is not None else "charger-1") }, name="Charger", connections=set(), - manufacturer=self._device["chargePointMake"], - model=self._device["chargePointModel"] + manufacturer=self._device.chargePointMake, + model=self._device.chargePointModel ) \ No newline at end of file diff --git a/custom_components/octopus_energy/intelligent/dispatching.py b/custom_components/octopus_energy/intelligent/dispatching.py index 44000984..890d033d 100644 --- a/custom_components/octopus_energy/intelligent/dispatching.py +++ b/custom_components/octopus_energy/intelligent/dispatching.py @@ -24,13 +24,14 @@ from .base import OctopusEnergyIntelligentSensor from ..coordinators.intelligent_dispatches import IntelligentDispatchesCoordinatorResult from ..utils.attributes import dict_to_typed_dict +from ..api_client.intelligent_device import IntelligentDevice _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: str, device, account_id: str, planned_dispatches_supported: bool): + def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, mpan: str, device: IntelligentDevice, account_id: str, planned_dispatches_supported: bool): """Init sensor.""" CoordinatorEntity.__init__(self, coordinator) @@ -41,18 +42,7 @@ def __init__(self, hass: HomeAssistant, coordinator, rates_coordinator, mpan: st self._account_id = account_id self._state = None self._planned_dispatches_supported = planned_dispatches_supported - self._attributes = { - "planned_dispatches": [], - "completed_dispatches": [], - "last_evaluated": None, - "provider": device["provider"], - "vehicle_battery_size_in_kwh": device["vehicleBatterySizeInKwh"], - "charge_point_power_in_kw": device["chargePointPowerInKw"], - "current_start": None, - "current_end": None, - "next_start": None, - "next_end": None, - } + self.__init_attributes__([], [], None, None) self.entity_id = generate_entity_id("binary_sensor.{}", self.unique_id, hass=hass) @@ -80,6 +70,21 @@ def extra_state_attributes(self): def is_on(self): return self._state + def __init_attributes__(self, planned_dispatches, completed_dispatches, data_last_retrieved, last_evaluated): + self._attributes = { + "planned_dispatches": planned_dispatches, + "completed_dispatches": completed_dispatches, + "data_last_retrieved": data_last_retrieved, + "last_evaluated": last_evaluated, + "provider": self._device.provider, + "vehicle_battery_size_in_kwh": self._device.vehicleBatterySizeInKwh, + "charge_point_power_in_kw": self._device.chargePointPowerInKw, + "current_start": None, + "current_end": None, + "next_start": None, + "next_end": None, + } + @callback def _handle_coordinator_update(self) -> None: """Determine if OE is currently dispatching energy.""" @@ -89,16 +94,12 @@ def _handle_coordinator_update(self) -> None: current_date = utcnow() planned_dispatches = result.dispatches.planned if result is not None and result.dispatches is not None and self._planned_dispatches_supported else [] - self._attributes = { - "planned_dispatches": dispatches_to_dictionary_list(planned_dispatches) if result is not None else [], - "completed_dispatches": dispatches_to_dictionary_list(result.dispatches.completed if result is not None and result.dispatches is not None else []) if result is not None else [], - "data_last_retrieved": result.last_retrieved if result is not None else None, - "last_evaluated": current_date, - "current_start": None, - "current_end": None, - "next_start": None, - "next_end": None, - } + self.__init_attributes__( + dispatches_to_dictionary_list(planned_dispatches) if result is not None else [], + dispatches_to_dictionary_list(result.dispatches.completed if result is not None and result.dispatches is not None else []) if result is not None else [], + result.last_retrieved if result is not None else None, + current_date + ) off_peak_times = get_off_peak_times(current_date, rates, True) is_dispatching = False diff --git a/custom_components/octopus_energy/number.py b/custom_components/octopus_energy/number.py index 7b5901ea..cdeec3e8 100644 --- a/custom_components/octopus_energy/number.py +++ b/custom_components/octopus_energy/number.py @@ -2,6 +2,7 @@ from .intelligent import get_intelligent_features from .intelligent.charge_limit import OctopusEnergyIntelligentChargeLimit +from .api_client.intelligent_device import IntelligentDevice from .const import ( CONFIG_ACCOUNT_ID, @@ -37,9 +38,9 @@ async def async_setup_intelligent_sensors(hass, config, async_add_entities): account_id = config[CONFIG_ACCOUNT_ID] client = hass.data[DOMAIN][account_id][DATA_CLIENT] - intelligent_device = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None + intelligent_device: IntelligentDevice = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None if intelligent_device is not None: - intelligent_features = get_intelligent_features(intelligent_device["provider"]) + intelligent_features = get_intelligent_features(intelligent_device.provider) settings_coordinator = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_SETTINGS_COORDINATOR] if intelligent_features.charge_limit_supported == True: diff --git a/custom_components/octopus_energy/switch.py b/custom_components/octopus_energy/switch.py index d2f370d7..e07ef8e8 100644 --- a/custom_components/octopus_energy/switch.py +++ b/custom_components/octopus_energy/switch.py @@ -4,6 +4,7 @@ from .intelligent.bump_charge import OctopusEnergyIntelligentBumpCharge from .api_client import OctopusEnergyApiClient from .intelligent import get_intelligent_features +from .api_client.intelligent_device import IntelligentDevice from .const import ( CONFIG_ACCOUNT_ID, @@ -44,9 +45,9 @@ async def async_setup_intelligent_sensors(hass, config, async_add_entities): account_id = account_info["id"] client = hass.data[DOMAIN][account_id][DATA_CLIENT] - intelligent_device = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None + intelligent_device: IntelligentDevice = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None if intelligent_device is not None: - intelligent_features = get_intelligent_features(intelligent_device["provider"]) + intelligent_features = get_intelligent_features(intelligent_device.provider) settings_coordinator = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_SETTINGS_COORDINATOR] dispatches_coordinator = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DISPATCHES_COORDINATOR] client: OctopusEnergyApiClient = hass.data[DOMAIN][account_id][DATA_CLIENT] diff --git a/custom_components/octopus_energy/time.py b/custom_components/octopus_energy/time.py index b8cfca8b..f55981ea 100644 --- a/custom_components/octopus_energy/time.py +++ b/custom_components/octopus_energy/time.py @@ -3,6 +3,7 @@ from .intelligent.ready_time import OctopusEnergyIntelligentReadyTime from .api_client import OctopusEnergyApiClient from .intelligent import get_intelligent_features +from .api_client.intelligent_device import IntelligentDevice from .const import ( CONFIG_ACCOUNT_ID, @@ -39,9 +40,9 @@ async def async_setup_intelligent_sensors(hass, config, async_add_entities): account_id = config[CONFIG_ACCOUNT_ID] client = hass.data[DOMAIN][account_id][DATA_CLIENT] - intelligent_device = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None + intelligent_device: IntelligentDevice = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_DEVICE] if DATA_INTELLIGENT_DEVICE in hass.data[DOMAIN][account_id] else None if intelligent_device is not None: - intelligent_features = get_intelligent_features(intelligent_device["provider"]) + intelligent_features = get_intelligent_features(intelligent_device.provider) settings_coordinator = hass.data[DOMAIN][account_id][DATA_INTELLIGENT_SETTINGS_COORDINATOR] client: OctopusEnergyApiClient = hass.data[DOMAIN][account_id][DATA_CLIENT] diff --git a/tests/unit/coordinators/test_async_refresh_intelligent_dispatches.py b/tests/unit/coordinators/test_async_refresh_intelligent_dispatches.py index 2414367a..c4197bbf 100644 --- a/tests/unit/coordinators/test_async_refresh_intelligent_dispatches.py +++ b/tests/unit/coordinators/test_async_refresh_intelligent_dispatches.py @@ -5,6 +5,7 @@ from custom_components.octopus_energy.const import REFRESH_RATE_IN_MINUTES_INTELLIGENT from custom_components.octopus_energy.api_client import OctopusEnergyApiClient from custom_components.octopus_energy.api_client.intelligent_dispatches import IntelligentDispatches +from custom_components.octopus_energy.api_client.intelligent_device import IntelligentDevice from custom_components.octopus_energy.intelligent import mock_intelligent_dispatches from custom_components.octopus_energy.coordinators.intelligent_dispatches import IntelligentDispatchesCoordinatorResult, async_refresh_intelligent_dispatches @@ -15,6 +16,8 @@ mpan = "1234567890" serial_number = "abcdefgh" +intelligent_device = IntelligentDevice("1", "2", "3", "4", 1, "5", "6", 2) + def get_account_info(is_active_agreement = True, active_tariff_code = tariff_code): return { "id": "A-XXXXXX", @@ -66,6 +69,7 @@ async def async_merge_dispatch_data(*args, **kwargs): current, client, account_info, + intelligent_device, existing_settings, False, async_merge_dispatch_data @@ -74,6 +78,38 @@ async def async_merge_dispatch_data(*args, **kwargs): assert retrieved_dispatches == existing_settings assert mock_api_called == False +@pytest.mark.asyncio +async def test_when_intelligent_device_is_none_then_none_returned(): + expected_dispatches = IntelligentDispatches([], []) + mock_api_called = False + async def async_mock_get_intelligent_dispatches(*args, **kwargs): + nonlocal mock_api_called + mock_api_called = True + return expected_dispatches + + async def async_merge_dispatch_data(*args, **kwargs): + account_id, completed_dispatches = args + return completed_dispatches + + account_info = get_account_info(True, "E-1R-GO-18-06-12-A") + existing_settings = None + + with mock.patch.multiple(OctopusEnergyApiClient, async_get_intelligent_dispatches=async_mock_get_intelligent_dispatches): + client = OctopusEnergyApiClient("NOT_REAL") + retrieved_dispatches: IntelligentDispatchesCoordinatorResult = await async_refresh_intelligent_dispatches( + current, + client, + account_info, + None, + existing_settings, + False, + async_merge_dispatch_data + ) + + assert mock_api_called == False + assert retrieved_dispatches is not None + assert retrieved_dispatches.dispatches is None + @pytest.mark.asyncio async def test_when_not_on_intelligent_tariff_then_none_returned(): expected_dispatches = IntelligentDispatches([], []) @@ -96,6 +132,7 @@ async def async_merge_dispatch_data(*args, **kwargs): current, client, account_info, + intelligent_device, existing_settings, False, async_merge_dispatch_data @@ -126,6 +163,7 @@ async def async_merge_dispatch_data(*args, **kwargs): current, client, account_info, + intelligent_device, existing_settings, True, async_merge_dispatch_data @@ -175,6 +213,7 @@ async def async_merge_dispatch_data(*args, **kwargs): current, client, account_info, + intelligent_device, existing_settings, False, async_merge_dispatch_data @@ -211,6 +250,7 @@ async def async_merge_dispatch_data(*args, **kwargs): current, client, account_info, + intelligent_device, existing_settings, False, async_merge_dispatch_data @@ -244,6 +284,7 @@ async def async_merge_dispatch_data(*args, **kwargs): current, client, account_info, + intelligent_device, existing_settings, False, async_merge_dispatch_data @@ -276,6 +317,7 @@ async def async_merge_dispatch_data(*args, **kwargs): current, client, account_info, + intelligent_device, existing_settings, False, async_merge_dispatch_data