From 226aa89a51ec7efaca110582b342f7f834810f42 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Mercier Date: Fri, 16 Feb 2024 08:58:14 +0100 Subject: [PATCH] fix: relay (#107) * fix: relay * fix: relay --- custom_components/mylight_systems/const.py | 2 +- custom_components/mylight_systems/coordinator.py | 14 +++++++------- custom_components/mylight_systems/manifest.json | 2 +- custom_components/mylight_systems/switch.py | 2 +- pyproject.toml | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/custom_components/mylight_systems/const.py b/custom_components/mylight_systems/const.py index efab179..480dff8 100644 --- a/custom_components/mylight_systems/const.py +++ b/custom_components/mylight_systems/const.py @@ -9,7 +9,7 @@ NAME = "MyLight Systems" DOMAIN = "mylight_systems" PLATFORMS = [Platform.SENSOR, Platform.SWITCH] -VERSION = "0.1.0" +VERSION = "0.1.1" COORDINATOR = "coordinator" ATTRIBUTION = "Data provided by https://www.mylight-systems.com/" SCAN_INTERVAL_IN_MINUTES = 15 diff --git a/custom_components/mylight_systems/coordinator.py b/custom_components/mylight_systems/coordinator.py index cb11c28..4090a46 100644 --- a/custom_components/mylight_systems/coordinator.py +++ b/custom_components/mylight_systems/coordinator.py @@ -43,7 +43,7 @@ class MyLightSystemsCoordinatorData(NamedTuple): msb_discharge: Measure green_energy: Measure battery_state: Measure - master_relay_state: str + master_relay_state: str | None # https://developers.home-assistant.io/docs/integration_fetching_data#coordinated-single-api-poll-for-data-for-all-entities @@ -78,9 +78,7 @@ async def _async_update_data(self) -> MyLightSystemsCoordinatorData: virtual_battery_id = self.config_entry.data[ CONF_VIRTUAL_BATTERY_ID ] - master_relay_id = self.config_entry.data[ - CONF_MASTER_RELAY_ID - ] + master_relay_id = self.config_entry.data.get(CONF_MASTER_RELAY_ID, None) await self.authenticate_user(email, password) @@ -92,9 +90,11 @@ async def _async_update_data(self) -> MyLightSystemsCoordinatorData: self.__auth_token, virtual_battery_id ) - master_relay_state = await self.client.async_get_relay_state( - self.__auth_token, master_relay_id - ) + master_relay_state = None + if master_relay_id is not None: + master_relay_state = await self.client.async_get_relay_state( + self.__auth_token, master_relay_id + ) data = MyLightSystemsCoordinatorData( produced_energy=self.find_measure_by_type( diff --git a/custom_components/mylight_systems/manifest.json b/custom_components/mylight_systems/manifest.json index f4908dc..1e3f29c 100644 --- a/custom_components/mylight_systems/manifest.json +++ b/custom_components/mylight_systems/manifest.json @@ -8,5 +8,5 @@ "documentation": "https://github.com/acesyde/hassio_mylight_integration", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/acesyde/hassio_mylight_integration/issues", - "version": "0.1.0" + "version": "0.1.1" } diff --git a/custom_components/mylight_systems/switch.py b/custom_components/mylight_systems/switch.py index a00ee09..c3d2df6 100644 --- a/custom_components/mylight_systems/switch.py +++ b/custom_components/mylight_systems/switch.py @@ -38,7 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e switches: list[MyLightSystemsSwitchEntityDescription] = [] - if entry.data[CONF_MASTER_RELAY_ID] is not None: + if entry.data.get(CONF_MASTER_RELAY_ID, None) is not None: switches.append(master_relay_switch) async_add_entities( diff --git a/pyproject.toml b/pyproject.toml index 93cff29..23934b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mylight_systems" -version = "0.1.0" +version = "0.1.1" description = "MyLight Systems integration for Home Assistant" authors = ["Pierre-Emmanuel Mercier "] license = "MIT"