From 224574c4a03ffbe3f30e1530352de5bf74d8afcf Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 29 Apr 2023 09:27:47 +0200 Subject: [PATCH 01/52] Link to plugwise v0.31.2a0, bump to v0.40.2a0 --- custom_components/plugwise/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/manifest.json b/custom_components/plugwise/manifest.json index 57855e7d3..7ab23f450 100644 --- a/custom_components/plugwise/manifest.json +++ b/custom_components/plugwise/manifest.json @@ -8,6 +8,6 @@ "integration_type": "hub", "iot_class": "local_polling", "loggers": ["plugwise"], - "requirements": ["plugwise==0.31.0"], - "version": "0.40.1" + "requirements": ["https://test-files.pythonhosted.org/packages/b6/a8/c41c9fcf2d546dc91fe50a6106161f375cdf17381a9c7bfd93a30d9d7c29/plugwise-0.31.2a0.tar.gz#plugwise==0.31.2a0"], + "version": "0.40.2a0" } From 03fa7a61f32e7521b7036100f296f185ac9d2924 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 29 Apr 2023 10:15:34 +0200 Subject: [PATCH 02/52] Link to plugwise v0.31.2a1 --- custom_components/plugwise/manifest.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/plugwise/manifest.json b/custom_components/plugwise/manifest.json index 7ab23f450..f5a79d555 100644 --- a/custom_components/plugwise/manifest.json +++ b/custom_components/plugwise/manifest.json @@ -8,6 +8,8 @@ "integration_type": "hub", "iot_class": "local_polling", "loggers": ["plugwise"], - "requirements": ["https://test-files.pythonhosted.org/packages/b6/a8/c41c9fcf2d546dc91fe50a6106161f375cdf17381a9c7bfd93a30d9d7c29/plugwise-0.31.2a0.tar.gz#plugwise==0.31.2a0"], + "requirements": [ + "https://test-files.pythonhosted.org/packages/e8/8e/7a4ff72fbfc05d687dd884c25074cb275e3c394f694ccae3b349d6b2f012/plugwise-0.31.2a1.tar.gz#plugwise==0.31.2a1" + ], "version": "0.40.2a0" } From d4b9cd983c70a576bfd94dbcdbc8c2d56ddb7438 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 29 Apr 2023 14:02:31 +0200 Subject: [PATCH 03/52] Adapt to using PlugwiseData class, fix remaining mypy errors --- custom_components/plugwise/binary_sensor.py | 9 +++---- custom_components/plugwise/climate.py | 14 +++++------ custom_components/plugwise/coordinator.py | 19 +++----------- custom_components/plugwise/entity.py | 2 +- custom_components/plugwise/number.py | 10 ++++---- custom_components/plugwise/select.py | 6 ++--- custom_components/plugwise/sensor.py | 4 +-- custom_components/plugwise/switch.py | 4 +-- tests/components/plugwise/conftest.py | 28 ++++++++++++++------- 9 files changed, 46 insertions(+), 50 deletions(-) diff --git a/custom_components/plugwise/binary_sensor.py b/custom_components/plugwise/binary_sensor.py index 3b90b9787..1f3258646 100644 --- a/custom_components/plugwise/binary_sensor.py +++ b/custom_components/plugwise/binary_sensor.py @@ -66,17 +66,16 @@ def __init__( self._notification: dict[str, str] = {} # pw-beta @property - def is_on(self) -> bool | None: + def is_on(self) -> bool: """Return true if the binary sensor is on.""" - if ( - self._notification - ): # pw-beta: show Plugwise notifications as HA persistent notifications + # pw-beta: show Plugwise notifications as HA persistent notifications + if self._notification: for notify_id, message in self._notification.items(): self.hass.components.persistent_notification.async_create( message, "Plugwise Notification:", f"{DOMAIN}.{notify_id}" ) - return self.device["binary_sensors"].get(self.entity_description.key) + return self.device["binary_sensors"][self.entity_description.key] # type: ignore [literal-required] @property def icon(self) -> str | None: diff --git a/custom_components/plugwise/climate.py b/custom_components/plugwise/climate.py index b3a72110c..f27f6fc76 100644 --- a/custom_components/plugwise/climate.py +++ b/custom_components/plugwise/climate.py @@ -156,13 +156,13 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core if control_state == "off": return HVACAction.IDLE - hc_data = self.coordinator.data.devices[ - self.coordinator.data.gateway["heater_id"] - ] - if hc_data["binary_sensors"]["heating_state"]: - return HVACAction.HEATING - if hc_data["binary_sensors"].get("cooling_state", False): # pw-beta adds False - return HVACAction.COOLING + heater: str | None = self.coordinator.data.gateway["heater_id"] + if heater is not None: + heater_data = self.coordinator.data.devices[heater] + if heater_data["binary_sensors"]["heating_state"]: + return HVACAction.HEATING + if heater_data["binary_sensors"].get("cooling_state", False): + return HVACAction.COOLING return HVACAction.IDLE diff --git a/custom_components/plugwise/coordinator.py b/custom_components/plugwise/coordinator.py index 0e88515f1..ebb321d51 100644 --- a/custom_components/plugwise/coordinator.py +++ b/custom_components/plugwise/coordinator.py @@ -1,6 +1,5 @@ """DataUpdateCoordinator for Plugwise.""" from datetime import timedelta -from typing import NamedTuple, cast from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME @@ -11,7 +10,7 @@ from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from plugwise import Smile -from plugwise.constants import DeviceData, GatewayData +from plugwise.constants import PlugwiseData from plugwise.exceptions import ( ConnectionFailedError, InvalidAuthentication, @@ -23,13 +22,6 @@ from .const import DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DEFAULT_USERNAME, DOMAIN, LOGGER -class PlugwiseData(NamedTuple): - """Plugwise data stored in the DataUpdateCoordinator.""" - - gateway: GatewayData - devices: dict[str, DeviceData] - - class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[PlugwiseData]): """Class to manage fetching Plugwise data from single endpoint.""" @@ -88,9 +80,7 @@ async def _async_update_data(self) -> PlugwiseData: if not self._connected: await self._connect() data = await self.api.async_update() - LOGGER.debug( - f"{self.api.smile_name} data: %s", PlugwiseData(data[0], data[1]) - ) + LOGGER.debug(f"{self.api.smile_name} data: %s", data) if self._unavailable_logged: self._unavailable_logged = False except InvalidAuthentication as err: @@ -112,7 +102,4 @@ async def _async_update_data(self) -> PlugwiseData: self._unavailable_logged = True raise UpdateFailed("Failed to connect") from err - return PlugwiseData( - gateway=cast(GatewayData, data[0]), - devices=cast(dict[str, DeviceData], data[1]), - ) + return data diff --git a/custom_components/plugwise/entity.py b/custom_components/plugwise/entity.py index 8fe64b490..b11298339 100644 --- a/custom_components/plugwise/entity.py +++ b/custom_components/plugwise/entity.py @@ -66,7 +66,7 @@ def available(self) -> bool: """Return if entity is available.""" return ( self._dev_id in self.coordinator.data.devices - and ("available" not in self.device or self.device["available"]) + and ("available" not in self.device or self.device["available"] is True) and super().available ) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index a7374ee36..2b44ae841 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -83,7 +83,7 @@ async def async_setup_entry( entities: list[PlugwiseNumberEntity] = [] for device_id, device in coordinator.data.devices.items(): for description in NUMBER_TYPES: - if description.key in device and "setpoint" in device[description.key]: + if description.key in device and "setpoint" in device[description.key]: # type: ignore [literal-required] entities.append( PlugwiseNumberEntity(coordinator, device_id, description) ) @@ -113,7 +113,7 @@ def __init__( def native_step(self) -> float: """Return the setpoint step value.""" return max( - self.device[self.entity_description.key][ + self.device[self.entity_description.key][ # type: ignore [literal-required] self.entity_description.native_step_key ], 1, @@ -122,21 +122,21 @@ def native_step(self) -> float: @property def native_value(self) -> float: """Return the present setpoint value.""" - return self.device[self.entity_description.key][ + return self.device[self.entity_description.key][ # type: ignore [literal-required] self.entity_description.native_value_key ] @property def native_min_value(self) -> float: """Return the setpoint min. value.""" - return self.device[self.entity_description.key][ + return self.device[self.entity_description.key][ # type: ignore [literal-required] self.entity_description.native_min_value_key ] @property def native_max_value(self) -> float: """Return the setpoint max. value.""" - return self.device[self.entity_description.key][ + return self.device[self.entity_description.key][ # type: ignore [literal-required] self.entity_description.native_max_value_key ] diff --git a/custom_components/plugwise/select.py b/custom_components/plugwise/select.py index 97dd4b83a..24615847f 100644 --- a/custom_components/plugwise/select.py +++ b/custom_components/plugwise/select.py @@ -81,7 +81,7 @@ async def async_setup_entry( for description in SELECT_TYPES: if ( description.options_key in device - and len(device[description.options_key]) > 1 + and len(device[description.options_key]) > 1 # type: ignore [literal-required] ): entities.append( PlugwiseSelectEntity(coordinator, device_id, description) @@ -110,12 +110,12 @@ def __init__( @property def current_option(self) -> str: """Return the selected entity option to represent the entity state.""" - return self.device[self.entity_description.current_option_key] + return self.device[self.entity_description.current_option_key] # type: ignore [literal-required] @property def options(self) -> list[str]: """Return the selectable entity options.""" - return self.device[self.entity_description.options_key] + return self.device[self.entity_description.options_key] # type: ignore [literal-required] async def async_select_option(self, option: str) -> None: """Change to the selected entity option.""" diff --git a/custom_components/plugwise/sensor.py b/custom_components/plugwise/sensor.py index 1b63a445f..456818a50 100644 --- a/custom_components/plugwise/sensor.py +++ b/custom_components/plugwise/sensor.py @@ -59,6 +59,6 @@ def __init__( self._attr_unique_id = f"{device_id}-{description.key}" @property - def native_value(self) -> int | float | None: + def native_value(self) -> int | float: """Return the value reported by the sensor.""" - return self.device["sensors"].get(self.entity_description.key) + return self.device["sensors"][self.entity_description.key] # type: ignore [literal-required] diff --git a/custom_components/plugwise/switch.py b/custom_components/plugwise/switch.py index a65ff9565..69e73ba84 100644 --- a/custom_components/plugwise/switch.py +++ b/custom_components/plugwise/switch.py @@ -48,9 +48,9 @@ def __init__( self._attr_unique_id = f"{device_id}-{description.key}" @property - def is_on(self) -> bool | None: + def is_on(self) -> bool: """Return True if entity is on.""" - return self.device["switches"].get(self.entity_description.key) + return self.device["switches"][self.entity_description.key] # type: ignore [literal-required] @plugwise_command async def async_turn_on(self, **kwargs: Any) -> None: diff --git a/tests/components/plugwise/conftest.py b/tests/components/plugwise/conftest.py index 880715820..5259cfb36 100644 --- a/tests/components/plugwise/conftest.py +++ b/tests/components/plugwise/conftest.py @@ -17,6 +17,7 @@ CONF_USERNAME, ) from homeassistant.core import HomeAssistant +from plugwise import PlugwiseData from tests.common import MockConfigEntry, load_fixture @@ -89,7 +90,8 @@ def mock_smile_adam() -> Generator[None, MagicMock, None]: smile.connect.return_value = True smile.notifications = _read_json(chosen_env, "notifications") - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile @@ -115,7 +117,8 @@ def mock_smile_adam_2() -> Generator[None, MagicMock, None]: smile.connect.return_value = True smile.notifications = _read_json(chosen_env, "notifications") - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile @@ -141,7 +144,8 @@ def mock_smile_adam_3() -> Generator[None, MagicMock, None]: smile.connect.return_value = True smile.notifications = _read_json(chosen_env, "notifications") - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile @@ -166,7 +170,8 @@ def mock_smile_anna() -> Generator[None, MagicMock, None]: smile.connect.return_value = True smile.notifications = _read_json(chosen_env, "notifications") - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile @@ -191,7 +196,8 @@ def mock_smile_anna_2() -> Generator[None, MagicMock, None]: smile.connect.return_value = True smile.notifications = _read_json(chosen_env, "notifications") - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile @@ -216,7 +222,8 @@ def mock_smile_anna_3() -> Generator[None, MagicMock, None]: smile.connect.return_value = True smile.notifications = _read_json(chosen_env, "notifications") - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile @@ -241,7 +248,8 @@ def mock_smile_p1() -> Generator[None, MagicMock, None]: smile.connect.return_value = True smile.notifications = _read_json(chosen_env, "notifications") - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile @@ -266,7 +274,8 @@ def mock_smile_p1_2() -> Generator[None, MagicMock, None]: smile.connect.return_value = True smile.notifications = _read_json(chosen_env, "notifications") - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile @@ -289,7 +298,8 @@ def mock_stretch() -> Generator[None, MagicMock, None]: smile.smile_name = "Stretch" smile.connect.return_value = True - smile.async_update.return_value = _read_json(chosen_env, "all_data") + all_data = _read_json(chosen_env, "all_data") + smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) yield smile From d65b3bf4e1cdf776bc6b1a3ec4ba5e08c43342ff Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 29 Apr 2023 14:28:11 +0200 Subject: [PATCH 04/52] Link to plugwise v0.31.2 --- custom_components/plugwise/manifest.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/custom_components/plugwise/manifest.json b/custom_components/plugwise/manifest.json index f5a79d555..567bc34ba 100644 --- a/custom_components/plugwise/manifest.json +++ b/custom_components/plugwise/manifest.json @@ -8,8 +8,6 @@ "integration_type": "hub", "iot_class": "local_polling", "loggers": ["plugwise"], - "requirements": [ - "https://test-files.pythonhosted.org/packages/e8/8e/7a4ff72fbfc05d687dd884c25074cb275e3c394f694ccae3b349d6b2f012/plugwise-0.31.2a1.tar.gz#plugwise==0.31.2a1" - ], + "requirements": ["plugwise==0.31.2"], "version": "0.40.2a0" } From e4f32a636bb1360a68a8721349ec6bd97749d77a Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 29 Apr 2023 14:40:15 +0200 Subject: [PATCH 05/52] Simplify plugwise imports --- custom_components/plugwise/coordinator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/custom_components/plugwise/coordinator.py b/custom_components/plugwise/coordinator.py index ebb321d51..b8a95d17e 100644 --- a/custom_components/plugwise/coordinator.py +++ b/custom_components/plugwise/coordinator.py @@ -9,8 +9,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed -from plugwise import Smile -from plugwise.constants import PlugwiseData +from plugwise import PlugwiseData, Smile from plugwise.exceptions import ( ConnectionFailedError, InvalidAuthentication, From 2283e6897a1cef0a1950c64f58b98e30f12b2585 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 29 Apr 2023 18:12:54 +0200 Subject: [PATCH 06/52] Fix pylint errors (copy from Core) --- custom_components/plugwise/coordinator.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/custom_components/plugwise/coordinator.py b/custom_components/plugwise/coordinator.py index b8a95d17e..738da78ab 100644 --- a/custom_components/plugwise/coordinator.py +++ b/custom_components/plugwise/coordinator.py @@ -27,7 +27,11 @@ class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[PlugwiseData]): _connected: bool = False def __init__( - self, hass: HomeAssistant, entry: ConfigEntry, cooldown: float + self, + hass: HomeAssistant, + entry: ConfigEntry, + cooldown: float, + update_interval=timedelta(seconds=60), ) -> None: # pw-beta cooldown """Initialize the coordinator.""" super().__init__( @@ -35,7 +39,7 @@ def __init__( LOGGER, name=DOMAIN, # Core directly updates from const's DEFAULT_SCAN_INTERVAL - update_interval=timedelta(seconds=60), + update_interval=update_interval, # Don't refresh immediately, give the device time to process # the change in state before we query it. request_refresh_debouncer=Debouncer( @@ -56,12 +60,12 @@ def __init__( ) self._entry = entry self._unavailable_logged = False + self.update_interval = update_interval async def _connect(self) -> None: """Connect to the Plugwise Smile.""" self._connected = await self.api.connect() self.api.get_all_devices() - self.name = self.api.smile_name self.update_interval = DEFAULT_SCAN_INTERVAL.get( self.api.smile_type, timedelta(seconds=60) From b9a3a81d423f8ad30851b51658b1fc374ca09532 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 29 Apr 2023 19:22:44 +0200 Subject: [PATCH 07/52] Add missing typing --- custom_components/plugwise/coordinator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/plugwise/coordinator.py b/custom_components/plugwise/coordinator.py index 738da78ab..928eade13 100644 --- a/custom_components/plugwise/coordinator.py +++ b/custom_components/plugwise/coordinator.py @@ -31,7 +31,7 @@ def __init__( hass: HomeAssistant, entry: ConfigEntry, cooldown: float, - update_interval=timedelta(seconds=60), + update_interval: timedelta = timedelta(seconds=60), ) -> None: # pw-beta cooldown """Initialize the coordinator.""" super().__init__( From b91f75973a9b9bfaace8fd3e64b285e8a80fa663 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 30 Apr 2023 09:23:09 +0200 Subject: [PATCH 08/52] Add handling of strict-typing --- scripts/core-testing.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/core-testing.sh b/scripts/core-testing.sh index 3b69df4c5..e0c6b5966 100755 --- a/scripts/core-testing.sh +++ b/scripts/core-testing.sh @@ -148,6 +148,9 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "core_prep" ] ; then # Fake branch git checkout -b fake_branch + echo "Prepping strict through hassfest" + echo "homeassistant.components.plugwise.*" >> .strict-typing + python3 -m script.hassfest echo "" echo "Cleaning existing plugwise from HA core" echo "" From 3af89fecdc274cc6cb2dbd2bd4e9694734a51987 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 30 Apr 2023 10:46:05 +0200 Subject: [PATCH 09/52] Manually add mypy-settings --- scripts/core-testing.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/core-testing.sh b/scripts/core-testing.sh index e0c6b5966..9e97b2e92 100755 --- a/scripts/core-testing.sh +++ b/scripts/core-testing.sh @@ -148,9 +148,6 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "core_prep" ] ; then # Fake branch git checkout -b fake_branch - echo "Prepping strict through hassfest" - echo "homeassistant.components.plugwise.*" >> .strict-typing - python3 -m script.hassfest echo "" echo "Cleaning existing plugwise from HA core" echo "" @@ -216,6 +213,17 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "quality" ] ; then echo "... black-ing ..." black homeassistant/components/plugwise/*py tests/components/plugwise/*py || exit echo "... mypy ..." + echo "Prepping strict without hassfest" + echo "homeassistant.components.plugwise.*" >> .strict-typing + echo "[mypy-homeassistant.components.plugwise.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true" >> mypy.ini script/run-in-env.sh mypy homeassistant/components/plugwise/*.py || exit cd .. echo "... markdownlint ..." From 454f3489cb3f81112f181f8d56ec2571ed5fd755 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 30 Apr 2023 11:14:23 +0200 Subject: [PATCH 10/52] Typing fixes --- custom_components/plugwise/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 433d5aac8..3ff5d9b84 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -61,18 +61,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def delete_notification( self, - ): # pragma: no cover # pw-beta: HA service - delete_notification + ) -> None: # pragma: no cover # pw-beta: HA service - delete_notification """Service: delete the Plugwise Notification.""" LOGGER.debug( - "Service delete PW Notification called for %s", coordinator.api.smile_name + "Service delete PW Notification called for %s", + self.coordinator.api.smile_name, ) try: - deleted = await coordinator.api.delete_notification() - LOGGER.debug("PW Notification deleted: %s", deleted) + await self.coordinator.api.delete_notification() + LOGGER.debug("PW Notification deleted") except PlugwiseError: LOGGER.debug( "Failed to delete the Plugwise Notification for %s", - coordinator.api.smile_name, + self.coordinator.api.smile_name, ) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS_GATEWAY) @@ -88,12 +89,12 @@ async def delete_notification( async def _update_listener( hass: HomeAssistant, entry: ConfigEntry -): # pragma: no cover # pw-beta +) -> None: # pragma: no cover # pw-beta """Handle options update.""" await hass.config_entries.async_reload(entry.entry_id) -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" if unload_ok := await hass.config_entries.async_unload_platforms( entry, PLATFORMS_GATEWAY From c51315554d0622303432da1ceccda9006ff9e4a8 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sun, 30 Apr 2023 17:41:24 +0200 Subject: [PATCH 11/52] Try --- custom_components/plugwise/models.py | 15 ++++++++++++++- custom_components/plugwise/switch.py | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 4b9c580d7..7c490a406 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -1,6 +1,7 @@ """Models for the Plugwise integration.""" from __future__ import annotations +from collections.abc import Callable from dataclasses import dataclass from homeassistant.components.binary_sensor import BinarySensorEntityDescription @@ -22,6 +23,14 @@ UnitOfVolume, UnitOfVolumeFlowRate, ) +from plugwise import DeviceData + + +@dataclass +class PlugwiseSwitchBaseMixin: + """Mixin for required Plugwise switch base description keys.""" + + value_fn: Callable[[DeviceData], bool] @dataclass @@ -32,7 +41,7 @@ class PlugwiseSensorEntityDescription(SensorEntityDescription): @dataclass -class PlugwiseSwitchEntityDescription(SwitchEntityDescription): +class PlugwiseSwitchEntityDescription(SwitchEntityDescription, PlugwiseSwitchBaseMixin): """Describes Plugwise switch entity.""" @@ -385,6 +394,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:water-plus", device_class=SwitchDeviceClass.SWITCH, entity_category=EntityCategory.CONFIG, + value_fn=lambda data: data["switches"]["dhw_cm_switch"], ), PlugwiseSwitchEntityDescription( key="lock", @@ -392,11 +402,13 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:lock", device_class=SwitchDeviceClass.SWITCH, entity_category=EntityCategory.CONFIG, + value_fn=lambda data: data["switches"]["lock"], ), PlugwiseSwitchEntityDescription( key="relay", translation_key="relay", device_class=SwitchDeviceClass.SWITCH, + value_fn=lambda data: data["switches"]["relay"], ), PlugwiseSwitchEntityDescription( key="cooling_enabled", @@ -404,6 +416,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:snowflake-thermometer", device_class=SwitchDeviceClass.SWITCH, entity_category=EntityCategory.CONFIG, + value_fn=lambda data: data["switches"]["cooling_ena_switch"], ), ) diff --git a/custom_components/plugwise/switch.py b/custom_components/plugwise/switch.py index 69e73ba84..393df4fbd 100644 --- a/custom_components/plugwise/switch.py +++ b/custom_components/plugwise/switch.py @@ -50,7 +50,7 @@ def __init__( @property def is_on(self) -> bool: """Return True if entity is on.""" - return self.device["switches"][self.entity_description.key] # type: ignore [literal-required] + return self.entity_description.value_fn(self.device) @plugwise_command async def async_turn_on(self, **kwargs: Any) -> None: From f4e77f336a4fc9f09d839c28f22708e99a7d2f84 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 1 May 2023 14:45:23 +0200 Subject: [PATCH 12/52] Add local mypy, fix __init__ --- custom_components/plugwise/__init__.py | 12 ++++---- mypy.ini | 40 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 mypy.ini diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 3ff5d9b84..fd29edf05 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -8,7 +8,7 @@ from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.helpers import device_registry as dr, entity_registry as er from plugwise.exceptions import PlugwiseError @@ -59,21 +59,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: sw_version=coordinator.api.smile_version[0], ) - async def delete_notification( - self, - ) -> None: # pragma: no cover # pw-beta: HA service - delete_notification + async def delete_notification(call: ServiceCall) -> None: # pragma: no cover # pw-beta: HA service - delete_notification """Service: delete the Plugwise Notification.""" LOGGER.debug( "Service delete PW Notification called for %s", - self.coordinator.api.smile_name, + coordinator.api.smile_name, ) try: - await self.coordinator.api.delete_notification() + await coordinator.api.delete_notification() LOGGER.debug("PW Notification deleted") except PlugwiseError: LOGGER.debug( "Failed to delete the Plugwise Notification for %s", - self.coordinator.api.smile_name, + coordinator.api.smile_name, ) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS_GATEWAY) diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 000000000..6b2249106 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,40 @@ +[mypy] +python_version = 3.11 +plugins = pydantic.mypy +show_error_codes = true +follow_imports = silent +ignore_missing_imports = true +local_partial_types = true +strict_equality = true +no_implicit_optional = true +warn_incomplete_stub = true +warn_redundant_casts = true +warn_unused_configs = true +warn_unused_ignores = true +enable_error_code = ignore-without-code, redundant-self, truthy-iterable +disable_error_code = annotation-unchecked +strict_concatenate = false +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true + +[pydantic-mypy] +init_forbid_extra = true +init_typed = true +warn_required_dynamic_aliases = true +warn_untyped_fields = true + +[mypy-homeassistant.components.plugwise.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true From 691df8371ebb72982086d6deadf52924e9eac296 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 12:45:48 +0000 Subject: [PATCH 13/52] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- custom_components/plugwise/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index fd29edf05..6d8754a48 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -59,7 +59,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: sw_version=coordinator.api.smile_version[0], ) - async def delete_notification(call: ServiceCall) -> None: # pragma: no cover # pw-beta: HA service - delete_notification + async def delete_notification( + call: ServiceCall, + ) -> None: # pragma: no cover # pw-beta: HA service - delete_notification """Service: delete the Plugwise Notification.""" LOGGER.debug( "Service delete PW Notification called for %s", From ebcbef78cf0f7d86976a58b35c9716bc71190543 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 1 May 2023 15:01:58 +0200 Subject: [PATCH 14/52] Add missing entity desc. --- custom_components/plugwise/switch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_components/plugwise/switch.py b/custom_components/plugwise/switch.py index 393df4fbd..596af35d8 100644 --- a/custom_components/plugwise/switch.py +++ b/custom_components/plugwise/switch.py @@ -36,6 +36,8 @@ async def async_setup_entry( class PlugwiseSwitchEntity(PlugwiseEntity, SwitchEntity): """Representation of a Plugwise plug.""" + entity_description: PlugwiseSwitchEntityDescription + def __init__( self, coordinator: PlugwiseDataUpdateCoordinator, From 92f756bdb70bbed87fd462ef5a81737e125126f2 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 1 May 2023 15:06:11 +0200 Subject: [PATCH 15/52] Bump cache to ensure core-testing with mypy strict --- .github/workflows/test.yml | 2 +- scripts/core-testing.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 89c7b96da..e0c92ad8e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ name: Test with HA-core env: - CACHE_VERSION: 1 + CACHE_VERSION: 2 DEFAULT_PYTHON: "3.11" on: diff --git a/scripts/core-testing.sh b/scripts/core-testing.sh index 9e97b2e92..be00271bd 100755 --- a/scripts/core-testing.sh +++ b/scripts/core-testing.sh @@ -212,8 +212,7 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "quality" ] ; then ruff tests/components/plugwise/*py || exit echo "... black-ing ..." black homeassistant/components/plugwise/*py tests/components/plugwise/*py || exit - echo "... mypy ..." - echo "Prepping strict without hassfest" + echo "... Prepping strict without hassfest ... (for mypy)" echo "homeassistant.components.plugwise.*" >> .strict-typing echo "[mypy-homeassistant.components.plugwise.*] check_untyped_defs = true @@ -224,6 +223,7 @@ disallow_untyped_decorators = true disallow_untyped_defs = true warn_return_any = true warn_unreachable = true" >> mypy.ini + echo "... mypy ..." script/run-in-env.sh mypy homeassistant/components/plugwise/*.py || exit cd .. echo "... markdownlint ..." From ed4e35ead8229c8b9238fc93695914891bbbcef3 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 1 May 2023 18:01:05 +0200 Subject: [PATCH 16/52] Apply Switch to Sensor (with TODOs) --- custom_components/plugwise/models.py | 122 ++++++++++++++++++++++----- custom_components/plugwise/sensor.py | 4 +- 2 files changed, 103 insertions(+), 23 deletions(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 7c490a406..2b5f2428d 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -26,6 +26,13 @@ from plugwise import DeviceData +@dataclass +class PlugwiseSensorBaseMixin: + """Mixin for required Plugwise sensor base description keys.""" + + value_fn: Callable[[DeviceData], float | int] + + @dataclass class PlugwiseSwitchBaseMixin: """Mixin for required Plugwise switch base description keys.""" @@ -34,7 +41,7 @@ class PlugwiseSwitchBaseMixin: @dataclass -class PlugwiseSensorEntityDescription(SensorEntityDescription): +class PlugwiseSensorEntityDescription(SensorEntityDescription, PlugwiseSensorBaseMixin): """Describes Plugwise sensor entity.""" state_class: str | None = SensorStateClass.MEASUREMENT @@ -52,6 +59,23 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon_off: str | None = None +# TODO + +# Not existing in SmileSensors +# Breaking to pw-beta tests +# value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], + +# Non-breaking to pw-beta tests +# relative_humidity +# cooling_setpoint +# heating_setpoint + +# Are these the same? (i.e. there is no maximum in SmileSensors) +# key="maximum_boiler_temperature", +# value_fn=lambda data: data["sensors"]["intended_boiler_temperature"], + +# /TODO + PW_SENSOR_TYPES: tuple[PlugwiseSensorEntityDescription, ...] = ( PlugwiseSensorEntityDescription( key="setpoint", @@ -59,27 +83,31 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - ), - PlugwiseSensorEntityDescription( - key="cooling_setpoint", - translation_key="cooling_setpoint", - device_class=SensorDeviceClass.TEMPERATURE, - entity_category=EntityCategory.DIAGNOSTIC, - native_unit_of_measurement=UnitOfTemperature.CELSIUS, - ), - PlugwiseSensorEntityDescription( - key="heating_setpoint", - translation_key="heating_setpoint", - device_class=SensorDeviceClass.TEMPERATURE, - entity_category=EntityCategory.DIAGNOSTIC, - native_unit_of_measurement=UnitOfTemperature.CELSIUS, - ), + value_fn=lambda data: data["sensors"]["setpoint"], + ), + # PlugwiseSensorEntityDescription( + # key="cooling_setpoint", + # translation_key="cooling_setpoint", + # device_class=SensorDeviceClass.TEMPERATURE, + # entity_category=EntityCategory.DIAGNOSTIC, + # native_unit_of_measurement=UnitOfTemperature.CELSIUS, + # value_fn=lambda data: data["sensors"]["cooling_setpoint"], + # ), + # PlugwiseSensorEntityDescription( + # key="heating_setpoint", + # translation_key="heating_setpoint", + # device_class=SensorDeviceClass.TEMPERATURE, + # entity_category=EntityCategory.DIAGNOSTIC, + # native_unit_of_measurement=UnitOfTemperature.CELSIUS, + # value_fn=lambda data: data["sensors"]["heating_setpoint"], + # ), PlugwiseSensorEntityDescription( key="temperature", translation_key="temperature", device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["temperature"], ), PlugwiseSensorEntityDescription( key="intended_boiler_temperature", @@ -87,12 +115,14 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["intended_boiler_temperature"], ), PlugwiseSensorEntityDescription( key="temperature_difference", translation_key="temperature_difference", entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.KELVIN, + value_fn=lambda data: data["sensors"]["temperature_difference"], icon="mdi:temperature-kelvin", ), PlugwiseSensorEntityDescription( @@ -100,6 +130,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="outdoor_temperature", device_class=SensorDeviceClass.TEMPERATURE, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["outdoor_temperature"], suggested_display_precision=1, ), PlugwiseSensorEntityDescription( @@ -108,6 +139,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["outdoor_air_temperature"], suggested_display_precision=1, ), PlugwiseSensorEntityDescription( @@ -116,6 +148,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["water_temperature"], ), PlugwiseSensorEntityDescription( key="return_temperature", @@ -123,18 +156,21 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["return_temperature"], ), PlugwiseSensorEntityDescription( key="electricity_consumed", translation_key="electricity_consumed", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_consumed"], ), PlugwiseSensorEntityDescription( key="electricity_produced", translation_key="electricity_produced", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_produced"], entity_registry_enabled_default=False, ), # Does not exist in Core - related to P1v2 @@ -143,6 +179,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="electricity_consumed_point", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_consumed_point"], ), # Does not exist in Core PlugwiseSensorEntityDescription( @@ -150,30 +187,35 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="electricity_produced_point", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_produced_point"], ), PlugwiseSensorEntityDescription( key="electricity_consumed_interval", translation_key="electricity_consumed_interval", icon="mdi:lightning-bolt", native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + value_fn=lambda data: data["sensors"]["electricity_consumed_interval"], ), PlugwiseSensorEntityDescription( key="electricity_consumed_peak_interval", translation_key="electricity_consumed_peak_interval", icon="mdi:lightning-bolt", native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + value_fn=lambda data: data["sensors"]["electricity_consumed_peak_interval"], ), PlugwiseSensorEntityDescription( key="electricity_consumed_off_peak_interval", translation_key="electricity_consumed_off_peak_interval", icon="mdi:lightning-bolt", native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + value_fn=lambda data: data["sensors"]["electricity_consumed_off_peak_interval"], ), PlugwiseSensorEntityDescription( key="electricity_produced_interval", translation_key="electricity_produced_interval", icon="mdi:lightning-bolt", native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + value_fn=lambda data: data["sensors"]["electricity_produced_interval"], entity_registry_enabled_default=False, ), PlugwiseSensorEntityDescription( @@ -181,30 +223,37 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="electricity_produced_peak_interval", icon="mdi:lightning-bolt", native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + value_fn=lambda data: data["sensors"]["electricity_produced_peak_interval"], ), PlugwiseSensorEntityDescription( key="electricity_produced_off_peak_interval", translation_key="electricity_produced_off_peak_interval", icon="mdi:lightning-bolt", native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, + value_fn=lambda data: data["sensors"]["electricity_produced_off_peak_interval"], ), PlugwiseSensorEntityDescription( key="electricity_consumed_off_peak_point", translation_key="electricity_consumed_off_peak_point", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_consumed_off_peak_point"], ), PlugwiseSensorEntityDescription( key="electricity_consumed_peak_point", translation_key="electricity_consumed_peak_point", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_consumed_peak_point"], ), PlugwiseSensorEntityDescription( key="electricity_consumed_off_peak_cumulative", translation_key="electricity_consumed_off_peak_cumulative", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + value_fn=lambda data: data["sensors"][ + "electricity_consumed_off_peak_cumulative" + ], state_class=SensorStateClass.TOTAL_INCREASING, ), PlugwiseSensorEntityDescription( @@ -212,6 +261,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="electricity_consumed_peak_cumulative", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + value_fn=lambda data: data["sensors"]["electricity_consumed_peak_cumulative"], state_class=SensorStateClass.TOTAL_INCREASING, ), PlugwiseSensorEntityDescription( @@ -219,24 +269,30 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="electricity_produced_off_peak_point", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_produced_off_peak_point"], ), PlugwiseSensorEntityDescription( key="electricity_produced_peak_point", translation_key="electricity_produced_peak_point", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_produced_peak_point"], ), PlugwiseSensorEntityDescription( key="electricity_produced_off_peak_cumulative", translation_key="electricity_produced_off_peak_cumulative", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + value_fn=lambda data: data["sensors"][ + "electricity_produced_off_peak_cumulative" + ], state_class=SensorStateClass.TOTAL_INCREASING, ), PlugwiseSensorEntityDescription( key="electricity_produced_peak_cumulative", translation_key="electricity_produced_peak_cumulative", native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + value_fn=lambda data: data["sensors"]["electricity_produced_peak_cumulative"], device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, ), @@ -246,42 +302,49 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): name="Electricity phase one consumed", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_phase_one_consumed"], ), PlugwiseSensorEntityDescription( key="electricity_phase_two_consumed", translation_key="electricity_phase_two_consumed", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_phase_two_consumed"], ), PlugwiseSensorEntityDescription( key="electricity_phase_three_consumed", translation_key="electricity_phase_three_consumed", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_phase_three_consumed"], ), PlugwiseSensorEntityDescription( key="electricity_phase_one_produced", translation_key="electricity_phase_one_produced", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_phase_one_produced"], ), PlugwiseSensorEntityDescription( key="electricity_phase_two_produced", translation_key="electricity_phase_two_produced", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_phase_two_produced"], ), PlugwiseSensorEntityDescription( key="electricity_phase_three_produced", translation_key="electricity_phase_three_produced", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["electricity_phase_three_produced"], ), PlugwiseSensorEntityDescription( key="voltage_phase_one", translation_key="voltage_phase_one", device_class=SensorDeviceClass.VOLTAGE, native_unit_of_measurement=UnitOfElectricPotential.VOLT, + value_fn=lambda data: data["sensors"]["voltage_phase_one"], entity_registry_enabled_default=False, ), PlugwiseSensorEntityDescription( @@ -289,6 +352,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="voltage_phase_two", device_class=SensorDeviceClass.VOLTAGE, native_unit_of_measurement=UnitOfElectricPotential.VOLT, + value_fn=lambda data: data["sensors"]["voltage_phase_two"], entity_registry_enabled_default=False, ), PlugwiseSensorEntityDescription( @@ -296,6 +360,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="voltage_phase_three", device_class=SensorDeviceClass.VOLTAGE, native_unit_of_measurement=UnitOfElectricPotential.VOLT, + value_fn=lambda data: data["sensors"]["voltage_phase_three"], entity_registry_enabled_default=False, ), PlugwiseSensorEntityDescription( @@ -303,12 +368,14 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="gas_consumed_interval", icon="mdi:meter-gas", native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR, + value_fn=lambda data: data["sensors"]["gas_consumed_interval"], ), PlugwiseSensorEntityDescription( key="gas_consumed_cumulative", translation_key="gas_consumed_cumulative", device_class=SensorDeviceClass.GAS, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, + value_fn=lambda data: data["sensors"]["gas_consumed_cumulative"], state_class=SensorStateClass.TOTAL_INCREASING, ), PlugwiseSensorEntityDescription( @@ -316,12 +383,14 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): translation_key="net_electricity_point", device_class=SensorDeviceClass.POWER, native_unit_of_measurement=UnitOfPower.WATT, + value_fn=lambda data: data["sensors"]["net_electricity_point"], ), PlugwiseSensorEntityDescription( key="net_electricity_cumulative", translation_key="net_electricity_cumulative", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + value_fn=lambda data: data["sensors"]["net_electricity_cumulative"], state_class=SensorStateClass.TOTAL, ), PlugwiseSensorEntityDescription( @@ -330,18 +399,21 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.BATTERY, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=PERCENTAGE, + value_fn=lambda data: data["sensors"]["battery"], ), PlugwiseSensorEntityDescription( key="illuminance", translation_key="illuminance", device_class=SensorDeviceClass.ILLUMINANCE, native_unit_of_measurement=LIGHT_LUX, + value_fn=lambda data: data["sensors"]["illuminance"], ), PlugwiseSensorEntityDescription( key="modulation_level", translation_key="modulation_level", entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=PERCENTAGE, + value_fn=lambda data: data["sensors"]["modulation_level"], icon="mdi:percent", ), PlugwiseSensorEntityDescription( @@ -350,6 +422,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:valve", entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=PERCENTAGE, + value_fn=lambda data: data["sensors"]["valve_position"], ), PlugwiseSensorEntityDescription( key="water_pressure", @@ -357,19 +430,22 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.PRESSURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfPressure.BAR, + value_fn=lambda data: data["sensors"]["water_pressure"], ), - PlugwiseSensorEntityDescription( - key="relative_humidity", - translation_key="relative_humidity", - device_class=SensorDeviceClass.HUMIDITY, - native_unit_of_measurement=PERCENTAGE, - ), + # PlugwiseSensorEntityDescription( + # key="relative_humidity", + # translation_key="relative_humidity", + # device_class=SensorDeviceClass.HUMIDITY, + # native_unit_of_measurement=PERCENTAGE, + # value_fn=lambda data: data["sensors"]["relative_humidity"], + # ), PlugwiseSensorEntityDescription( key="dhw_temperature", translation_key="dhw_temperature", device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["dhw_temperature"], ), PlugwiseSensorEntityDescription( key="domestic_hot_water_setpoint", @@ -377,6 +453,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], ), PlugwiseSensorEntityDescription( key="maximum_boiler_temperature", @@ -384,6 +461,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["intended_boiler_temperature"], ), ) diff --git a/custom_components/plugwise/sensor.py b/custom_components/plugwise/sensor.py index 456818a50..d74a9b144 100644 --- a/custom_components/plugwise/sensor.py +++ b/custom_components/plugwise/sensor.py @@ -47,6 +47,8 @@ async def async_setup_entry( class PlugwiseSensorEntity(PlugwiseEntity, SensorEntity): """Represent Plugwise Sensors.""" + entity_description: PlugwiseSensorEntityDescription + def __init__( self, coordinator: PlugwiseDataUpdateCoordinator, @@ -61,4 +63,4 @@ def __init__( @property def native_value(self) -> int | float: """Return the value reported by the sensor.""" - return self.device["sensors"][self.entity_description.key] # type: ignore [literal-required] + return self.entity_description.value_fn(self.device) From 7d836074df4ff9b5cea3da7df555e5e1b18c1e3e Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 1 May 2023 18:39:21 +0200 Subject: [PATCH 17/52] Fix TODO's --- custom_components/plugwise/models.py | 65 ++++++++++------------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 2b5f2428d..74935fe5d 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -59,23 +59,6 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon_off: str | None = None -# TODO - -# Not existing in SmileSensors -# Breaking to pw-beta tests -# value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], - -# Non-breaking to pw-beta tests -# relative_humidity -# cooling_setpoint -# heating_setpoint - -# Are these the same? (i.e. there is no maximum in SmileSensors) -# key="maximum_boiler_temperature", -# value_fn=lambda data: data["sensors"]["intended_boiler_temperature"], - -# /TODO - PW_SENSOR_TYPES: tuple[PlugwiseSensorEntityDescription, ...] = ( PlugwiseSensorEntityDescription( key="setpoint", @@ -85,22 +68,22 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): native_unit_of_measurement=UnitOfTemperature.CELSIUS, value_fn=lambda data: data["sensors"]["setpoint"], ), - # PlugwiseSensorEntityDescription( - # key="cooling_setpoint", - # translation_key="cooling_setpoint", - # device_class=SensorDeviceClass.TEMPERATURE, - # entity_category=EntityCategory.DIAGNOSTIC, - # native_unit_of_measurement=UnitOfTemperature.CELSIUS, - # value_fn=lambda data: data["sensors"]["cooling_setpoint"], - # ), - # PlugwiseSensorEntityDescription( - # key="heating_setpoint", - # translation_key="heating_setpoint", - # device_class=SensorDeviceClass.TEMPERATURE, - # entity_category=EntityCategory.DIAGNOSTIC, - # native_unit_of_measurement=UnitOfTemperature.CELSIUS, - # value_fn=lambda data: data["sensors"]["heating_setpoint"], - # ), + PlugwiseSensorEntityDescription( + key="cooling_setpoint", + translation_key="cooling_setpoint", + device_class=SensorDeviceClass.TEMPERATURE, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["setpoint_high"], + ), + PlugwiseSensorEntityDescription( + key="heating_setpoint", + translation_key="heating_setpoint", + device_class=SensorDeviceClass.TEMPERATURE, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["sensors"]["setpoint_low"], + ), PlugwiseSensorEntityDescription( key="temperature", translation_key="temperature", @@ -432,13 +415,13 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): native_unit_of_measurement=UnitOfPressure.BAR, value_fn=lambda data: data["sensors"]["water_pressure"], ), - # PlugwiseSensorEntityDescription( - # key="relative_humidity", - # translation_key="relative_humidity", - # device_class=SensorDeviceClass.HUMIDITY, - # native_unit_of_measurement=PERCENTAGE, - # value_fn=lambda data: data["sensors"]["relative_humidity"], - # ), + PlugwiseSensorEntityDescription( + key="relative_humidity", + translation_key="relative_humidity", + device_class=SensorDeviceClass.HUMIDITY, + native_unit_of_measurement=PERCENTAGE, + value_fn=lambda data: data["sensors"]["humidity"], + ), PlugwiseSensorEntityDescription( key="dhw_temperature", translation_key="dhw_temperature", @@ -461,7 +444,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["sensors"]["intended_boiler_temperature"], + value_fn=lambda data: data["sensors"]["maximum_boiler_temperature"], ), ) From b0c02587bd36843965768cc2e2558527a2163e0a Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 1 May 2023 19:12:12 +0200 Subject: [PATCH 18/52] Fix the 2 actuator-sensors --- custom_components/plugwise/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 74935fe5d..60f6f6b50 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -436,7 +436,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], + value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], ), PlugwiseSensorEntityDescription( key="maximum_boiler_temperature", @@ -444,7 +444,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["sensors"]["maximum_boiler_temperature"], + value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], ), ) From 8a06771960587780b165ddae521632aea5b1fd05 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 1 May 2023 19:31:09 +0200 Subject: [PATCH 19/52] Binary --- custom_components/plugwise/binary_sensor.py | 3 ++- custom_components/plugwise/models.py | 12 +++++++++++- tests/components/plugwise/test_sensor.py | 7 ++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/custom_components/plugwise/binary_sensor.py b/custom_components/plugwise/binary_sensor.py index 1f3258646..05784030d 100644 --- a/custom_components/plugwise/binary_sensor.py +++ b/custom_components/plugwise/binary_sensor.py @@ -75,7 +75,8 @@ def is_on(self) -> bool: message, "Plugwise Notification:", f"{DOMAIN}.{notify_id}" ) - return self.device["binary_sensors"][self.entity_description.key] # type: ignore [literal-required] + # return self.device["binary_sensors"][self.entity_description.key] # type: ignore [literal-required] + return self.entity_description.value_fn(self.device) @property def icon(self) -> str | None: diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 60f6f6b50..4c661c2df 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -53,7 +53,9 @@ class PlugwiseSwitchEntityDescription(SwitchEntityDescription, PlugwiseSwitchBas @dataclass -class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): +class PlugwiseBinarySensorEntityDescription( + BinarySensorEntityDescription, PlugwiseSwitchBaseMixin +): """Describes Plugwise binary sensor entity.""" icon_off: str | None = None @@ -488,12 +490,14 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:hvac", icon_off="mdi:hvac-off", entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data["binary_sensors"]["compressor_state"], ), PlugwiseBinarySensorEntityDescription( key="cooling_enabled", translation_key="cooling_enabled", icon="mdi:snowflake-thermometer", entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data["binary_sensors"]["cooling_enabled"], ), PlugwiseBinarySensorEntityDescription( key="dhw_state", @@ -501,6 +505,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:water-pump", icon_off="mdi:water-pump-off", entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data["binary_sensors"]["dhw_state"], ), PlugwiseBinarySensorEntityDescription( key="flame_state", @@ -508,6 +513,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:fire", icon_off="mdi:fire-off", entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data["binary_sensors"]["flame_state"], ), PlugwiseBinarySensorEntityDescription( key="heating_state", @@ -515,6 +521,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:radiator", icon_off="mdi:radiator-off", entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data["binary_sensors"]["heating_state"], ), PlugwiseBinarySensorEntityDescription( key="cooling_state", @@ -522,6 +529,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:snowflake", icon_off="mdi:snowflake-off", entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data["binary_sensors"]["cooling_state"], ), PlugwiseBinarySensorEntityDescription( key="slave_boiler_state", @@ -529,6 +537,7 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:fire", icon_off="mdi:circle-off-outline", entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data["binary_sensors"]["slave_boiler_state"], ), PlugwiseBinarySensorEntityDescription( key="plugwise_notification", @@ -536,5 +545,6 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): icon="mdi:mailbox-up-outline", icon_off="mdi:mailbox-outline", entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data["binary_sensors"]["plugwise_notification"], ), ) diff --git a/tests/components/plugwise/test_sensor.py b/tests/components/plugwise/test_sensor.py index 663c63bf3..178813c3d 100644 --- a/tests/components/plugwise/test_sensor.py +++ b/tests/components/plugwise/test_sensor.py @@ -49,9 +49,10 @@ async def test_anna_as_smt_climate_sensor_entities( assert state assert float(state.state) == 29.1 - state = hass.states.get("sensor.opentherm_dhw_setpoint") - assert state - assert float(state.state) == 60.0 + # TODO + # state = hass.states.get("sensor.opentherm_dhw_setpoint") + # assert state + # assert float(state.state) == 60.0 state = hass.states.get("sensor.opentherm_dhw_temperature") assert state From bb29f537bd1ba8e55858b9a319b27189b185235e Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 1 May 2023 19:41:53 +0200 Subject: [PATCH 20/52] Mark sensors as TODO --- custom_components/plugwise/models.py | 34 +++++------ .../fixtures/p1v4_442_triple/all_data.json | 57 +++++++++++++++++++ .../p1v4_442_triple/notifications.json | 1 + 3 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json create mode 100644 tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 4c661c2df..d2fd7cb62 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -432,22 +432,24 @@ class PlugwiseBinarySensorEntityDescription( native_unit_of_measurement=UnitOfTemperature.CELSIUS, value_fn=lambda data: data["sensors"]["dhw_temperature"], ), - PlugwiseSensorEntityDescription( - key="domestic_hot_water_setpoint", - translation_key="domestic_hot_water_setpoint", - device_class=SensorDeviceClass.TEMPERATURE, - entity_category=EntityCategory.DIAGNOSTIC, - native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], - ), - PlugwiseSensorEntityDescription( - key="maximum_boiler_temperature", - translation_key="maximum_boiler_temperature", - device_class=SensorDeviceClass.TEMPERATURE, - entity_category=EntityCategory.DIAGNOSTIC, - native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], - ), +# TODO FIX +# PlugwiseSensorEntityDescription( +# key="domestic_hot_water_setpoint", +# translation_key="domestic_hot_water_setpoint", +# device_class=SensorDeviceClass.TEMPERATURE, +# entity_category=EntityCategory.DIAGNOSTIC, +# native_unit_of_measurement=UnitOfTemperature.CELSIUS, +# value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], +# ), +# TODO FIX +# PlugwiseSensorEntityDescription( +# key="maximum_boiler_temperature", +# translation_key="maximum_boiler_temperature", +# device_class=SensorDeviceClass.TEMPERATURE, +# entity_category=EntityCategory.DIAGNOSTIC, +# native_unit_of_measurement=UnitOfTemperature.CELSIUS, +# value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], +# ), ) PW_SWITCH_TYPES: tuple[PlugwiseSwitchEntityDescription, ...] = ( diff --git a/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json b/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json new file mode 100644 index 000000000..137210a04 --- /dev/null +++ b/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json @@ -0,0 +1,57 @@ +{ + "gateway": { + "smile_name": "Smile P1", + "gateway_id": "03e65b16e4b247a29ae0d75a78cb492e", + "notifications": {} + }, + "devices": { + "03e65b16e4b247a29ae0d75a78cb492e": { + "dev_class": "gateway", + "firmware": "4.4.2", + "hardware": "AME Smile 2.0 board", + "location": "03e65b16e4b247a29ae0d75a78cb492e", + "mac_address": "012345670001", + "model": "Gateway", + "name": "Smile P1", + "vendor": "Plugwise", + "binary_sensors": { + "plugwise_notification": false + } + }, + "b82b6b3322484f2ea4e25e0bd5f3d61f": { + "dev_class": "smartmeter", + "location": "03e65b16e4b247a29ae0d75a78cb492e", + "model": "XMX5LGF0010453051839", + "name": "P1", + "vendor": "XEMEX NV", + "available": true, + "sensors": { + "net_electricity_point": 5553, + "electricity_consumed_peak_point": 0, + "electricity_consumed_off_peak_point": 5553, + "net_electricity_cumulative": 231866.539, + "electricity_consumed_peak_cumulative": 161328.641, + "electricity_consumed_off_peak_cumulative": 70537.898, + "electricity_consumed_peak_interval": 0, + "electricity_consumed_off_peak_interval": 314, + "electricity_produced_peak_point": 0, + "electricity_produced_off_peak_point": 0, + "electricity_produced_peak_cumulative": 0.0, + "electricity_produced_off_peak_cumulative": 0.0, + "electricity_produced_peak_interval": 0, + "electricity_produced_off_peak_interval": 0, + "electricity_phase_one_consumed": 1763, + "electricity_phase_two_consumed": 1703, + "electricity_phase_three_consumed": 2080, + "electricity_phase_one_produced": 0, + "electricity_phase_two_produced": 0, + "electricity_phase_three_produced": 0, + "gas_consumed_cumulative": 16811.37, + "gas_consumed_interval": 0.06, + "voltage_phase_one": 233.2, + "voltage_phase_two": 234.4, + "voltage_phase_three": 234.7 + } + } + } +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json b/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json @@ -0,0 +1 @@ +{} From 85a76e24ea901ec82ba8345dafa411ddfe523356 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 17:42:23 +0000 Subject: [PATCH 21/52] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- custom_components/plugwise/models.py | 36 +++++++++---------- .../fixtures/p1v4_442_triple/all_data.json | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index d2fd7cb62..f3abba9e2 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -432,24 +432,24 @@ class PlugwiseBinarySensorEntityDescription( native_unit_of_measurement=UnitOfTemperature.CELSIUS, value_fn=lambda data: data["sensors"]["dhw_temperature"], ), -# TODO FIX -# PlugwiseSensorEntityDescription( -# key="domestic_hot_water_setpoint", -# translation_key="domestic_hot_water_setpoint", -# device_class=SensorDeviceClass.TEMPERATURE, -# entity_category=EntityCategory.DIAGNOSTIC, -# native_unit_of_measurement=UnitOfTemperature.CELSIUS, -# value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], -# ), -# TODO FIX -# PlugwiseSensorEntityDescription( -# key="maximum_boiler_temperature", -# translation_key="maximum_boiler_temperature", -# device_class=SensorDeviceClass.TEMPERATURE, -# entity_category=EntityCategory.DIAGNOSTIC, -# native_unit_of_measurement=UnitOfTemperature.CELSIUS, -# value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], -# ), + # TODO FIX + # PlugwiseSensorEntityDescription( + # key="domestic_hot_water_setpoint", + # translation_key="domestic_hot_water_setpoint", + # device_class=SensorDeviceClass.TEMPERATURE, + # entity_category=EntityCategory.DIAGNOSTIC, + # native_unit_of_measurement=UnitOfTemperature.CELSIUS, + # value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], + # ), + # TODO FIX + # PlugwiseSensorEntityDescription( + # key="maximum_boiler_temperature", + # translation_key="maximum_boiler_temperature", + # device_class=SensorDeviceClass.TEMPERATURE, + # entity_category=EntityCategory.DIAGNOSTIC, + # native_unit_of_measurement=UnitOfTemperature.CELSIUS, + # value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], + # ), ) PW_SWITCH_TYPES: tuple[PlugwiseSwitchEntityDescription, ...] = ( diff --git a/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json b/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json index 137210a04..4ba77c1e2 100644 --- a/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json +++ b/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json @@ -54,4 +54,4 @@ } } } -} \ No newline at end of file +} From 8da7c1da1025f45dbfb4a791d4908f7f335eecb0 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 1 May 2023 21:51:50 +0200 Subject: [PATCH 22/52] Fix number and select (not working, fixtures next) --- custom_components/plugwise/number.py | 56 ++++++++++++++++------------ custom_components/plugwise/select.py | 16 ++++++-- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 2b44ae841..9829c5e28 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -14,7 +14,7 @@ from homeassistant.const import TEMP_CELSIUS, EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from plugwise import Smile +from plugwise import Smile, DeviceData from .const import COORDINATOR # pw-beta from .const import DOMAIN, LOGGER @@ -27,6 +27,10 @@ class PlugwiseEntityDescriptionMixin: """Mixin values for Plugwse entities.""" command: Callable[[Smile, str, float], Awaitable[None]] + native_max_value_fn: Callable[[DeviceData], str] + native_min_value_fn: Callable[[DeviceData], str] + native_step_key_fn: Callable[[DeviceData], str] + native_value_fn: Callable[[DeviceData], str] @dataclass @@ -48,11 +52,11 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_key="upper_bound", - native_min_value_key="lower_bound", - native_step_key="resolution", + native_max_value_fn=lambda data: data["thermostat"]["upper_bound"], + native_min_value_fn=lambda data: data["thermostat"]["lower_bound"], + native_step_key_fn=lambda data: data["thermostat"]["resolution"], + native_value_fn=lambda data: data["thermostat"]["setpoint"], native_unit_of_measurement=TEMP_CELSIUS, - native_value_key="setpoint", ), PlugwiseNumberEntityDescription( key="domestic_hot_water_setpoint", @@ -60,11 +64,11 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_key="upper_bound", - native_min_value_key="lower_bound", - native_step_key="resolution", + native_max_value_fn=lambda data: data["thermostat"]["upper_bound"], + native_min_value_fn=lambda data: data["thermostat"]["lower_bound"], + native_step_key_fn=lambda data: data["thermostat"]["resolution"], + native_value_fn=lambda data: data["thermostat"]["setpoint"], native_unit_of_measurement=TEMP_CELSIUS, - native_value_key="setpoint", ), ) @@ -112,33 +116,37 @@ def __init__( @property def native_step(self) -> float: """Return the setpoint step value.""" - return max( - self.device[self.entity_description.key][ # type: ignore [literal-required] - self.entity_description.native_step_key - ], - 1, - ) + # return max( + # self.device[self.entity_description.key][ # type: ignore [literal-required] + # self.entity_description.native_step_key + # ], + # 1, + # ) + return self.entity_description.native_step_key_fn(self.device) # type: ignore [literal-required] @property def native_value(self) -> float: """Return the present setpoint value.""" - return self.device[self.entity_description.key][ # type: ignore [literal-required] - self.entity_description.native_value_key - ] + # return self.device[self.entity_description.key][ # type: ignore [literal-required] + # self.entity_description.native_value_key + # ] + return self.entity_description.native_value_fn(self.device) # type: ignore [literal-required] @property def native_min_value(self) -> float: """Return the setpoint min. value.""" - return self.device[self.entity_description.key][ # type: ignore [literal-required] - self.entity_description.native_min_value_key - ] + # return self.device[self.entity_description.key][ # type: ignore [literal-required] + # self.entity_description.native_min_value_key + # ] + return self.entity_description.native_min_value_fn(self.device) @property def native_max_value(self) -> float: """Return the setpoint max. value.""" - return self.device[self.entity_description.key][ # type: ignore [literal-required] - self.entity_description.native_max_value_key - ] + # return self.device[self.entity_description.key][ # type: ignore [literal-required] + # self.entity_description.native_max_value_key + # ] + return self.entity_description.native_max_value_fn(self.device) async def async_set_native_value(self, value: float) -> None: """Change to the new setpoint value.""" diff --git a/custom_components/plugwise/select.py b/custom_components/plugwise/select.py index 24615847f..add0aa030 100644 --- a/custom_components/plugwise/select.py +++ b/custom_components/plugwise/select.py @@ -10,7 +10,7 @@ from homeassistant.const import STATE_ON, EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from plugwise import Smile +from plugwise import Smile, DeviceData from .const import COORDINATOR # pw-beta from .const import DOMAIN, LOGGER @@ -25,6 +25,8 @@ class PlugwiseSelectDescriptionMixin: """Mixin values for Plugwise Select entities.""" command: Callable[[Smile, str, str], Awaitable[Any]] + value_fn: Callable[[DeviceData], str] + values_fn: Callable[[DeviceData], list[str]] current_option_key: str options_key: str @@ -44,6 +46,8 @@ class PlugwiseSelectEntityDescription( command=lambda api, loc, opt: api.set_schedule_state(loc, opt, STATE_ON), current_option_key="selected_schedule", options_key="available_schedules", + value_fn=lambda data: data["selected_schedule"], + values_fn=lambda data: data["available_schedules"], ), PlugwiseSelectEntityDescription( key="select_regulation_mode", @@ -53,6 +57,8 @@ class PlugwiseSelectEntityDescription( command=lambda api, loc, opt: api.set_regulation_mode(opt), current_option_key="regulation_mode", options_key="regulation_modes", + value_fn=lambda data: data["regulation_mode"], + values_fn=lambda data: data["regulation_modes"], ), PlugwiseSelectEntityDescription( key="select_dhw_mode", @@ -62,6 +68,8 @@ class PlugwiseSelectEntityDescription( command=lambda api, loc, opt: api.set_dhw_mode(opt), current_option_key="dhw_mode", options_key="dhw_modes", + value_fn=lambda data: data["dhw_mode"], + values_fn=lambda data: data["dhw_modes"], ), ) @@ -110,12 +118,14 @@ def __init__( @property def current_option(self) -> str: """Return the selected entity option to represent the entity state.""" - return self.device[self.entity_description.current_option_key] # type: ignore [literal-required] + # return self.device[self.entity_description.current_option_key] # type: ignore [literal-required] + return self.entity_description.value_fn(self.device) @property def options(self) -> list[str]: """Return the selectable entity options.""" - return self.device[self.entity_description.options_key] # type: ignore [literal-required] + # return self.device[self.entity_description.options_key] # type: ignore [literal-required] + return self.entity_description.values_fn(self.device) async def async_select_option(self, option: str) -> None: """Change to the selected entity option.""" From b0b1cf25e77db2e41385d2bce207643d56acb597 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 19:52:36 +0000 Subject: [PATCH 23/52] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- custom_components/plugwise/number.py | 2 +- custom_components/plugwise/select.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 9829c5e28..4f1c7eb75 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -14,7 +14,7 @@ from homeassistant.const import TEMP_CELSIUS, EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from plugwise import Smile, DeviceData +from plugwise import DeviceData, Smile from .const import COORDINATOR # pw-beta from .const import DOMAIN, LOGGER diff --git a/custom_components/plugwise/select.py b/custom_components/plugwise/select.py index add0aa030..8d999c9c3 100644 --- a/custom_components/plugwise/select.py +++ b/custom_components/plugwise/select.py @@ -10,7 +10,7 @@ from homeassistant.const import STATE_ON, EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from plugwise import Smile, DeviceData +from plugwise import DeviceData, Smile from .const import COORDINATOR # pw-beta from .const import DOMAIN, LOGGER From adb350c2f5502d7475be186bd8f6f67ba31954d6 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Tue, 2 May 2023 00:14:16 +0200 Subject: [PATCH 24/52] Fix fixtures (4 TODO left), expected increase of strict again --- CHANGELOG.md | 3 + custom_components/plugwise/number.py | 22 ++++--- tests/components/plugwise/conftest.py | 38 +++++++++---- .../all_data.json | 8 +-- .../anna_heatpump_heating/all_data.json | 12 ++-- .../fixtures/m_adam_cooling/all_data.json | 32 +++++------ .../fixtures/m_adam_heating/all_data.json | 29 +++++----- .../m_anna_heatpump_cooling/all_data.json | 20 +++---- .../m_anna_heatpump_idle/all_data.json | 21 +++---- .../fixtures/p1v3_full_option/all_data.json | 8 +-- .../plugwise/fixtures/p1v4_3ph/all_data.json | 57 ------------------- .../fixtures/p1v4_3ph/notifications.json | 1 - .../fixtures/stretch_v31/all_data.json | 8 +-- tests/components/plugwise/test_number.py | 37 ++++++------ 14 files changed, 132 insertions(+), 164 deletions(-) delete mode 100644 tests/components/plugwise/fixtures/p1v4_3ph/all_data.json delete mode 100644 tests/components/plugwise/fixtures/p1v4_3ph/notifications.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 05f2b9f82..2c2947dc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Ongoing / Unreleased - CI improvements +- Typing improvements +- Dynamic generated fixtures re-introduced +- TODO: rework marked TODOs ### 0.40.1 diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 4f1c7eb75..6c0bee1e0 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -52,10 +52,16 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["thermostat"]["upper_bound"], - native_min_value_fn=lambda data: data["thermostat"]["lower_bound"], - native_step_key_fn=lambda data: data["thermostat"]["resolution"], - native_value_fn=lambda data: data["thermostat"]["setpoint"], + native_max_value_fn=lambda data: data["maximum_boiler_temperature"][ + "upper_bound" + ], + native_min_value_fn=lambda data: data["maximum_boiler_temperature"][ + "lower_bound" + ], + native_step_key_fn=lambda data: data["maximum_boiler_temperature"][ + "resolution" + ], + native_value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], native_unit_of_measurement=TEMP_CELSIUS, ), PlugwiseNumberEntityDescription( @@ -64,10 +70,10 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["thermostat"]["upper_bound"], - native_min_value_fn=lambda data: data["thermostat"]["lower_bound"], - native_step_key_fn=lambda data: data["thermostat"]["resolution"], - native_value_fn=lambda data: data["thermostat"]["setpoint"], + native_max_value_fn=lambda data: data["domestic_hot_water"]["upper_bound"], + native_min_value_fn=lambda data: data["domestic_hot_water"]["lower_bound"], + native_step_key_fn=lambda data: data["domestic_hot_water"]["resolution"], + native_value_fn=lambda data: data["domestic_hot_water"]["setpoint"], native_unit_of_measurement=TEMP_CELSIUS, ), ) diff --git a/tests/components/plugwise/conftest.py b/tests/components/plugwise/conftest.py index 5259cfb36..cf16b2c4d 100644 --- a/tests/components/plugwise/conftest.py +++ b/tests/components/plugwise/conftest.py @@ -91,7 +91,9 @@ def mock_smile_adam() -> Generator[None, MagicMock, None]: smile.notifications = _read_json(chosen_env, "notifications") all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile @@ -118,7 +120,9 @@ def mock_smile_adam_2() -> Generator[None, MagicMock, None]: smile.notifications = _read_json(chosen_env, "notifications") all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile @@ -145,7 +149,9 @@ def mock_smile_adam_3() -> Generator[None, MagicMock, None]: smile.notifications = _read_json(chosen_env, "notifications") all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile @@ -171,7 +177,9 @@ def mock_smile_anna() -> Generator[None, MagicMock, None]: smile.notifications = _read_json(chosen_env, "notifications") all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile @@ -197,7 +205,9 @@ def mock_smile_anna_2() -> Generator[None, MagicMock, None]: smile.notifications = _read_json(chosen_env, "notifications") all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile @@ -223,7 +233,9 @@ def mock_smile_anna_3() -> Generator[None, MagicMock, None]: smile.notifications = _read_json(chosen_env, "notifications") all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile @@ -249,7 +261,9 @@ def mock_smile_p1() -> Generator[None, MagicMock, None]: smile.notifications = _read_json(chosen_env, "notifications") all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile @@ -257,7 +271,7 @@ def mock_smile_p1() -> Generator[None, MagicMock, None]: @pytest.fixture def mock_smile_p1_2() -> Generator[None, MagicMock, None]: """Create a Mock P1 3-phase DSMR environment for testing exceptions.""" - chosen_env = "p1v4_3ph" + chosen_env = "p1v4_442_triple" with patch( "homeassistant.components.plugwise.coordinator.Smile", autospec=True ) as smile_mock: @@ -275,7 +289,9 @@ def mock_smile_p1_2() -> Generator[None, MagicMock, None]: smile.notifications = _read_json(chosen_env, "notifications") all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile @@ -299,7 +315,9 @@ def mock_stretch() -> Generator[None, MagicMock, None]: smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") - smile.async_update.return_value = PlugwiseData(all_data[0], all_data[1]) + smile.async_update.return_value = PlugwiseData( + all_data["gateway"], all_data["devices"] + ) yield smile diff --git a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json index d62ff0e24..2d59f7797 100644 --- a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json +++ b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json @@ -1,5 +1,5 @@ -[ - { +{ + "gateway": { "smile_name": "Adam", "gateway_id": "fe799307f1624099878210aa0b9f1475", "heater_id": "90986d591dcd426cae3ec3e8111ff730", @@ -10,7 +10,7 @@ } } }, - { + "devices": { "df4a4a8169904cdb9c03d61a21f42140": { "dev_class": "zone_thermostat", "firmware": "2016-10-27T02:00:00+02:00", @@ -426,4 +426,4 @@ } } } -] +} diff --git a/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json b/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json index f00293a65..50e8bd13e 100644 --- a/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json +++ b/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json @@ -1,16 +1,16 @@ -[ - { +{ + "gateway": { "smile_name": "Smile Anna", "gateway_id": "015ae9ea3f964e668e490fa39da3870b", "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", "cooling_present": false, "notifications": {} }, - { + "devices": { "1cbf783bb11e4a7c8a6843dee3a86927": { "dev_class": "heater_central", "location": "a57efe5f145f498c9be62a9b63626fbf", - "model": "Generic heater/cooler", + "model": "Generic heater", "name": "OpenTherm", "vendor": "Techneco", "maximum_boiler_temperature": { @@ -21,10 +21,10 @@ }, "available": true, "binary_sensors": { - "cooling_enabled": false, "dhw_state": false, "heating_state": true, "compressor_state": true, + "cooling_enabled": false, "slave_boiler_state": false, "flame_state": false }, @@ -87,4 +87,4 @@ } } } -] +} diff --git a/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json b/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json index 06a3fa400..40ecebfbd 100644 --- a/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json @@ -1,12 +1,12 @@ -[ - { +{ + "gateway": { "smile_name": "Adam", "gateway_id": "da224107914542988a88561b4452b0f6", "heater_id": "056ee145a816487eaa69243c3280f8bf", "cooling_present": true, "notifications": {} }, - { + "devices": { "ad4838d7d35c4d6ea796ee12ae5aedf8": { "dev_class": "thermostat", "location": "f2bf9048bef64cc5b6d5110154e33c81", @@ -14,13 +14,12 @@ "name": "Anna", "vendor": "Plugwise", "thermostat": { - "setpoint_low": 4.0, - "setpoint_high": 23.5, "lower_bound": 1.0, "upper_bound": 35.0, - "resolution": 0.01 + "resolution": 0.01, + "setpoint_low": 4.0, + "setpoint_high": 23.5 }, - "available": true, "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "active_preset": "asleep", "available_schedules": ["Weekschema", "Badkamer", "Test"], @@ -32,7 +31,8 @@ "temperature": 25.8, "setpoint_low": 4.0, "setpoint_high": 23.5 - } + }, + "available": true }, "1772a4ea304041adb83f357b751341ff": { "dev_class": "thermo_sensor", @@ -61,11 +61,11 @@ "zigbee_mac_address": "ABCD012345670A04", "vendor": "Plugwise", "thermostat": { - "setpoint_low": 19.0, - "setpoint_high": 25.0, "lower_bound": 0.0, "upper_bound": 99.9, - "resolution": 0.01 + "resolution": 0.01, + "setpoint_low": 19.0, + "setpoint_high": 25.0 }, "available": true, "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], @@ -94,11 +94,11 @@ "vendor": "Plugwise", "regulation_mode": "cooling", "regulation_modes": [ - "cooling", "heating", "off", "bleeding_cold", - "bleeding_hot" + "bleeding_hot", + "cooling" ], "binary_sensors": { "plugwise_notification": false @@ -120,10 +120,10 @@ }, "available": true, "binary_sensors": { - "cooling_state": true, "dhw_state": false, "heating_state": false, - "flame_state": false + "flame_state": false, + "cooling_state": true }, "sensors": { "water_temperature": 19.0, @@ -146,4 +146,4 @@ } } } -] +} diff --git a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json index 8ee3df544..aceeeb506 100644 --- a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json @@ -1,12 +1,12 @@ -[ - { +{ + "gateway": { "smile_name": "Adam", "gateway_id": "da224107914542988a88561b4452b0f6", "heater_id": "056ee145a816487eaa69243c3280f8bf", "cooling_present": false, "notifications": {} }, - { + "devices": { "ad4838d7d35c4d6ea796ee12ae5aedf8": { "dev_class": "thermostat", "location": "f2bf9048bef64cc5b6d5110154e33c81", @@ -14,12 +14,11 @@ "name": "Anna", "vendor": "Plugwise", "thermostat": { - "setpoint": 20.0, "lower_bound": 1.0, "upper_bound": 35.0, - "resolution": 0.01 + "resolution": 0.01, + "setpoint": 20.0 }, - "available": true, "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "active_preset": "asleep", "available_schedules": ["Weekschema", "Badkamer", "Test"], @@ -27,7 +26,11 @@ "last_used": "Weekschema", "control_state": "heating", "mode": "heat", - "sensors": { "temperature": 19.1, "setpoint": 20.0 } + "sensors": { + "temperature": 19.1, + "setpoint": 20.0 + }, + "available": true }, "1772a4ea304041adb83f357b751341ff": { "dev_class": "thermo_sensor", @@ -56,10 +59,10 @@ "zigbee_mac_address": "ABCD012345670A04", "vendor": "Plugwise", "thermostat": { - "setpoint": 15.0, "lower_bound": 0.0, "upper_bound": 99.9, - "resolution": 0.01 + "resolution": 0.01, + "setpoint": 15.0 }, "available": true, "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], @@ -105,12 +108,6 @@ "upper_bound": 95.0, "resolution": 0.01 }, - "domestic_hot_water_setpoint": { - "setpoint": 60.0, - "lower_bound": 40.0, - "upper_bound": 60.0, - "resolution": 0.01 - }, "available": true, "binary_sensors": { "dhw_state": false, @@ -138,4 +135,4 @@ } } } -] +} diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json index ba980a7fc..490f3def7 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json @@ -1,12 +1,12 @@ -[ - { +{ + "gateway": { "smile_name": "Smile Anna", "gateway_id": "015ae9ea3f964e668e490fa39da3870b", "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", "cooling_present": true, "notifications": {} }, - { + "devices": { "1cbf783bb11e4a7c8a6843dee3a86927": { "dev_class": "heater_central", "location": "a57efe5f145f498c9be62a9b63626fbf", @@ -21,13 +21,13 @@ }, "available": true, "binary_sensors": { - "cooling_enabled": true, "dhw_state": false, "heating_state": false, "compressor_state": true, - "cooling_state": true, + "cooling_enabled": true, "slave_boiler_state": false, - "flame_state": false + "flame_state": false, + "cooling_state": true }, "sensors": { "water_temperature": 22.7, @@ -68,11 +68,11 @@ "name": "Anna", "vendor": "Plugwise", "thermostat": { - "setpoint_low": 20.5, - "setpoint_high": 24.0, "lower_bound": 4.0, "upper_bound": 30.0, - "resolution": 0.1 + "resolution": 0.1, + "setpoint_low": 20.5, + "setpoint_high": 24.0 }, "preset_modes": ["no_frost", "home", "away", "asleep", "vacation"], "active_preset": "home", @@ -90,4 +90,4 @@ } } } -] +} diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json index 0a421be53..0beed5537 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json @@ -1,12 +1,12 @@ -[ - { +{ + "gateway": { "smile_name": "Smile Anna", "gateway_id": "015ae9ea3f964e668e490fa39da3870b", "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", "cooling_present": true, "notifications": {} }, - { + "devices": { "1cbf783bb11e4a7c8a6843dee3a86927": { "dev_class": "heater_central", "location": "a57efe5f145f498c9be62a9b63626fbf", @@ -21,16 +21,17 @@ }, "available": true, "binary_sensors": { - "cooling_enabled": true, "dhw_state": false, "heating_state": false, "compressor_state": false, - "cooling_state": false, + "cooling_enabled": true, "slave_boiler_state": false, - "flame_state": false + "flame_state": false, + "cooling_state": false }, "sensors": { "water_temperature": 19.1, + "domestic_hot_water_setpoint": 60.0, "dhw_temperature": 46.3, "intended_boiler_temperature": 18.0, "modulation_level": 0, @@ -67,11 +68,11 @@ "name": "Anna", "vendor": "Plugwise", "thermostat": { - "setpoint_low": 20.5, - "setpoint_high": 24.0, "lower_bound": 4.0, "upper_bound": 30.0, - "resolution": 0.1 + "resolution": 0.1, + "setpoint_low": 20.5, + "setpoint_high": 24.0 }, "preset_modes": ["no_frost", "home", "away", "asleep", "vacation"], "active_preset": "home", @@ -89,4 +90,4 @@ } } } -] +} diff --git a/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json b/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json index c52f33e63..f76b17b8a 100644 --- a/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json +++ b/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json @@ -1,10 +1,10 @@ -[ - { +{ + "gateway": { "smile_name": "Smile P1", "gateway_id": "cd3e822288064775a7c4afcdd70bdda2", "notifications": {} }, - { + "devices": { "cd3e822288064775a7c4afcdd70bdda2": { "dev_class": "gateway", "firmware": "3.3.9", @@ -45,4 +45,4 @@ } } } -] +} diff --git a/tests/components/plugwise/fixtures/p1v4_3ph/all_data.json b/tests/components/plugwise/fixtures/p1v4_3ph/all_data.json deleted file mode 100644 index 852ca2857..000000000 --- a/tests/components/plugwise/fixtures/p1v4_3ph/all_data.json +++ /dev/null @@ -1,57 +0,0 @@ -[ - { - "smile_name": "Smile P1", - "gateway_id": "03e65b16e4b247a29ae0d75a78cb492e", - "notifications": {} - }, - { - "03e65b16e4b247a29ae0d75a78cb492e": { - "dev_class": "gateway", - "firmware": "4.4.2", - "hardware": "AME Smile 2.0 board", - "location": "03e65b16e4b247a29ae0d75a78cb492e", - "mac_address": "012345670001", - "model": "Gateway", - "name": "Smile P1", - "vendor": "Plugwise", - "binary_sensors": { - "plugwise_notification": false - } - }, - "b82b6b3322484f2ea4e25e0bd5f3d61f": { - "dev_class": "smartmeter", - "location": "03e65b16e4b247a29ae0d75a78cb492e", - "model": "XMX5LGF0010453051839", - "name": "P1", - "vendor": "XEMEX NV", - "available": true, - "sensors": { - "net_electricity_point": 5553, - "electricity_consumed_peak_point": 0, - "electricity_consumed_off_peak_point": 5553, - "net_electricity_cumulative": 231866.539, - "electricity_consumed_peak_cumulative": 161328.641, - "electricity_consumed_off_peak_cumulative": 70537.898, - "electricity_consumed_peak_interval": 0, - "electricity_consumed_off_peak_interval": 314, - "electricity_produced_peak_point": 0, - "electricity_produced_off_peak_point": 0, - "electricity_produced_peak_cumulative": 0.0, - "electricity_produced_off_peak_cumulative": 0.0, - "electricity_produced_peak_interval": 0, - "electricity_produced_off_peak_interval": 0, - "electricity_phase_one_consumed": 1763, - "electricity_phase_two_consumed": 1703, - "electricity_phase_three_consumed": 2080, - "electricity_phase_one_produced": 0, - "electricity_phase_two_produced": 0, - "electricity_phase_three_produced": 0, - "gas_consumed_cumulative": 16811.37, - "gas_consumed_interval": 0.06, - "voltage_phase_one": 233.2, - "voltage_phase_two": 234.4, - "voltage_phase_three": 234.7 - } - } - } -] diff --git a/tests/components/plugwise/fixtures/p1v4_3ph/notifications.json b/tests/components/plugwise/fixtures/p1v4_3ph/notifications.json deleted file mode 100644 index 0967ef424..000000000 --- a/tests/components/plugwise/fixtures/p1v4_3ph/notifications.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/components/plugwise/fixtures/stretch_v31/all_data.json b/tests/components/plugwise/fixtures/stretch_v31/all_data.json index 1ce34e376..ecd173f92 100644 --- a/tests/components/plugwise/fixtures/stretch_v31/all_data.json +++ b/tests/components/plugwise/fixtures/stretch_v31/all_data.json @@ -1,10 +1,10 @@ -[ - { +{ + "gateway": { "smile_name": "Stretch", "gateway_id": "0000aaaa0000aaaa0000aaaa0000aa00", "notifications": {} }, - { + "devices": { "0000aaaa0000aaaa0000aaaa0000aa00": { "dev_class": "gateway", "firmware": "3.1.11", @@ -147,4 +147,4 @@ } } } -] +} diff --git a/tests/components/plugwise/test_number.py b/tests/components/plugwise/test_number.py index f2a42bb1d..035f2e36f 100644 --- a/tests/components/plugwise/test_number.py +++ b/tests/components/plugwise/test_number.py @@ -42,21 +42,22 @@ async def test_anna_max_boiler_temp_change( ) -async def test_adam_dhw_setpoint_change( - hass: HomeAssistant, mock_smile_adam_2: MagicMock, init_integration: MockConfigEntry -) -> None: - """Test changing of number entities.""" - await hass.services.async_call( - NUMBER_DOMAIN, - SERVICE_SET_VALUE, - { - ATTR_ENTITY_ID: "number.opentherm_domestic_hot_water_setpoint", - ATTR_VALUE: 55, - }, - blocking=True, - ) - - assert mock_smile_adam_2.set_number_setpoint.call_count == 1 - mock_smile_adam_2.set_number_setpoint.assert_called_with( - "domestic_hot_water_setpoint", 55.0 - ) +# TODO: Broken, might be fixture failing +# async def test_adam_dhw_setpoint_change( +# hass: HomeAssistant, mock_smile_adam_2: MagicMock, init_integration: MockConfigEntry +# ) -> None: +# """Test changing of number entities.""" +# await hass.services.async_call( +# NUMBER_DOMAIN, +# SERVICE_SET_VALUE, +# { +# ATTR_ENTITY_ID: "number.opentherm_domestic_hot_water_setpoint", +# ATTR_VALUE: 55, +# }, +# blocking=True, +# ) +# +# assert mock_smile_adam_2.set_number_setpoint.call_count == 1 +# mock_smile_adam_2.set_number_setpoint.assert_called_with( +# "domestic_hot_water_setpoint", 55.0 +# ) From 65d934945d7fdfe5d65cfd4b2dbad0070fffe216 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Tue, 2 May 2023 09:43:33 +0200 Subject: [PATCH 25/52] Use TypeVar --- custom_components/plugwise/models.py | 7 +++++-- custom_components/plugwise/number.py | 15 +++++++++------ custom_components/plugwise/select.py | 8 +++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index f3abba9e2..bfcf93190 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -3,6 +3,7 @@ from collections.abc import Callable from dataclasses import dataclass +from typing import TypeVar from homeassistant.components.binary_sensor import BinarySensorEntityDescription from homeassistant.components.sensor import ( @@ -25,19 +26,21 @@ ) from plugwise import DeviceData +T = TypeVar("T", bound=DeviceData) + @dataclass class PlugwiseSensorBaseMixin: """Mixin for required Plugwise sensor base description keys.""" - value_fn: Callable[[DeviceData], float | int] + value_fn: Callable[[T], float | int] @dataclass class PlugwiseSwitchBaseMixin: """Mixin for required Plugwise switch base description keys.""" - value_fn: Callable[[DeviceData], bool] + value_fn: Callable[[T], bool] @dataclass diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 6c0bee1e0..286596650 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -3,6 +3,7 @@ from collections.abc import Awaitable, Callable from dataclasses import dataclass +from typing import TypeVar from homeassistant.components.number import ( NumberDeviceClass, @@ -21,16 +22,18 @@ from .coordinator import PlugwiseDataUpdateCoordinator from .entity import PlugwiseEntity +T = TypeVar("T", bound=DeviceData) + @dataclass class PlugwiseEntityDescriptionMixin: """Mixin values for Plugwse entities.""" command: Callable[[Smile, str, float], Awaitable[None]] - native_max_value_fn: Callable[[DeviceData], str] - native_min_value_fn: Callable[[DeviceData], str] - native_step_key_fn: Callable[[DeviceData], str] - native_value_fn: Callable[[DeviceData], str] + native_max_value_fn: Callable[[T], float] + native_min_value_fn: Callable[[T], float] + native_step_key_fn: Callable[[T], float] + native_value_fn: Callable[[T], float] @dataclass @@ -128,7 +131,7 @@ def native_step(self) -> float: # ], # 1, # ) - return self.entity_description.native_step_key_fn(self.device) # type: ignore [literal-required] + return self.entity_description.native_step_key_fn(self.device) @property def native_value(self) -> float: @@ -136,7 +139,7 @@ def native_value(self) -> float: # return self.device[self.entity_description.key][ # type: ignore [literal-required] # self.entity_description.native_value_key # ] - return self.entity_description.native_value_fn(self.device) # type: ignore [literal-required] + return self.entity_description.native_value_fn(self.device) @property def native_min_value(self) -> float: diff --git a/custom_components/plugwise/select.py b/custom_components/plugwise/select.py index 8d999c9c3..c96b556cb 100644 --- a/custom_components/plugwise/select.py +++ b/custom_components/plugwise/select.py @@ -3,7 +3,7 @@ from collections.abc import Awaitable, Callable from dataclasses import dataclass -from typing import Any +from typing import Any, TypeVar from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.config_entries import ConfigEntry @@ -19,14 +19,16 @@ PARALLEL_UPDATES = 0 +T = TypeVar("T", bound=DeviceData) + @dataclass class PlugwiseSelectDescriptionMixin: """Mixin values for Plugwise Select entities.""" command: Callable[[Smile, str, str], Awaitable[Any]] - value_fn: Callable[[DeviceData], str] - values_fn: Callable[[DeviceData], list[str]] + value_fn: Callable[[T], str] + values_fn: Callable[[T], list[str]] current_option_key: str options_key: str From 7c15808f83753261e580aaa849ec736e30955930 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Tue, 2 May 2023 18:00:26 +0200 Subject: [PATCH 26/52] Correctly name dhw to dhw_setpoint --- custom_components/plugwise/number.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 286596650..ec8c01dc9 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -73,10 +73,16 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["domestic_hot_water"]["upper_bound"], - native_min_value_fn=lambda data: data["domestic_hot_water"]["lower_bound"], - native_step_key_fn=lambda data: data["domestic_hot_water"]["resolution"], - native_value_fn=lambda data: data["domestic_hot_water"]["setpoint"], + native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"][ + "upper_bound" + ], + native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"][ + "lower_bound" + ], + native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"][ + "resolution" + ], + native_value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], native_unit_of_measurement=TEMP_CELSIUS, ), ) From e2c18818793be244400e5eb6bc93fed288e3b0fb Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Tue, 2 May 2023 19:47:17 +0200 Subject: [PATCH 27/52] Work on todos (breaking tests) --- custom_components/plugwise/models.py | 41 +++++++++++------------- custom_components/plugwise/number.py | 12 ++----- tests/components/plugwise/test_number.py | 37 +++++++++++---------- tests/components/plugwise/test_sensor.py | 7 ++-- 4 files changed, 42 insertions(+), 55 deletions(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index bfcf93190..4c661c2df 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -3,7 +3,6 @@ from collections.abc import Callable from dataclasses import dataclass -from typing import TypeVar from homeassistant.components.binary_sensor import BinarySensorEntityDescription from homeassistant.components.sensor import ( @@ -26,21 +25,19 @@ ) from plugwise import DeviceData -T = TypeVar("T", bound=DeviceData) - @dataclass class PlugwiseSensorBaseMixin: """Mixin for required Plugwise sensor base description keys.""" - value_fn: Callable[[T], float | int] + value_fn: Callable[[DeviceData], float | int] @dataclass class PlugwiseSwitchBaseMixin: """Mixin for required Plugwise switch base description keys.""" - value_fn: Callable[[T], bool] + value_fn: Callable[[DeviceData], bool] @dataclass @@ -435,24 +432,22 @@ class PlugwiseBinarySensorEntityDescription( native_unit_of_measurement=UnitOfTemperature.CELSIUS, value_fn=lambda data: data["sensors"]["dhw_temperature"], ), - # TODO FIX - # PlugwiseSensorEntityDescription( - # key="domestic_hot_water_setpoint", - # translation_key="domestic_hot_water_setpoint", - # device_class=SensorDeviceClass.TEMPERATURE, - # entity_category=EntityCategory.DIAGNOSTIC, - # native_unit_of_measurement=UnitOfTemperature.CELSIUS, - # value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], - # ), - # TODO FIX - # PlugwiseSensorEntityDescription( - # key="maximum_boiler_temperature", - # translation_key="maximum_boiler_temperature", - # device_class=SensorDeviceClass.TEMPERATURE, - # entity_category=EntityCategory.DIAGNOSTIC, - # native_unit_of_measurement=UnitOfTemperature.CELSIUS, - # value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], - # ), + PlugwiseSensorEntityDescription( + key="domestic_hot_water_setpoint", + translation_key="domestic_hot_water_setpoint", + device_class=SensorDeviceClass.TEMPERATURE, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], + ), + PlugwiseSensorEntityDescription( + key="maximum_boiler_temperature", + translation_key="maximum_boiler_temperature", + device_class=SensorDeviceClass.TEMPERATURE, + entity_category=EntityCategory.DIAGNOSTIC, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], + ), ) PW_SWITCH_TYPES: tuple[PlugwiseSwitchEntityDescription, ...] = ( diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index ec8c01dc9..e441258e1 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -73,15 +73,9 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"][ - "upper_bound" - ], - native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"][ - "lower_bound" - ], - native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"][ - "resolution" - ], + native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"]["upper_bound"], + native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"]["lower_bound"], + native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"]["resolution"], native_value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], native_unit_of_measurement=TEMP_CELSIUS, ), diff --git a/tests/components/plugwise/test_number.py b/tests/components/plugwise/test_number.py index 035f2e36f..e4e2f4f14 100644 --- a/tests/components/plugwise/test_number.py +++ b/tests/components/plugwise/test_number.py @@ -42,22 +42,21 @@ async def test_anna_max_boiler_temp_change( ) -# TODO: Broken, might be fixture failing -# async def test_adam_dhw_setpoint_change( -# hass: HomeAssistant, mock_smile_adam_2: MagicMock, init_integration: MockConfigEntry -# ) -> None: -# """Test changing of number entities.""" -# await hass.services.async_call( -# NUMBER_DOMAIN, -# SERVICE_SET_VALUE, -# { -# ATTR_ENTITY_ID: "number.opentherm_domestic_hot_water_setpoint", -# ATTR_VALUE: 55, -# }, -# blocking=True, -# ) -# -# assert mock_smile_adam_2.set_number_setpoint.call_count == 1 -# mock_smile_adam_2.set_number_setpoint.assert_called_with( -# "domestic_hot_water_setpoint", 55.0 -# ) +async def test_adam_dhw_setpoint_change( + hass: HomeAssistant, mock_smile_adam_2: MagicMock, init_integration: MockConfigEntry +) -> None: + """Test changing of number entities.""" + await hass.services.async_call( + NUMBER_DOMAIN, + SERVICE_SET_VALUE, + { + ATTR_ENTITY_ID: "number.opentherm_domestic_hot_water_setpoint", + ATTR_VALUE: 55, + }, + blocking=True, + ) + + assert mock_smile_adam_2.set_number_setpoint.call_count == 1 + mock_smile_adam_2.set_number_setpoint.assert_called_with( + "domestic_hot_water_setpoint", 55.0 + ) diff --git a/tests/components/plugwise/test_sensor.py b/tests/components/plugwise/test_sensor.py index 178813c3d..663c63bf3 100644 --- a/tests/components/plugwise/test_sensor.py +++ b/tests/components/plugwise/test_sensor.py @@ -49,10 +49,9 @@ async def test_anna_as_smt_climate_sensor_entities( assert state assert float(state.state) == 29.1 - # TODO - # state = hass.states.get("sensor.opentherm_dhw_setpoint") - # assert state - # assert float(state.state) == 60.0 + state = hass.states.get("sensor.opentherm_dhw_setpoint") + assert state + assert float(state.state) == 60.0 state = hass.states.get("sensor.opentherm_dhw_temperature") assert state From 917dcb96377c5640e9526514aeed2f93346bce36 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 17:47:51 +0000 Subject: [PATCH 28/52] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- custom_components/plugwise/number.py | 12 ++++++--- tests/components/plugwise/test_number.py | 32 ++++++++++++------------ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index e441258e1..ec8c01dc9 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -73,9 +73,15 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"]["upper_bound"], - native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"]["lower_bound"], - native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"]["resolution"], + native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"][ + "upper_bound" + ], + native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"][ + "lower_bound" + ], + native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"][ + "resolution" + ], native_value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], native_unit_of_measurement=TEMP_CELSIUS, ), diff --git a/tests/components/plugwise/test_number.py b/tests/components/plugwise/test_number.py index e4e2f4f14..f2a42bb1d 100644 --- a/tests/components/plugwise/test_number.py +++ b/tests/components/plugwise/test_number.py @@ -43,20 +43,20 @@ async def test_anna_max_boiler_temp_change( async def test_adam_dhw_setpoint_change( - hass: HomeAssistant, mock_smile_adam_2: MagicMock, init_integration: MockConfigEntry + hass: HomeAssistant, mock_smile_adam_2: MagicMock, init_integration: MockConfigEntry ) -> None: - """Test changing of number entities.""" - await hass.services.async_call( - NUMBER_DOMAIN, - SERVICE_SET_VALUE, - { - ATTR_ENTITY_ID: "number.opentherm_domestic_hot_water_setpoint", - ATTR_VALUE: 55, - }, - blocking=True, - ) - - assert mock_smile_adam_2.set_number_setpoint.call_count == 1 - mock_smile_adam_2.set_number_setpoint.assert_called_with( - "domestic_hot_water_setpoint", 55.0 - ) + """Test changing of number entities.""" + await hass.services.async_call( + NUMBER_DOMAIN, + SERVICE_SET_VALUE, + { + ATTR_ENTITY_ID: "number.opentherm_domestic_hot_water_setpoint", + ATTR_VALUE: 55, + }, + blocking=True, + ) + + assert mock_smile_adam_2.set_number_setpoint.call_count == 1 + mock_smile_adam_2.set_number_setpoint.assert_called_with( + "domestic_hot_water_setpoint", 55.0 + ) From e65e9472c1fbbef254b96ff64c6d8411757b5bf3 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 2 May 2023 20:08:20 +0200 Subject: [PATCH 29/52] Refix dhw_setpoint sensor --- custom_components/plugwise/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 4c661c2df..46d721689 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -438,7 +438,7 @@ class PlugwiseBinarySensorEntityDescription( device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], + value_fn=lambda data: data["sensor"]["domestic_hot_water_setpoint"], ), PlugwiseSensorEntityDescription( key="maximum_boiler_temperature", From 827c124f6edebe5d6b683418cf9e68fc52582fb3 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 2 May 2023 20:13:37 +0200 Subject: [PATCH 30/52] Fix typo --- custom_components/plugwise/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 46d721689..d3c93e918 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -438,7 +438,7 @@ class PlugwiseBinarySensorEntityDescription( device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["sensor"]["domestic_hot_water_setpoint"], + value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], ), PlugwiseSensorEntityDescription( key="maximum_boiler_temperature", From bd8dba4dfd7341c2e475359f6f80228ceface866 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Tue, 2 May 2023 20:18:00 +0200 Subject: [PATCH 31/52] Add dhw_setpoint actuator dict to m_adam_heating fixture --- .../plugwise/fixtures/m_adam_heating/all_data.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json index aceeeb506..1e4a666da 100644 --- a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json @@ -102,6 +102,12 @@ "location": "bc93488efab249e5bc54fd7e175a6f91", "model": "Generic heater", "name": "OpenTherm", + "domestic_hot_water_setpoint": { + "setpoint": 60.0, + "lower_bound": 25.0, + "upper_bound": 95.0, + "resolution": 0.01 + }, "maximum_boiler_temperature": { "setpoint": 60.0, "lower_bound": 25.0, From f06d8b26be58f7163e146c451d86586a5a435419 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 3 May 2023 14:21:42 +0200 Subject: [PATCH 32/52] Temp revert dhw for mypy; ignoring index --- custom_components/plugwise/models.py | 6 ++++-- custom_components/plugwise/number.py | 16 ++++++++-------- tests/components/plugwise/test_sensor.py | 7 ++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index d3c93e918..0813406cf 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -438,7 +438,9 @@ class PlugwiseBinarySensorEntityDescription( device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], + value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], # type: ignore [index] + # TODO + # value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], ), PlugwiseSensorEntityDescription( key="maximum_boiler_temperature", @@ -446,7 +448,7 @@ class PlugwiseBinarySensorEntityDescription( device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], + value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], # type: ignore [index] ), ) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index ec8c01dc9..40d626b2c 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -57,14 +57,14 @@ class PlugwiseNumberEntityDescription( entity_category=EntityCategory.CONFIG, native_max_value_fn=lambda data: data["maximum_boiler_temperature"][ "upper_bound" - ], + ], # type: ignore [index] native_min_value_fn=lambda data: data["maximum_boiler_temperature"][ "lower_bound" - ], + ], # type: ignore [index] native_step_key_fn=lambda data: data["maximum_boiler_temperature"][ "resolution" - ], - native_value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], + ], # type: ignore [index] + native_value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), PlugwiseNumberEntityDescription( @@ -75,14 +75,14 @@ class PlugwiseNumberEntityDescription( entity_category=EntityCategory.CONFIG, native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"][ "upper_bound" - ], + ], # type: ignore [index] native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"][ "lower_bound" - ], + ], # type: ignore [index] native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"][ "resolution" - ], - native_value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], + ], # type: ignore [index] + native_value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), ) diff --git a/tests/components/plugwise/test_sensor.py b/tests/components/plugwise/test_sensor.py index 663c63bf3..0b26fa493 100644 --- a/tests/components/plugwise/test_sensor.py +++ b/tests/components/plugwise/test_sensor.py @@ -49,9 +49,10 @@ async def test_anna_as_smt_climate_sensor_entities( assert state assert float(state.state) == 29.1 - state = hass.states.get("sensor.opentherm_dhw_setpoint") - assert state - assert float(state.state) == 60.0 + # TODO + # state = hass.states.get("sensor.opentherm_dhw_setpoint") + # assert state + # assert float(state.state) == 60.0 state = hass.states.get("sensor.opentherm_dhw_temperature") assert state From 940a380feb2000f22da793efb488abc1f035b1f9 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 3 May 2023 21:53:56 +0200 Subject: [PATCH 33/52] Fugly fix (but working) with 31.3 --- custom_components/plugwise/manifest.json | 4 +- custom_components/plugwise/models.py | 4 +- custom_components/plugwise/number.py | 70 ++++++------------------ tests/components/plugwise/test_sensor.py | 7 +-- 4 files changed, 24 insertions(+), 61 deletions(-) diff --git a/custom_components/plugwise/manifest.json b/custom_components/plugwise/manifest.json index 567bc34ba..c5d2b826a 100644 --- a/custom_components/plugwise/manifest.json +++ b/custom_components/plugwise/manifest.json @@ -8,6 +8,6 @@ "integration_type": "hub", "iot_class": "local_polling", "loggers": ["plugwise"], - "requirements": ["plugwise==0.31.2"], - "version": "0.40.2a0" + "requirements": ["plugwise==0.31.3"], + "version": "0.40.2a2" } diff --git a/custom_components/plugwise/models.py b/custom_components/plugwise/models.py index 0813406cf..39c3d3688 100644 --- a/custom_components/plugwise/models.py +++ b/custom_components/plugwise/models.py @@ -438,9 +438,7 @@ class PlugwiseBinarySensorEntityDescription( device_class=SensorDeviceClass.TEMPERATURE, entity_category=EntityCategory.DIAGNOSTIC, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], # type: ignore [index] - # TODO - # value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], + value_fn=lambda data: data["sensors"]["domestic_hot_water_setpoint"], ), PlugwiseSensorEntityDescription( key="maximum_boiler_temperature", diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 40d626b2c..38eba6779 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -26,27 +26,20 @@ @dataclass -class PlugwiseEntityDescriptionMixin: +class PlugwiseNumberMixin: """Mixin values for Plugwse entities.""" command: Callable[[Smile, str, float], Awaitable[None]] - native_max_value_fn: Callable[[T], float] - native_min_value_fn: Callable[[T], float] - native_step_key_fn: Callable[[T], float] - native_value_fn: Callable[[T], float] + max_value_fn: Callable[[T], float] + min_value_fn: Callable[[T], float] + step_key_fn: Callable[[T], float] + value_fn: Callable[[T], float] @dataclass -class PlugwiseNumberEntityDescription( - NumberEntityDescription, PlugwiseEntityDescriptionMixin -): +class PlugwiseNumberEntityDescription(NumberEntityDescription, PlugwiseNumberMixin): """Class describing Plugwise Number entities.""" - native_max_value_key: str | None = None - native_min_value_key: str | None = None - native_step_key: str | None = None - native_value_key: str | None = None - NUMBER_TYPES = ( PlugwiseNumberEntityDescription( @@ -55,16 +48,10 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["maximum_boiler_temperature"][ - "upper_bound" - ], # type: ignore [index] - native_min_value_fn=lambda data: data["maximum_boiler_temperature"][ - "lower_bound" - ], # type: ignore [index] - native_step_key_fn=lambda data: data["maximum_boiler_temperature"][ - "resolution" - ], # type: ignore [index] - native_value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], # type: ignore [index] + max_value_fn=lambda data: data["maximum_boiler_temperature"]["upper_bound"] or 0.0, # type: ignore [index] + min_value_fn=lambda data: data["maximum_boiler_temperature"]["lower_bound"] or 0.0, # type: ignore [index] + step_key_fn=lambda data: data["maximum_boiler_temperature"]["resolution"] or 0.0, # type: ignore [index] + value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"] or 0.0, # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), PlugwiseNumberEntityDescription( @@ -73,16 +60,10 @@ class PlugwiseNumberEntityDescription( command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"][ - "upper_bound" - ], # type: ignore [index] - native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"][ - "lower_bound" - ], # type: ignore [index] - native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"][ - "resolution" - ], # type: ignore [index] - native_value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"], # type: ignore [index] + max_value_fn=lambda data: data["domestic_hot_water_setpoint"]["upper_bound"] or 0.0, # type: ignore [index] + min_value_fn=lambda data: data["domestic_hot_water_setpoint"]["lower_bound"] or 0.0, # type: ignore [index] + step_key_fn=lambda data: data["domestic_hot_water_setpoint"]["resolution"] or 0.0, # type: ignore [index] + value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"] or 0.0, # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), ) @@ -131,37 +112,22 @@ def __init__( @property def native_step(self) -> float: """Return the setpoint step value.""" - # return max( - # self.device[self.entity_description.key][ # type: ignore [literal-required] - # self.entity_description.native_step_key - # ], - # 1, - # ) - return self.entity_description.native_step_key_fn(self.device) + return self.entity_description.step_key_fn(self.device) @property def native_value(self) -> float: """Return the present setpoint value.""" - # return self.device[self.entity_description.key][ # type: ignore [literal-required] - # self.entity_description.native_value_key - # ] - return self.entity_description.native_value_fn(self.device) + return self.entity_description.value_fn(self.device) @property def native_min_value(self) -> float: """Return the setpoint min. value.""" - # return self.device[self.entity_description.key][ # type: ignore [literal-required] - # self.entity_description.native_min_value_key - # ] - return self.entity_description.native_min_value_fn(self.device) + return self.entity_description.min_value_fn(self.device) @property def native_max_value(self) -> float: """Return the setpoint max. value.""" - # return self.device[self.entity_description.key][ # type: ignore [literal-required] - # self.entity_description.native_max_value_key - # ] - return self.entity_description.native_max_value_fn(self.device) + return self.entity_description.max_value_fn(self.device) async def async_set_native_value(self, value: float) -> None: """Change to the new setpoint value.""" diff --git a/tests/components/plugwise/test_sensor.py b/tests/components/plugwise/test_sensor.py index 0b26fa493..663c63bf3 100644 --- a/tests/components/plugwise/test_sensor.py +++ b/tests/components/plugwise/test_sensor.py @@ -49,10 +49,9 @@ async def test_anna_as_smt_climate_sensor_entities( assert state assert float(state.state) == 29.1 - # TODO - # state = hass.states.get("sensor.opentherm_dhw_setpoint") - # assert state - # assert float(state.state) == 60.0 + state = hass.states.get("sensor.opentherm_dhw_setpoint") + assert state + assert float(state.state) == 60.0 state = hass.states.get("sensor.opentherm_dhw_temperature") assert state From 119aa7c28a87046920a34b7e1bbd6a65eda2fd4e Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 3 May 2023 21:59:54 +0200 Subject: [PATCH 34/52] Try single core-testing --- .github/workflows/test.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e0c92ad8e..a1490ff6d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,18 +44,21 @@ jobs: ${{ env.CACHE_VERSION}}-${{ runner.os }}-base-hacore ${{ env.CACHE_VERSION}}-${{ runner.os }} ${{ env.CACHE_VERSION}} - - name: Create HA-core Python virtual environment + - name: Test through core (full, not split) run: | - scripts/core-testing.sh core_prep - - name: Prepare HA-core Python virtual environment - run: | - scripts/core-testing.sh pip_prep - - name: Test - run: | - scripts/core-testing.sh testing - - name: Quality - run: | - scripts/core-testing.sh quality + GITHUB_ACTIONS="" scripts/core-testing.sh + # - name: Create HA-core Python virtual environment + # run: | + # scripts/core-testing.sh core_prep + # - name: Prepare HA-core Python virtual environment + # run: | + # scripts/core-testing.sh pip_prep + # - name: Test + # run: | + # scripts/core-testing.sh testing + # - name: Quality + # run: | + # scripts/core-testing.sh quality shellcheck: name: Shellcheck From 4ff80e74f946d4254d08fbbccb676dbef7218b4e Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 3 May 2023 22:06:34 +0200 Subject: [PATCH 35/52] Try single core-testing without hassfest --- scripts/core-testing.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/core-testing.sh b/scripts/core-testing.sh index be00271bd..90ac062fc 100755 --- a/scripts/core-testing.sh +++ b/scripts/core-testing.sh @@ -250,8 +250,12 @@ if [ -z "${GITHUB_ACTIONS}" ]; then # shellcheck disable=SC2090 sed -i".sedbck" 's/http.*test-files.pythonhosted.*#//g' ./homeassistant/components/plugwise/manifest.json ) - echo "Running hassfest for plugwise" - python3 -m script.hassfest --requirements --action validate + + # Hassfest already runs on Github + if [ -z "${GITHUB_ACTIONS}" ] ; then + echo "Running hassfest for plugwise" + python3 -m script.hassfest --requirements --action validate + fi fi # pylint was removed from 'quality' some time ago From 2f97660b9372eaf20bc22f97bb785596a47c85ac Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 3 May 2023 22:12:21 +0200 Subject: [PATCH 36/52] Try single core-testing without hassfest --- scripts/core-testing.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/core-testing.sh b/scripts/core-testing.sh index 90ac062fc..f9be3543c 100755 --- a/scripts/core-testing.sh +++ b/scripts/core-testing.sh @@ -252,7 +252,7 @@ if [ -z "${GITHUB_ACTIONS}" ]; then ) # Hassfest already runs on Github - if [ -z "${GITHUB_ACTIONS}" ] ; then + if [ ! -z "${GITHUB_ACTIONS}" ] ; then echo "Running hassfest for plugwise" python3 -m script.hassfest --requirements --action validate fi From 49b6df489d2a3b763277269decc2ab693b09bca8 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 3 May 2023 22:18:15 +0200 Subject: [PATCH 37/52] Try single core-testing without hassfest --- scripts/core-testing.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/core-testing.sh b/scripts/core-testing.sh index f9be3543c..3a4d28221 100755 --- a/scripts/core-testing.sh +++ b/scripts/core-testing.sh @@ -252,7 +252,7 @@ if [ -z "${GITHUB_ACTIONS}" ]; then ) # Hassfest already runs on Github - if [ ! -z "${GITHUB_ACTIONS}" ] ; then + if [ -n "${GITHUB_ACTIONS}" ] ; then echo "Running hassfest for plugwise" python3 -m script.hassfest --requirements --action validate fi From fd2dd56ea325f26e15c466d2268171f83384241a Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Wed, 3 May 2023 23:30:21 +0200 Subject: [PATCH 38/52] Fixture generator issue (true core pr diffing) --- .../plugwise/fixtures/m_adam_heating/all_data.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json index 1e4a666da..d1726b687 100644 --- a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json @@ -102,12 +102,6 @@ "location": "bc93488efab249e5bc54fd7e175a6f91", "model": "Generic heater", "name": "OpenTherm", - "domestic_hot_water_setpoint": { - "setpoint": 60.0, - "lower_bound": 25.0, - "upper_bound": 95.0, - "resolution": 0.01 - }, "maximum_boiler_temperature": { "setpoint": 60.0, "lower_bound": 25.0, @@ -126,6 +120,12 @@ }, "switches": { "dhw_cm_switch": false + }, + "domestic_hot_water_setpoint": { + "setpoint": 60.0, + "lower_bound": 40.0, + "upper_bound": 60.0, + "resolution": 0.01 } }, "e8ef2a01ed3b4139a53bf749204fe6b4": { From 2a5d56c7ba3a9d91082501a4a58aad854af71008 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Fri, 5 May 2023 00:16:30 +0200 Subject: [PATCH 39/52] Sorted fixtures except m_adam_heating --- .pre-commit-config.yaml | 1 + .../all_data.json | 630 +++++++++--------- .../notifications.json | 2 +- .../anna_heatpump_heating/all_data.json | 124 ++-- .../anna_heatpump_heating/notifications.json | 2 +- .../fixtures/m_adam_cooling/all_data.json | 204 +++--- .../m_adam_cooling/notifications.json | 2 +- .../m_anna_heatpump_cooling/all_data.json | 124 ++-- .../notifications.json | 2 +- .../m_anna_heatpump_idle/all_data.json | 124 ++-- .../m_anna_heatpump_idle/notifications.json | 2 +- .../fixtures/p1v3_full_option/all_data.json | 44 +- .../p1v3_full_option/notifications.json | 2 +- .../fixtures/p1v4_442_triple/all_data.json | 58 +- .../p1v4_442_triple/notifications.json | 2 +- .../fixtures/stretch_v31/all_data.json | 144 ++-- .../fixtures/stretch_v31/notifications.json | 2 +- 17 files changed, 773 insertions(+), 696 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a913169fc..0b566858c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,6 +70,7 @@ repos: hooks: - id: prettier name: "Verifying/updating code with prettier" + exclude_types: [csv, json] - repo: https://github.com/cdce8p/python-typing-update rev: v0.5.1 hooks: diff --git a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json index 2d59f7797..8eb362b1e 100644 --- a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json +++ b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json @@ -1,103 +1,106 @@ { - "gateway": { - "smile_name": "Adam", - "gateway_id": "fe799307f1624099878210aa0b9f1475", - "heater_id": "90986d591dcd426cae3ec3e8111ff730", - "cooling_present": false, - "notifications": { - "af82e4ccf9c548528166d38e560662a4": { - "warning": "Node Plug (with MAC address 000D6F000D13CB01, in room 'n.a.') has been unreachable since 23:03 2020-01-18. Please check the connection and restart the device." - } - } - }, "devices": { - "df4a4a8169904cdb9c03d61a21f42140": { - "dev_class": "zone_thermostat", - "firmware": "2016-10-27T02:00:00+02:00", - "hardware": "255", - "location": "12493538af164a409c6a1c79e38afe1c", - "model": "Lisa", - "name": "Zone Lisa Bios", - "zigbee_mac_address": "ABCD012345670A06", - "vendor": "Plugwise", - "thermostat": { - "setpoint": 13.0, - "lower_bound": 0.0, - "upper_bound": 99.9, - "resolution": 0.01 + "02cf28bfec924855854c544690a609ef": { + "available": true, + "dev_class": "vcr", + "firmware": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "NVR", + "sensors": { + "electricity_consumed": 34.0, + "electricity_consumed_interval": 9.15, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0 + }, + "switches": { + "lock": true, + "relay": true }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A15" + }, + "21f2b542c49845e6bb416884c55778d6": { "available": true, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "away", - "available_schedules": [ - "CV Roan", - "Bios Schema met Film Avond", - "GF7 Woonkamer", - "Badkamer Schema", - "CV Jessie" - ], - "selected_schedule": "None", - "last_used": "Badkamer Schema", - "mode": "heat", + "dev_class": "game_console", + "firmware": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "Playstation Smart Plug", "sensors": { - "temperature": 16.5, - "setpoint": 13.0, - "battery": 67 - } + "electricity_consumed": 82.6, + "electricity_consumed_interval": 8.6, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0 + }, + "switches": { + "lock": false, + "relay": true + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A12" }, - "b310b72a0e354bfab43089919b9a88bf": { - "dev_class": "thermo_sensor", - "firmware": "2019-03-27T01:00:00+01:00", - "hardware": "1", - "location": "c50f167537524366a5af7aa3942feb1e", - "model": "Tom/Floor", - "name": "Floor kraan", - "zigbee_mac_address": "ABCD012345670A02", + "4a810418d5394b3f82727340b91ba740": { + "available": true, + "dev_class": "router", + "firmware": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "USG Smart Plug", + "sensors": { + "electricity_consumed": 8.5, + "electricity_consumed_interval": 0.0, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0 + }, + "switches": { + "lock": true, + "relay": true + }, "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A16" + }, + "675416a629f343c495449970e2ca37b5": { "available": true, + "dev_class": "router", + "firmware": "2019-06-21T02:00:00+02:00", + "location": "cd143c07248f491493cea0533bc3d669", + "model": "Plug", + "name": "Ziggo Modem", "sensors": { - "temperature": 26.0, - "setpoint": 21.5, - "temperature_difference": 3.5, - "valve_position": 100 - } + "electricity_consumed": 12.2, + "electricity_consumed_interval": 2.97, + "electricity_produced": 0.0, + "electricity_produced_interval": 0.0 + }, + "switches": { + "lock": true, + "relay": true + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A01" }, - "a2c3583e0a6349358998b760cea82d2a": { + "680423ff840043738f42cc7f1ff97a36": { + "available": true, "dev_class": "thermo_sensor", "firmware": "2019-03-27T01:00:00+01:00", "hardware": "1", - "location": "12493538af164a409c6a1c79e38afe1c", + "location": "08963fec7c53423ca5680aa4cb502c63", "model": "Tom/Floor", - "name": "Bios Cv Thermostatic Radiator ", - "zigbee_mac_address": "ABCD012345670A09", - "vendor": "Plugwise", - "available": true, + "name": "Thermostatic Radiator Badkamer", "sensors": { - "temperature": 17.2, - "setpoint": 13.0, - "battery": 62, - "temperature_difference": -0.2, + "battery": 51, + "setpoint": 14.0, + "temperature": 19.1, + "temperature_difference": -0.4, "valve_position": 0.0 - } - }, - "b59bcebaf94b499ea7d46e4a66fb62d8": { - "dev_class": "zone_thermostat", - "firmware": "2016-08-02T02:00:00+02:00", - "hardware": "255", - "location": "c50f167537524366a5af7aa3942feb1e", - "model": "Lisa", - "name": "Zone Lisa WK", - "zigbee_mac_address": "ABCD012345670A07", - "vendor": "Plugwise", - "thermostat": { - "setpoint": 21.5, - "lower_bound": 0.0, - "upper_bound": 99.9, - "resolution": 0.01 }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A17" + }, + "6a3bf693d05e48e0b460c815a4fdd09d": { + "active_preset": "asleep", "available": true, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "home", "available_schedules": [ "CV Roan", "Bios Schema met Film Avond", @@ -105,80 +108,43 @@ "Badkamer Schema", "CV Jessie" ], - "selected_schedule": "GF7 Woonkamer", - "last_used": "GF7 Woonkamer", + "dev_class": "zone_thermostat", + "firmware": "2016-10-27T02:00:00+02:00", + "hardware": "255", + "last_used": "CV Jessie", + "location": "82fa13f017d240daa0d0ea1775420f24", "mode": "auto", + "model": "Lisa", + "name": "Zone Thermostat Jessie", + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "CV Jessie", "sensors": { - "temperature": 20.9, - "setpoint": 21.5, - "battery": 34 - } - }, - "fe799307f1624099878210aa0b9f1475": { - "dev_class": "gateway", - "firmware": "3.0.15", - "hardware": "AME Smile 2.0 board", - "location": "1f9dcf83fd4e4b66b72ff787957bfe5d", - "mac_address": "012345670001", - "model": "Gateway", - "name": "Adam", - "zigbee_mac_address": "ABCD012345670101", - "vendor": "Plugwise", - "regulation_mode": "heating", - "binary_sensors": { - "plugwise_notification": true + "battery": 37, + "setpoint": 15.0, + "temperature": 17.2 }, - "sensors": { - "outdoor_temperature": 7.81 - } - }, - "d3da73bde12a47d5a6b8f9dad971f2ec": { - "dev_class": "thermo_sensor", - "firmware": "2019-03-27T01:00:00+01:00", - "hardware": "1", - "location": "82fa13f017d240daa0d0ea1775420f24", - "model": "Tom/Floor", - "name": "Thermostatic Radiator Jessie", - "zigbee_mac_address": "ABCD012345670A10", - "vendor": "Plugwise", - "available": true, - "sensors": { - "temperature": 17.1, + "thermostat": { + "lower_bound": 0.0, + "resolution": 0.01, "setpoint": 15.0, - "battery": 62, - "temperature_difference": 0.1, - "valve_position": 0.0 - } - }, - "21f2b542c49845e6bb416884c55778d6": { - "dev_class": "game_console", - "firmware": "2019-06-21T02:00:00+02:00", - "location": "cd143c07248f491493cea0533bc3d669", - "model": "Plug", - "name": "Playstation Smart Plug", - "zigbee_mac_address": "ABCD012345670A12", - "vendor": "Plugwise", - "available": true, - "sensors": { - "electricity_consumed": 82.6, - "electricity_consumed_interval": 8.6, - "electricity_produced": 0.0, - "electricity_produced_interval": 0.0 + "upper_bound": 99.9 }, - "switches": { - "relay": true, - "lock": false - } + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A03" }, "78d1126fc4c743db81b61c20e88342a7": { + "available": true, "dev_class": "central_heating_pump", "firmware": "2019-06-21T02:00:00+02:00", "location": "c50f167537524366a5af7aa3942feb1e", "model": "Plug", "name": "CV Pomp", - "zigbee_mac_address": "ABCD012345670A05", - "vendor": "Plugwise", - "available": true, "sensors": { "electricity_consumed": 35.6, "electricity_consumed_interval": 7.37, @@ -187,120 +153,160 @@ }, "switches": { "relay": true - } + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A05" }, "90986d591dcd426cae3ec3e8111ff730": { + "binary_sensors": { + "heating_state": true + }, "dev_class": "heater_central", "location": "1f9dcf83fd4e4b66b72ff787957bfe5d", "model": "Unknown", "name": "OnOff", - "binary_sensors": { - "heating_state": true - }, "sensors": { - "water_temperature": 70.0, "intended_boiler_temperature": 70.0, - "modulation_level": 1 + "modulation_level": 1, + "water_temperature": 70.0 } }, - "cd0ddb54ef694e11ac18ed1cbce5dbbd": { - "dev_class": "vcr", + "a28f588dc4a049a483fd03a30361ad3a": { + "available": true, + "dev_class": "settop", "firmware": "2019-06-21T02:00:00+02:00", "location": "cd143c07248f491493cea0533bc3d669", "model": "Plug", - "name": "NAS", - "zigbee_mac_address": "ABCD012345670A14", - "vendor": "Plugwise", - "available": true, + "name": "Fibaro HC2", "sensors": { - "electricity_consumed": 16.5, - "electricity_consumed_interval": 0.5, + "electricity_consumed": 12.5, + "electricity_consumed_interval": 3.8, "electricity_produced": 0.0, "electricity_produced_interval": 0.0 }, "switches": { - "relay": true, - "lock": true - } - }, - "4a810418d5394b3f82727340b91ba740": { - "dev_class": "router", - "firmware": "2019-06-21T02:00:00+02:00", - "location": "cd143c07248f491493cea0533bc3d669", - "model": "Plug", - "name": "USG Smart Plug", - "zigbee_mac_address": "ABCD012345670A16", + "lock": true, + "relay": true + }, "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A13" + }, + "a2c3583e0a6349358998b760cea82d2a": { "available": true, + "dev_class": "thermo_sensor", + "firmware": "2019-03-27T01:00:00+01:00", + "hardware": "1", + "location": "12493538af164a409c6a1c79e38afe1c", + "model": "Tom/Floor", + "name": "Bios Cv Thermostatic Radiator ", "sensors": { - "electricity_consumed": 8.5, - "electricity_consumed_interval": 0.0, - "electricity_produced": 0.0, - "electricity_produced_interval": 0.0 + "battery": 62, + "setpoint": 13.0, + "temperature": 17.2, + "temperature_difference": -0.2, + "valve_position": 0.0 }, - "switches": { - "relay": true, - "lock": true - } + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A09" }, - "02cf28bfec924855854c544690a609ef": { - "dev_class": "vcr", - "firmware": "2019-06-21T02:00:00+02:00", - "location": "cd143c07248f491493cea0533bc3d669", - "model": "Plug", - "name": "NVR", - "zigbee_mac_address": "ABCD012345670A15", + "b310b72a0e354bfab43089919b9a88bf": { + "available": true, + "dev_class": "thermo_sensor", + "firmware": "2019-03-27T01:00:00+01:00", + "hardware": "1", + "location": "c50f167537524366a5af7aa3942feb1e", + "model": "Tom/Floor", + "name": "Floor kraan", + "sensors": { + "setpoint": 21.5, + "temperature": 26.0, + "temperature_difference": 3.5, + "valve_position": 100 + }, "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A02" + }, + "b59bcebaf94b499ea7d46e4a66fb62d8": { + "active_preset": "home", "available": true, + "available_schedules": [ + "CV Roan", + "Bios Schema met Film Avond", + "GF7 Woonkamer", + "Badkamer Schema", + "CV Jessie" + ], + "dev_class": "zone_thermostat", + "firmware": "2016-08-02T02:00:00+02:00", + "hardware": "255", + "last_used": "GF7 Woonkamer", + "location": "c50f167537524366a5af7aa3942feb1e", + "mode": "auto", + "model": "Lisa", + "name": "Zone Lisa WK", + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "GF7 Woonkamer", "sensors": { - "electricity_consumed": 34.0, - "electricity_consumed_interval": 9.15, - "electricity_produced": 0.0, - "electricity_produced_interval": 0.0 + "battery": 34, + "setpoint": 21.5, + "temperature": 20.9 }, - "switches": { - "relay": true, - "lock": true - } + "thermostat": { + "lower_bound": 0.0, + "resolution": 0.01, + "setpoint": 21.5, + "upper_bound": 99.9 + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A07" }, - "a28f588dc4a049a483fd03a30361ad3a": { - "dev_class": "settop", + "cd0ddb54ef694e11ac18ed1cbce5dbbd": { + "available": true, + "dev_class": "vcr", "firmware": "2019-06-21T02:00:00+02:00", "location": "cd143c07248f491493cea0533bc3d669", "model": "Plug", - "name": "Fibaro HC2", - "zigbee_mac_address": "ABCD012345670A13", - "vendor": "Plugwise", - "available": true, + "name": "NAS", "sensors": { - "electricity_consumed": 12.5, - "electricity_consumed_interval": 3.8, + "electricity_consumed": 16.5, + "electricity_consumed_interval": 0.5, "electricity_produced": 0.0, "electricity_produced_interval": 0.0 }, "switches": { - "relay": true, - "lock": true - } + "lock": true, + "relay": true + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A14" }, - "6a3bf693d05e48e0b460c815a4fdd09d": { - "dev_class": "zone_thermostat", - "firmware": "2016-10-27T02:00:00+02:00", - "hardware": "255", + "d3da73bde12a47d5a6b8f9dad971f2ec": { + "available": true, + "dev_class": "thermo_sensor", + "firmware": "2019-03-27T01:00:00+01:00", + "hardware": "1", "location": "82fa13f017d240daa0d0ea1775420f24", - "model": "Lisa", - "name": "Zone Thermostat Jessie", - "zigbee_mac_address": "ABCD012345670A03", - "vendor": "Plugwise", - "thermostat": { + "model": "Tom/Floor", + "name": "Thermostatic Radiator Jessie", + "sensors": { + "battery": 62, "setpoint": 15.0, - "lower_bound": 0.0, - "upper_bound": 99.9, - "resolution": 0.01 + "temperature": 17.1, + "temperature_difference": 0.1, + "valve_position": 0.0 }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A10" + }, + "df4a4a8169904cdb9c03d61a21f42140": { + "active_preset": "away", "available": true, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "asleep", "available_schedules": [ "CV Roan", "Bios Schema met Film Avond", @@ -308,51 +314,39 @@ "Badkamer Schema", "CV Jessie" ], - "selected_schedule": "CV Jessie", - "last_used": "CV Jessie", - "mode": "auto", - "sensors": { - "temperature": 17.2, - "setpoint": 15.0, - "battery": 37 - } - }, - "680423ff840043738f42cc7f1ff97a36": { - "dev_class": "thermo_sensor", - "firmware": "2019-03-27T01:00:00+01:00", - "hardware": "1", - "location": "08963fec7c53423ca5680aa4cb502c63", - "model": "Tom/Floor", - "name": "Thermostatic Radiator Badkamer", - "zigbee_mac_address": "ABCD012345670A17", - "vendor": "Plugwise", - "available": true, - "sensors": { - "temperature": 19.1, - "setpoint": 14.0, - "battery": 51, - "temperature_difference": -0.4, - "valve_position": 0.0 - } - }, - "f1fee6043d3642a9b0a65297455f008e": { "dev_class": "zone_thermostat", "firmware": "2016-10-27T02:00:00+02:00", "hardware": "255", - "location": "08963fec7c53423ca5680aa4cb502c63", + "last_used": "Badkamer Schema", + "location": "12493538af164a409c6a1c79e38afe1c", + "mode": "heat", "model": "Lisa", - "name": "Zone Thermostat Badkamer", - "zigbee_mac_address": "ABCD012345670A08", - "vendor": "Plugwise", + "name": "Zone Lisa Bios", + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "None", + "sensors": { + "battery": 67, + "setpoint": 13.0, + "temperature": 16.5 + }, "thermostat": { - "setpoint": 14.0, "lower_bound": 0.0, - "upper_bound": 99.9, - "resolution": 0.01 + "resolution": 0.01, + "setpoint": 13.0, + "upper_bound": 99.9 }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A06" + }, + "e7693eb9582644e5b865dba8d4447cf1": { + "active_preset": "no_frost", "available": true, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "away", "available_schedules": [ "CV Roan", "Bios Schema met Film Avond", @@ -360,53 +354,41 @@ "Badkamer Schema", "CV Jessie" ], - "selected_schedule": "Badkamer Schema", - "last_used": "Badkamer Schema", - "mode": "auto", - "sensors": { - "temperature": 18.9, - "setpoint": 14.0, - "battery": 92 - } - }, - "675416a629f343c495449970e2ca37b5": { - "dev_class": "router", - "firmware": "2019-06-21T02:00:00+02:00", - "location": "cd143c07248f491493cea0533bc3d669", - "model": "Plug", - "name": "Ziggo Modem", - "zigbee_mac_address": "ABCD012345670A01", - "vendor": "Plugwise", - "available": true, - "sensors": { - "electricity_consumed": 12.2, - "electricity_consumed_interval": 2.97, - "electricity_produced": 0.0, - "electricity_produced_interval": 0.0 - }, - "switches": { - "relay": true, - "lock": true - } - }, - "e7693eb9582644e5b865dba8d4447cf1": { "dev_class": "thermostatic_radiator_valve", "firmware": "2019-03-27T01:00:00+01:00", "hardware": "1", + "last_used": "Badkamer Schema", "location": "446ac08dd04d4eff8ac57489757b7314", + "mode": "heat", "model": "Tom/Floor", "name": "CV Kraan Garage", - "zigbee_mac_address": "ABCD012345670A11", - "vendor": "Plugwise", - "thermostat": { + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "None", + "sensors": { + "battery": 68, "setpoint": 5.5, + "temperature": 15.6, + "temperature_difference": 0.0, + "valve_position": 0.0 + }, + "thermostat": { "lower_bound": 0.0, - "upper_bound": 100.0, - "resolution": 0.01 + "resolution": 0.01, + "setpoint": 5.5, + "upper_bound": 100.0 }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A11" + }, + "f1fee6043d3642a9b0a65297455f008e": { + "active_preset": "away", "available": true, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "no_frost", "available_schedules": [ "CV Roan", "Bios Schema met Film Avond", @@ -414,16 +396,64 @@ "Badkamer Schema", "CV Jessie" ], - "selected_schedule": "None", + "dev_class": "zone_thermostat", + "firmware": "2016-10-27T02:00:00+02:00", + "hardware": "255", "last_used": "Badkamer Schema", - "mode": "heat", + "location": "08963fec7c53423ca5680aa4cb502c63", + "mode": "auto", + "model": "Lisa", + "name": "Zone Thermostat Badkamer", + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "Badkamer Schema", "sensors": { - "temperature": 15.6, - "setpoint": 5.5, - "battery": 68, - "temperature_difference": 0.0, - "valve_position": 0.0 - } + "battery": 92, + "setpoint": 14.0, + "temperature": 18.9 + }, + "thermostat": { + "lower_bound": 0.0, + "resolution": 0.01, + "setpoint": 14.0, + "upper_bound": 99.9 + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A08" + }, + "fe799307f1624099878210aa0b9f1475": { + "binary_sensors": { + "plugwise_notification": true + }, + "dev_class": "gateway", + "firmware": "3.0.15", + "hardware": "AME Smile 2.0 board", + "location": "1f9dcf83fd4e4b66b72ff787957bfe5d", + "mac_address": "012345670001", + "model": "Gateway", + "name": "Adam", + "regulation_mode": "heating", + "sensors": { + "outdoor_temperature": 7.81 + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670101" } + }, + "gateway": { + "cooling_present": false, + "gateway_id": "fe799307f1624099878210aa0b9f1475", + "heater_id": "90986d591dcd426cae3ec3e8111ff730", + "notifications": { + "af82e4ccf9c548528166d38e560662a4": { + "warning": "Node Plug (with MAC address 000D6F000D13CB01, in room 'n.a.') has been unreachable since 23:03 2020-01-18. Please check the connection and restart the device." + } + }, + "smile_name": "Adam" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/notifications.json b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/notifications.json index 8749be4c3..f94bce4ef 100644 --- a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/notifications.json +++ b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/notifications.json @@ -2,4 +2,4 @@ "af82e4ccf9c548528166d38e560662a4": { "warning": "Node Plug (with MAC address 000D6F000D13CB01, in room 'n.a.') has been unreachable since 23:03 2020-01-18. Please check the connection and restart the device." } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json b/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json index 50e8bd13e..b94971cd1 100644 --- a/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json +++ b/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json @@ -1,90 +1,98 @@ { - "gateway": { - "smile_name": "Smile Anna", - "gateway_id": "015ae9ea3f964e668e490fa39da3870b", - "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", - "cooling_present": false, - "notifications": {} - }, "devices": { - "1cbf783bb11e4a7c8a6843dee3a86927": { - "dev_class": "heater_central", + "015ae9ea3f964e668e490fa39da3870b": { + "binary_sensors": { + "plugwise_notification": false + }, + "dev_class": "gateway", + "firmware": "4.0.15", + "hardware": "AME Smile 2.0 board", "location": "a57efe5f145f498c9be62a9b63626fbf", - "model": "Generic heater", - "name": "OpenTherm", - "vendor": "Techneco", - "maximum_boiler_temperature": { - "setpoint": 60.0, - "lower_bound": 0.0, - "upper_bound": 100.0, - "resolution": 1.0 + "mac_address": "012345670001", + "model": "Gateway", + "name": "Smile Anna", + "sensors": { + "outdoor_temperature": 20.2 }, + "vendor": "Plugwise" + }, + "1cbf783bb11e4a7c8a6843dee3a86927": { "available": true, "binary_sensors": { - "dhw_state": false, - "heating_state": true, "compressor_state": true, "cooling_enabled": false, - "slave_boiler_state": false, - "flame_state": false + "dhw_state": false, + "flame_state": false, + "heating_state": true, + "slave_boiler_state": false }, + "dev_class": "heater_central", + "location": "a57efe5f145f498c9be62a9b63626fbf", + "maximum_boiler_temperature": { + "lower_bound": 0.0, + "resolution": 1.0, + "setpoint": 60.0, + "upper_bound": 100.0 + }, + "model": "Generic heater", + "name": "OpenTherm", "sensors": { - "water_temperature": 29.1, - "domestic_hot_water_setpoint": 60.0, "dhw_temperature": 46.3, + "domestic_hot_water_setpoint": 60.0, "intended_boiler_temperature": 35.0, "modulation_level": 52, + "outdoor_air_temperature": 3.0, "return_temperature": 25.1, "water_pressure": 1.57, - "outdoor_air_temperature": 3.0 + "water_temperature": 29.1 }, "switches": { "dhw_cm_switch": false - } - }, - "015ae9ea3f964e668e490fa39da3870b": { - "dev_class": "gateway", - "firmware": "4.0.15", - "hardware": "AME Smile 2.0 board", - "location": "a57efe5f145f498c9be62a9b63626fbf", - "mac_address": "012345670001", - "model": "Gateway", - "name": "Smile Anna", - "vendor": "Plugwise", - "binary_sensors": { - "plugwise_notification": false }, - "sensors": { - "outdoor_temperature": 20.2 - } + "vendor": "Techneco" }, "3cb70739631c4d17a86b8b12e8a5161b": { + "active_preset": "home", + "available_schedules": [ + "standaard" + ], "dev_class": "thermostat", "firmware": "2018-02-08T11:15:53+01:00", "hardware": "6539-1301-5002", + "last_used": "standaard", "location": "c784ee9fdab44e1395b8dee7d7a497d5", + "mode": "auto", "model": "ThermoTouch", "name": "Anna", - "vendor": "Plugwise", - "thermostat": { - "setpoint": 20.5, - "lower_bound": 4.0, - "upper_bound": 30.0, - "resolution": 0.1 - }, - "preset_modes": ["no_frost", "home", "away", "asleep", "vacation"], - "active_preset": "home", - "available_schedules": ["standaard"], + "preset_modes": [ + "no_frost", + "home", + "away", + "asleep", + "vacation" + ], "selected_schedule": "standaard", - "last_used": "standaard", - "mode": "auto", "sensors": { - "temperature": 19.3, - "setpoint": 20.5, - "illuminance": 86.0, "cooling_activation_outdoor_temperature": 21.0, - "cooling_deactivation_threshold": 4.0 - } + "cooling_deactivation_threshold": 4.0, + "illuminance": 86.0, + "setpoint": 20.5, + "temperature": 19.3 + }, + "thermostat": { + "lower_bound": 4.0, + "resolution": 0.1, + "setpoint": 20.5, + "upper_bound": 30.0 + }, + "vendor": "Plugwise" } + }, + "gateway": { + "cooling_present": false, + "gateway_id": "015ae9ea3f964e668e490fa39da3870b", + "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", + "notifications": {}, + "smile_name": "Smile Anna" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/anna_heatpump_heating/notifications.json b/tests/components/plugwise/fixtures/anna_heatpump_heating/notifications.json index 0967ef424..9e26dfeeb 100644 --- a/tests/components/plugwise/fixtures/anna_heatpump_heating/notifications.json +++ b/tests/components/plugwise/fixtures/anna_heatpump_heating/notifications.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json b/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json index 40ecebfbd..ca92fc017 100644 --- a/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json @@ -1,88 +1,89 @@ { - "gateway": { - "smile_name": "Adam", - "gateway_id": "da224107914542988a88561b4452b0f6", - "heater_id": "056ee145a816487eaa69243c3280f8bf", - "cooling_present": true, - "notifications": {} - }, "devices": { - "ad4838d7d35c4d6ea796ee12ae5aedf8": { - "dev_class": "thermostat", - "location": "f2bf9048bef64cc5b6d5110154e33c81", - "model": "ThermoTouch", - "name": "Anna", - "vendor": "Plugwise", - "thermostat": { - "lower_bound": 1.0, - "upper_bound": 35.0, + "056ee145a816487eaa69243c3280f8bf": { + "available": true, + "binary_sensors": { + "cooling_state": true, + "dhw_state": false, + "flame_state": false, + "heating_state": false + }, + "dev_class": "heater_central", + "location": "bc93488efab249e5bc54fd7e175a6f91", + "maximum_boiler_temperature": { + "lower_bound": 25.0, "resolution": 0.01, - "setpoint_low": 4.0, - "setpoint_high": 23.5 + "setpoint": 60.0, + "upper_bound": 95.0 }, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "asleep", - "available_schedules": ["Weekschema", "Badkamer", "Test"], - "selected_schedule": "None", - "last_used": "Weekschema", - "control_state": "cooling", - "mode": "heat_cool", + "model": "Generic heater", + "name": "OpenTherm", "sensors": { - "temperature": 25.8, - "setpoint_low": 4.0, - "setpoint_high": 23.5 + "intended_boiler_temperature": 17.5, + "water_temperature": 19.0 }, - "available": true + "switches": { + "dhw_cm_switch": false + } }, "1772a4ea304041adb83f357b751341ff": { + "available": true, "dev_class": "thermo_sensor", "firmware": "2020-11-04T01:00:00+01:00", "hardware": "1", "location": "f871b8c4d63549319221e294e4f88074", "model": "Tom/Floor", "name": "Tom Badkamer", - "zigbee_mac_address": "ABCD012345670A01", - "vendor": "Plugwise", - "available": true, "sensors": { - "temperature": 21.6, "battery": 99, + "temperature": 21.6, "temperature_difference": 2.3, "valve_position": 0.0 - } - }, - "e2f4322d57924fa090fbbc48b3a140dc": { - "dev_class": "zone_thermostat", - "firmware": "2016-10-10T02:00:00+02:00", - "hardware": "255", - "location": "f871b8c4d63549319221e294e4f88074", - "model": "Lisa", - "name": "Lisa Badkamer", - "zigbee_mac_address": "ABCD012345670A04", + }, "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A01" + }, + "ad4838d7d35c4d6ea796ee12ae5aedf8": { + "active_preset": "asleep", + "available": true, + "available_schedules": [ + "Weekschema", + "Badkamer", + "Test" + ], + "control_state": "cooling", + "dev_class": "thermostat", + "last_used": "Weekschema", + "location": "f2bf9048bef64cc5b6d5110154e33c81", + "mode": "heat_cool", + "model": "ThermoTouch", + "name": "Anna", + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "None", + "sensors": { + "setpoint_high": 23.5, + "setpoint_low": 4.0, + "temperature": 25.8 + }, "thermostat": { - "lower_bound": 0.0, - "upper_bound": 99.9, + "lower_bound": 1.0, "resolution": 0.01, - "setpoint_low": 19.0, - "setpoint_high": 25.0 + "setpoint_high": 23.5, + "setpoint_low": 4.0, + "upper_bound": 35.0 }, - "available": true, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "home", - "available_schedules": ["Weekschema", "Badkamer", "Test"], - "selected_schedule": "Badkamer", - "last_used": "Badkamer", - "control_state": "off", - "mode": "auto", - "sensors": { - "temperature": 239, - "battery": 56, - "setpoint_low": 20.0, - "setpoint_high": 23.5 - } + "vendor": "Plugwise" }, "da224107914542988a88561b4452b0f6": { + "binary_sensors": { + "plugwise_notification": false + }, "dev_class": "gateway", "firmware": "3.6.4", "hardware": "AME Smile 2.0 board", @@ -90,8 +91,6 @@ "mac_address": "012345670001", "model": "Gateway", "name": "Adam", - "zigbee_mac_address": "ABCD012345670101", - "vendor": "Plugwise", "regulation_mode": "cooling", "regulation_modes": [ "heating", @@ -100,50 +99,71 @@ "bleeding_hot", "cooling" ], - "binary_sensors": { - "plugwise_notification": false - }, "sensors": { "outdoor_temperature": 29.65 - } - }, - "056ee145a816487eaa69243c3280f8bf": { - "dev_class": "heater_central", - "location": "bc93488efab249e5bc54fd7e175a6f91", - "model": "Generic heater", - "name": "OpenTherm", - "maximum_boiler_temperature": { - "setpoint": 60.0, - "lower_bound": 25.0, - "upper_bound": 95.0, - "resolution": 0.01 }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670101" + }, + "e2f4322d57924fa090fbbc48b3a140dc": { + "active_preset": "home", "available": true, - "binary_sensors": { - "dhw_state": false, - "heating_state": false, - "flame_state": false, - "cooling_state": true - }, + "available_schedules": [ + "Weekschema", + "Badkamer", + "Test" + ], + "control_state": "off", + "dev_class": "zone_thermostat", + "firmware": "2016-10-10T02:00:00+02:00", + "hardware": "255", + "last_used": "Badkamer", + "location": "f871b8c4d63549319221e294e4f88074", + "mode": "auto", + "model": "Lisa", + "name": "Lisa Badkamer", + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "Badkamer", "sensors": { - "water_temperature": 19.0, - "intended_boiler_temperature": 17.5 + "battery": 56, + "setpoint_high": 23.5, + "setpoint_low": 20.0, + "temperature": 239 }, - "switches": { - "dhw_cm_switch": false - } + "thermostat": { + "lower_bound": 0.0, + "resolution": 0.01, + "setpoint_high": 25.0, + "setpoint_low": 19.0, + "upper_bound": 99.9 + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A04" }, "e8ef2a01ed3b4139a53bf749204fe6b4": { "dev_class": "switching", - "model": "Switchgroup", - "name": "Test", "members": [ "2568cc4b9c1e401495d4741a5f89bee1", "29542b2b6a6a4169acecc15c72a599b8" ], + "model": "Switchgroup", + "name": "Test", "switches": { "relay": true } } + }, + "gateway": { + "cooling_present": true, + "gateway_id": "da224107914542988a88561b4452b0f6", + "heater_id": "056ee145a816487eaa69243c3280f8bf", + "notifications": {}, + "smile_name": "Adam" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/m_adam_cooling/notifications.json b/tests/components/plugwise/fixtures/m_adam_cooling/notifications.json index 0967ef424..9e26dfeeb 100644 --- a/tests/components/plugwise/fixtures/m_adam_cooling/notifications.json +++ b/tests/components/plugwise/fixtures/m_adam_cooling/notifications.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json index 490f3def7..53e4d0538 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json @@ -1,93 +1,101 @@ { - "gateway": { - "smile_name": "Smile Anna", - "gateway_id": "015ae9ea3f964e668e490fa39da3870b", - "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", - "cooling_present": true, - "notifications": {} - }, "devices": { - "1cbf783bb11e4a7c8a6843dee3a86927": { - "dev_class": "heater_central", + "015ae9ea3f964e668e490fa39da3870b": { + "binary_sensors": { + "plugwise_notification": false + }, + "dev_class": "gateway", + "firmware": "4.0.15", + "hardware": "AME Smile 2.0 board", "location": "a57efe5f145f498c9be62a9b63626fbf", - "model": "Generic heater/cooler", - "name": "OpenTherm", - "vendor": "Techneco", - "maximum_boiler_temperature": { - "setpoint": 60.0, - "lower_bound": 0.0, - "upper_bound": 100.0, - "resolution": 1.0 + "mac_address": "012345670001", + "model": "Gateway", + "name": "Smile Anna", + "sensors": { + "outdoor_temperature": 28.2 }, + "vendor": "Plugwise" + }, + "1cbf783bb11e4a7c8a6843dee3a86927": { "available": true, "binary_sensors": { - "dhw_state": false, - "heating_state": false, "compressor_state": true, "cooling_enabled": true, - "slave_boiler_state": false, + "cooling_state": true, + "dhw_state": false, "flame_state": false, - "cooling_state": true + "heating_state": false, + "slave_boiler_state": false }, + "dev_class": "heater_central", + "location": "a57efe5f145f498c9be62a9b63626fbf", + "maximum_boiler_temperature": { + "lower_bound": 0.0, + "resolution": 1.0, + "setpoint": 60.0, + "upper_bound": 100.0 + }, + "model": "Generic heater/cooler", + "name": "OpenTherm", "sensors": { - "water_temperature": 22.7, - "domestic_hot_water_setpoint": 60.0, "dhw_temperature": 41.5, + "domestic_hot_water_setpoint": 60.0, "intended_boiler_temperature": 0.0, "modulation_level": 40, + "outdoor_air_temperature": 28.0, "return_temperature": 23.8, "water_pressure": 1.57, - "outdoor_air_temperature": 28.0 + "water_temperature": 22.7 }, "switches": { "dhw_cm_switch": false - } - }, - "015ae9ea3f964e668e490fa39da3870b": { - "dev_class": "gateway", - "firmware": "4.0.15", - "hardware": "AME Smile 2.0 board", - "location": "a57efe5f145f498c9be62a9b63626fbf", - "mac_address": "012345670001", - "model": "Gateway", - "name": "Smile Anna", - "vendor": "Plugwise", - "binary_sensors": { - "plugwise_notification": false }, - "sensors": { - "outdoor_temperature": 28.2 - } + "vendor": "Techneco" }, "3cb70739631c4d17a86b8b12e8a5161b": { + "active_preset": "home", + "available_schedules": [ + "standaard" + ], "dev_class": "thermostat", "firmware": "2018-02-08T11:15:53+01:00", "hardware": "6539-1301-5002", + "last_used": "standaard", "location": "c784ee9fdab44e1395b8dee7d7a497d5", + "mode": "auto", "model": "ThermoTouch", "name": "Anna", - "vendor": "Plugwise", - "thermostat": { - "lower_bound": 4.0, - "upper_bound": 30.0, - "resolution": 0.1, - "setpoint_low": 20.5, - "setpoint_high": 24.0 - }, - "preset_modes": ["no_frost", "home", "away", "asleep", "vacation"], - "active_preset": "home", - "available_schedules": ["standaard"], + "preset_modes": [ + "no_frost", + "home", + "away", + "asleep", + "vacation" + ], "selected_schedule": "standaard", - "last_used": "standaard", - "mode": "auto", "sensors": { - "temperature": 26.3, - "illuminance": 86.0, "cooling_activation_outdoor_temperature": 21.0, "cooling_deactivation_threshold": 4.0, + "illuminance": 86.0, + "setpoint_high": 24.0, "setpoint_low": 20.5, - "setpoint_high": 24.0 - } + "temperature": 26.3 + }, + "thermostat": { + "lower_bound": 4.0, + "resolution": 0.1, + "setpoint_high": 24.0, + "setpoint_low": 20.5, + "upper_bound": 30.0 + }, + "vendor": "Plugwise" } + }, + "gateway": { + "cooling_present": true, + "gateway_id": "015ae9ea3f964e668e490fa39da3870b", + "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", + "notifications": {}, + "smile_name": "Smile Anna" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/notifications.json b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/notifications.json index 0967ef424..9e26dfeeb 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/notifications.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/notifications.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json index 0beed5537..9188a68c8 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json @@ -1,93 +1,101 @@ { - "gateway": { - "smile_name": "Smile Anna", - "gateway_id": "015ae9ea3f964e668e490fa39da3870b", - "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", - "cooling_present": true, - "notifications": {} - }, "devices": { - "1cbf783bb11e4a7c8a6843dee3a86927": { - "dev_class": "heater_central", + "015ae9ea3f964e668e490fa39da3870b": { + "binary_sensors": { + "plugwise_notification": false + }, + "dev_class": "gateway", + "firmware": "4.0.15", + "hardware": "AME Smile 2.0 board", "location": "a57efe5f145f498c9be62a9b63626fbf", - "model": "Generic heater/cooler", - "name": "OpenTherm", - "vendor": "Techneco", - "maximum_boiler_temperature": { - "setpoint": 60.0, - "lower_bound": 0.0, - "upper_bound": 100.0, - "resolution": 1.0 + "mac_address": "012345670001", + "model": "Gateway", + "name": "Smile Anna", + "sensors": { + "outdoor_temperature": 28.2 }, + "vendor": "Plugwise" + }, + "1cbf783bb11e4a7c8a6843dee3a86927": { "available": true, "binary_sensors": { - "dhw_state": false, - "heating_state": false, "compressor_state": false, "cooling_enabled": true, - "slave_boiler_state": false, + "cooling_state": false, + "dhw_state": false, "flame_state": false, - "cooling_state": false + "heating_state": false, + "slave_boiler_state": false }, + "dev_class": "heater_central", + "location": "a57efe5f145f498c9be62a9b63626fbf", + "maximum_boiler_temperature": { + "lower_bound": 0.0, + "resolution": 1.0, + "setpoint": 60.0, + "upper_bound": 100.0 + }, + "model": "Generic heater/cooler", + "name": "OpenTherm", "sensors": { - "water_temperature": 19.1, - "domestic_hot_water_setpoint": 60.0, "dhw_temperature": 46.3, + "domestic_hot_water_setpoint": 60.0, "intended_boiler_temperature": 18.0, "modulation_level": 0, + "outdoor_air_temperature": 28.2, "return_temperature": 22.0, "water_pressure": 1.57, - "outdoor_air_temperature": 28.2 + "water_temperature": 19.1 }, "switches": { "dhw_cm_switch": false - } - }, - "015ae9ea3f964e668e490fa39da3870b": { - "dev_class": "gateway", - "firmware": "4.0.15", - "hardware": "AME Smile 2.0 board", - "location": "a57efe5f145f498c9be62a9b63626fbf", - "mac_address": "012345670001", - "model": "Gateway", - "name": "Smile Anna", - "vendor": "Plugwise", - "binary_sensors": { - "plugwise_notification": false }, - "sensors": { - "outdoor_temperature": 28.2 - } + "vendor": "Techneco" }, "3cb70739631c4d17a86b8b12e8a5161b": { + "active_preset": "home", + "available_schedules": [ + "standaard" + ], "dev_class": "thermostat", "firmware": "2018-02-08T11:15:53+01:00", "hardware": "6539-1301-5002", + "last_used": "standaard", "location": "c784ee9fdab44e1395b8dee7d7a497d5", + "mode": "auto", "model": "ThermoTouch", "name": "Anna", - "vendor": "Plugwise", - "thermostat": { - "lower_bound": 4.0, - "upper_bound": 30.0, - "resolution": 0.1, - "setpoint_low": 20.5, - "setpoint_high": 24.0 - }, - "preset_modes": ["no_frost", "home", "away", "asleep", "vacation"], - "active_preset": "home", - "available_schedules": ["standaard"], + "preset_modes": [ + "no_frost", + "home", + "away", + "asleep", + "vacation" + ], "selected_schedule": "standaard", - "last_used": "standaard", - "mode": "auto", "sensors": { - "temperature": 23.0, - "illuminance": 86.0, "cooling_activation_outdoor_temperature": 25.0, "cooling_deactivation_threshold": 4.0, + "illuminance": 86.0, + "setpoint_high": 24.0, "setpoint_low": 20.5, - "setpoint_high": 24.0 - } + "temperature": 23.0 + }, + "thermostat": { + "lower_bound": 4.0, + "resolution": 0.1, + "setpoint_high": 24.0, + "setpoint_low": 20.5, + "upper_bound": 30.0 + }, + "vendor": "Plugwise" } + }, + "gateway": { + "cooling_present": true, + "gateway_id": "015ae9ea3f964e668e490fa39da3870b", + "heater_id": "1cbf783bb11e4a7c8a6843dee3a86927", + "notifications": {}, + "smile_name": "Smile Anna" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/notifications.json b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/notifications.json index 0967ef424..9e26dfeeb 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/notifications.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/notifications.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json b/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json index f76b17b8a..67400e2e4 100644 --- a/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json +++ b/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json @@ -1,11 +1,9 @@ { - "gateway": { - "smile_name": "Smile P1", - "gateway_id": "cd3e822288064775a7c4afcdd70bdda2", - "notifications": {} - }, "devices": { "cd3e822288064775a7c4afcdd70bdda2": { + "binary_sensors": { + "plugwise_notification": false + }, "dev_class": "gateway", "firmware": "3.3.9", "hardware": "AME Smile 2.0 board", @@ -13,36 +11,38 @@ "mac_address": "012345670001", "model": "Gateway", "name": "Smile P1", - "vendor": "Plugwise", - "binary_sensors": { - "plugwise_notification": false - } + "vendor": "Plugwise" }, "e950c7d5e1ee407a858e2a8b5016c8b3": { + "available": true, "dev_class": "smartmeter", "location": "cd3e822288064775a7c4afcdd70bdda2", "model": "2M550E-1012", "name": "P1", - "vendor": "ISKRAEMECO", - "available": true, "sensors": { - "net_electricity_point": -2816, - "electricity_consumed_peak_point": 0, + "electricity_consumed_off_peak_cumulative": 551.09, + "electricity_consumed_off_peak_interval": 0, "electricity_consumed_off_peak_point": 0, - "net_electricity_cumulative": 442.972, "electricity_consumed_peak_cumulative": 442.932, - "electricity_consumed_off_peak_cumulative": 551.09, "electricity_consumed_peak_interval": 0, - "electricity_consumed_off_peak_interval": 0, - "electricity_produced_peak_point": 2816, + "electricity_consumed_peak_point": 0, + "electricity_produced_off_peak_cumulative": 154.491, + "electricity_produced_off_peak_interval": 0, "electricity_produced_off_peak_point": 0, "electricity_produced_peak_cumulative": 396.559, - "electricity_produced_off_peak_cumulative": 154.491, "electricity_produced_peak_interval": 0, - "electricity_produced_off_peak_interval": 0, + "electricity_produced_peak_point": 2816, "gas_consumed_cumulative": 584.85, - "gas_consumed_interval": 0.0 - } + "gas_consumed_interval": 0.0, + "net_electricity_cumulative": 442.972, + "net_electricity_point": -2816 + }, + "vendor": "ISKRAEMECO" } + }, + "gateway": { + "gateway_id": "cd3e822288064775a7c4afcdd70bdda2", + "notifications": {}, + "smile_name": "Smile P1" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/p1v3_full_option/notifications.json b/tests/components/plugwise/fixtures/p1v3_full_option/notifications.json index 0967ef424..9e26dfeeb 100644 --- a/tests/components/plugwise/fixtures/p1v3_full_option/notifications.json +++ b/tests/components/plugwise/fixtures/p1v3_full_option/notifications.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json b/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json index 4ba77c1e2..da05edf29 100644 --- a/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json +++ b/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json @@ -1,11 +1,9 @@ { - "gateway": { - "smile_name": "Smile P1", - "gateway_id": "03e65b16e4b247a29ae0d75a78cb492e", - "notifications": {} - }, "devices": { "03e65b16e4b247a29ae0d75a78cb492e": { + "binary_sensors": { + "plugwise_notification": false + }, "dev_class": "gateway", "firmware": "4.4.2", "hardware": "AME Smile 2.0 board", @@ -13,45 +11,47 @@ "mac_address": "012345670001", "model": "Gateway", "name": "Smile P1", - "vendor": "Plugwise", - "binary_sensors": { - "plugwise_notification": false - } + "vendor": "Plugwise" }, "b82b6b3322484f2ea4e25e0bd5f3d61f": { + "available": true, "dev_class": "smartmeter", "location": "03e65b16e4b247a29ae0d75a78cb492e", "model": "XMX5LGF0010453051839", "name": "P1", - "vendor": "XEMEX NV", - "available": true, "sensors": { - "net_electricity_point": 5553, - "electricity_consumed_peak_point": 0, + "electricity_consumed_off_peak_cumulative": 70537.898, + "electricity_consumed_off_peak_interval": 314, "electricity_consumed_off_peak_point": 5553, - "net_electricity_cumulative": 231866.539, "electricity_consumed_peak_cumulative": 161328.641, - "electricity_consumed_off_peak_cumulative": 70537.898, "electricity_consumed_peak_interval": 0, - "electricity_consumed_off_peak_interval": 314, - "electricity_produced_peak_point": 0, - "electricity_produced_off_peak_point": 0, - "electricity_produced_peak_cumulative": 0.0, - "electricity_produced_off_peak_cumulative": 0.0, - "electricity_produced_peak_interval": 0, - "electricity_produced_off_peak_interval": 0, + "electricity_consumed_peak_point": 0, "electricity_phase_one_consumed": 1763, - "electricity_phase_two_consumed": 1703, - "electricity_phase_three_consumed": 2080, "electricity_phase_one_produced": 0, - "electricity_phase_two_produced": 0, + "electricity_phase_three_consumed": 2080, "electricity_phase_three_produced": 0, + "electricity_phase_two_consumed": 1703, + "electricity_phase_two_produced": 0, + "electricity_produced_off_peak_cumulative": 0.0, + "electricity_produced_off_peak_interval": 0, + "electricity_produced_off_peak_point": 0, + "electricity_produced_peak_cumulative": 0.0, + "electricity_produced_peak_interval": 0, + "electricity_produced_peak_point": 0, "gas_consumed_cumulative": 16811.37, "gas_consumed_interval": 0.06, + "net_electricity_cumulative": 231866.539, + "net_electricity_point": 5553, "voltage_phase_one": 233.2, - "voltage_phase_two": 234.4, - "voltage_phase_three": 234.7 - } + "voltage_phase_three": 234.7, + "voltage_phase_two": 234.4 + }, + "vendor": "XEMEX NV" } + }, + "gateway": { + "gateway_id": "03e65b16e4b247a29ae0d75a78cb492e", + "notifications": {}, + "smile_name": "Smile P1" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json b/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json index 0967ef424..9e26dfeeb 100644 --- a/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json +++ b/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/stretch_v31/all_data.json b/tests/components/plugwise/fixtures/stretch_v31/all_data.json index ecd173f92..51a636ebd 100644 --- a/tests/components/plugwise/fixtures/stretch_v31/all_data.json +++ b/tests/components/plugwise/fixtures/stretch_v31/all_data.json @@ -1,9 +1,4 @@ { - "gateway": { - "smile_name": "Stretch", - "gateway_id": "0000aaaa0000aaaa0000aaaa0000aa00", - "notifications": {} - }, "devices": { "0000aaaa0000aaaa0000aaaa0000aa00": { "dev_class": "gateway", @@ -12,8 +7,27 @@ "mac_address": "01:23:45:67:89:AB", "model": "Gateway", "name": "Stretch", - "zigbee_mac_address": "ABCD012345670101", - "vendor": "Plugwise" + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670101" + }, + "059e4d03c7a34d278add5c7a4a781d19": { + "dev_class": "washingmachine", + "firmware": "2011-06-27T10:52:18+02:00", + "hardware": "0000-0440-0107", + "location": "0000aaaa0000aaaa0000aaaa0000aa00", + "model": "Circle type F", + "name": "Wasmachine (52AC1)", + "sensors": { + "electricity_consumed": 0.0, + "electricity_consumed_interval": 0.0, + "electricity_produced": 0.0 + }, + "switches": { + "lock": false, + "relay": true + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A01" }, "5871317346d045bc9f6b987ef25ee638": { "dev_class": "water_heater_vessel", @@ -22,35 +36,27 @@ "location": "0000aaaa0000aaaa0000aaaa0000aa00", "model": "Circle type F", "name": "Boiler (1EB31)", - "zigbee_mac_address": "ABCD012345670A07", - "vendor": "Plugwise", "sensors": { "electricity_consumed": 1.19, "electricity_consumed_interval": 0.0, "electricity_produced": 0.0 }, "switches": { - "relay": true, - "lock": false - } - }, - "e1c884e7dede431dadee09506ec4f859": { - "dev_class": "refrigerator", - "firmware": "2011-06-27T10:47:37+02:00", - "hardware": "6539-0700-7330", - "location": "0000aaaa0000aaaa0000aaaa0000aa00", - "model": "Circle+ type F", - "name": "Koelkast (92C4A)", - "zigbee_mac_address": "0123456789AB", - "vendor": "Plugwise", - "sensors": { - "electricity_consumed": 50.5, - "electricity_consumed_interval": 0.08, - "electricity_produced": 0.0 + "lock": false, + "relay": true }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A07" + }, + "71e1944f2a944b26ad73323e399efef0": { + "dev_class": "switching", + "members": [ + "5ca521ac179d468e91d772eeeb8a2117" + ], + "model": "Switchgroup", + "name": "Test", "switches": { - "relay": true, - "lock": false + "relay": true } }, "aac7b735042c4832ac9ff33aae4f453b": { @@ -60,17 +66,17 @@ "location": "0000aaaa0000aaaa0000aaaa0000aa00", "model": "Circle type F", "name": "Vaatwasser (2a1ab)", - "zigbee_mac_address": "ABCD012345670A02", - "vendor": "Plugwise", "sensors": { "electricity_consumed": 0.0, "electricity_consumed_interval": 0.71, "electricity_produced": 0.0 }, "switches": { - "relay": true, - "lock": false - } + "lock": false, + "relay": true + }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A02" }, "cfe95cf3de1948c0b8955125bf754614": { "dev_class": "dryer", @@ -79,50 +85,32 @@ "location": "0000aaaa0000aaaa0000aaaa0000aa00", "model": "Circle type F", "name": "Droger (52559)", - "zigbee_mac_address": "ABCD012345670A04", - "vendor": "Plugwise", "sensors": { "electricity_consumed": 0.0, "electricity_consumed_interval": 0.0, "electricity_produced": 0.0 }, "switches": { - "relay": true, - "lock": false - } - }, - "059e4d03c7a34d278add5c7a4a781d19": { - "dev_class": "washingmachine", - "firmware": "2011-06-27T10:52:18+02:00", - "hardware": "0000-0440-0107", - "location": "0000aaaa0000aaaa0000aaaa0000aa00", - "model": "Circle type F", - "name": "Wasmachine (52AC1)", - "zigbee_mac_address": "ABCD012345670A01", - "vendor": "Plugwise", - "sensors": { - "electricity_consumed": 0.0, - "electricity_consumed_interval": 0.0, - "electricity_produced": 0.0 + "lock": false, + "relay": true }, - "switches": { - "relay": true, - "lock": false - } + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A04" }, - "71e1944f2a944b26ad73323e399efef0": { + "d03738edfcc947f7b8f4573571d90d2d": { "dev_class": "switching", + "members": [ + "059e4d03c7a34d278add5c7a4a781d19", + "cfe95cf3de1948c0b8955125bf754614" + ], "model": "Switchgroup", - "name": "Test", - "members": ["5ca521ac179d468e91d772eeeb8a2117"], + "name": "Schakel", "switches": { "relay": true } }, "d950b314e9d8499f968e6db8d82ef78c": { "dev_class": "report", - "model": "Switchgroup", - "name": "Stroomvreters", "members": [ "059e4d03c7a34d278add5c7a4a781d19", "5871317346d045bc9f6b987ef25ee638", @@ -130,21 +118,35 @@ "cfe95cf3de1948c0b8955125bf754614", "e1c884e7dede431dadee09506ec4f859" ], + "model": "Switchgroup", + "name": "Stroomvreters", "switches": { "relay": true } }, - "d03738edfcc947f7b8f4573571d90d2d": { - "dev_class": "switching", - "model": "Switchgroup", - "name": "Schakel", - "members": [ - "059e4d03c7a34d278add5c7a4a781d19", - "cfe95cf3de1948c0b8955125bf754614" - ], + "e1c884e7dede431dadee09506ec4f859": { + "dev_class": "refrigerator", + "firmware": "2011-06-27T10:47:37+02:00", + "hardware": "6539-0700-7330", + "location": "0000aaaa0000aaaa0000aaaa0000aa00", + "model": "Circle+ type F", + "name": "Koelkast (92C4A)", + "sensors": { + "electricity_consumed": 50.5, + "electricity_consumed_interval": 0.08, + "electricity_produced": 0.0 + }, "switches": { + "lock": false, "relay": true - } + }, + "vendor": "Plugwise", + "zigbee_mac_address": "0123456789AB" } + }, + "gateway": { + "gateway_id": "0000aaaa0000aaaa0000aaaa0000aa00", + "notifications": {}, + "smile_name": "Stretch" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/stretch_v31/notifications.json b/tests/components/plugwise/fixtures/stretch_v31/notifications.json index 0967ef424..9e26dfeeb 100644 --- a/tests/components/plugwise/fixtures/stretch_v31/notifications.json +++ b/tests/components/plugwise/fixtures/stretch_v31/notifications.json @@ -1 +1 @@ -{} +{} \ No newline at end of file From 23904c37b6617b0683c18e424a728693ad4492b0 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Fri, 5 May 2023 08:39:59 +0200 Subject: [PATCH 40/52] Restore proper naming --- custom_components/plugwise/number.py | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 38eba6779..a82ba3fb6 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -30,10 +30,10 @@ class PlugwiseNumberMixin: """Mixin values for Plugwse entities.""" command: Callable[[Smile, str, float], Awaitable[None]] - max_value_fn: Callable[[T], float] - min_value_fn: Callable[[T], float] - step_key_fn: Callable[[T], float] - value_fn: Callable[[T], float] + native_max_value_fn: Callable[[T], float] + native_min_value_fn: Callable[[T], float] + native_step_key_fn: Callable[[T], float] + native_value_fn: Callable[[T], float] @dataclass @@ -48,10 +48,10 @@ class PlugwiseNumberEntityDescription(NumberEntityDescription, PlugwiseNumberMix command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - max_value_fn=lambda data: data["maximum_boiler_temperature"]["upper_bound"] or 0.0, # type: ignore [index] - min_value_fn=lambda data: data["maximum_boiler_temperature"]["lower_bound"] or 0.0, # type: ignore [index] - step_key_fn=lambda data: data["maximum_boiler_temperature"]["resolution"] or 0.0, # type: ignore [index] - value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"] or 0.0, # type: ignore [index] + native_max_value_fn=lambda data: data["maximum_boiler_temperature"]["upper_bound"] or 0.0, # type: ignore [index] + native_min_value_fn=lambda data: data["maximum_boiler_temperature"]["lower_bound"] or 0.0, # type: ignore [index] + native_step_key_fn=lambda data: data["maximum_boiler_temperature"]["resolution"] or 0.0, # type: ignore [index] + native_value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"] or 0.0, # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), PlugwiseNumberEntityDescription( @@ -60,10 +60,10 @@ class PlugwiseNumberEntityDescription(NumberEntityDescription, PlugwiseNumberMix command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - max_value_fn=lambda data: data["domestic_hot_water_setpoint"]["upper_bound"] or 0.0, # type: ignore [index] - min_value_fn=lambda data: data["domestic_hot_water_setpoint"]["lower_bound"] or 0.0, # type: ignore [index] - step_key_fn=lambda data: data["domestic_hot_water_setpoint"]["resolution"] or 0.0, # type: ignore [index] - value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"] or 0.0, # type: ignore [index] + native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"]["upper_bound"] or 0.0, # type: ignore [index] + native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"]["lower_bound"] or 0.0, # type: ignore [index] + native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"]["resolution"] or 0.0, # type: ignore [index] + native_value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"] or 0.0, # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), ) @@ -112,22 +112,22 @@ def __init__( @property def native_step(self) -> float: """Return the setpoint step value.""" - return self.entity_description.step_key_fn(self.device) + return self.entity_description.native_step_key_fn(self.device) @property def native_value(self) -> float: """Return the present setpoint value.""" - return self.entity_description.value_fn(self.device) + return self.entity_description.native_value_fn(self.device) @property def native_min_value(self) -> float: """Return the setpoint min. value.""" - return self.entity_description.min_value_fn(self.device) + return self.entity_description.native_min_value_fn(self.device) @property def native_max_value(self) -> float: """Return the setpoint max. value.""" - return self.entity_description.max_value_fn(self.device) + return self.entity_description.native_max_value_fn(self.device) async def async_set_native_value(self, value: float) -> None: """Change to the new setpoint value.""" From e7c57e873bc07309ef381ac1fb7741abbf5e17bc Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Fri, 5 May 2023 09:51:25 +0200 Subject: [PATCH 41/52] Rework for max_dhw --- custom_components/plugwise/number.py | 12 +- custom_components/plugwise/strings.json | 2 +- .../plugwise/translations/en.json | 2 +- .../plugwise/translations/nl.json | 2 +- .../fixtures/m_adam_heating/all_data.json | 211 ++++++++++-------- .../m_adam_heating/notifications.json | 2 +- tests/components/plugwise/test_number.py | 2 +- 7 files changed, 129 insertions(+), 104 deletions(-) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index a82ba3fb6..fc857b8b2 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -55,15 +55,15 @@ class PlugwiseNumberEntityDescription(NumberEntityDescription, PlugwiseNumberMix native_unit_of_measurement=TEMP_CELSIUS, ), PlugwiseNumberEntityDescription( - key="domestic_hot_water_setpoint", - translation_key="domestic_hot_water_setpoint", + key="max_dhw_temperature", + translation_key="max_dhw_temperature", command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["domestic_hot_water_setpoint"]["upper_bound"] or 0.0, # type: ignore [index] - native_min_value_fn=lambda data: data["domestic_hot_water_setpoint"]["lower_bound"] or 0.0, # type: ignore [index] - native_step_key_fn=lambda data: data["domestic_hot_water_setpoint"]["resolution"] or 0.0, # type: ignore [index] - native_value_fn=lambda data: data["domestic_hot_water_setpoint"]["setpoint"] or 0.0, # type: ignore [index] + native_max_value_fn=lambda data: data["max_dhw_temperature"]["upper_bound"] or 0.0, # type: ignore [index] + native_min_value_fn=lambda data: data["max_dhw_temperature"]["lower_bound"] or 0.0, # type: ignore [index] + native_step_key_fn=lambda data: data["max_dhw_temperature"]["resolution"] or 0.0, # type: ignore [index] + native_value_fn=lambda data: data["max_dhw_temperature"]["setpoint"] or 0.0, # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), ) diff --git a/custom_components/plugwise/strings.json b/custom_components/plugwise/strings.json index fc29356d4..63abaee47 100644 --- a/custom_components/plugwise/strings.json +++ b/custom_components/plugwise/strings.json @@ -75,7 +75,7 @@ "maximum_boiler_temperature": { "name": "Maximum boiler temperature setpoint" }, - "domestic_hot_water_setpoint": { "name": "Domestic hot water setpoint" } + "max_dhw_temperature": { "name": "Domestic hot water setpoint" } }, "select": { "dhw_mode": { diff --git a/custom_components/plugwise/translations/en.json b/custom_components/plugwise/translations/en.json index ec43e8596..8e2b36ce3 100644 --- a/custom_components/plugwise/translations/en.json +++ b/custom_components/plugwise/translations/en.json @@ -94,7 +94,7 @@ "maximum_boiler_temperature": { "name": "Maximum boiler temperature setpoint" }, - "domestic_hot_water_setpoint": { "name": "Domestic hot water setpoint" } + "max_dhw_temperature": { "name": "Domestic hot water setpoint" } }, "select": { "dhw_mode": { diff --git a/custom_components/plugwise/translations/nl.json b/custom_components/plugwise/translations/nl.json index c458bb061..e0380491a 100644 --- a/custom_components/plugwise/translations/nl.json +++ b/custom_components/plugwise/translations/nl.json @@ -92,7 +92,7 @@ }, "number": { "maximum_boiler_temperature": { "name": "Max cv-ketel temperatuur" }, - "domestic_hot_water_setpoint": { + "max_dhw_temperature": { "name": "Max huishoudelijk warm water temperatuur" } }, diff --git a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json index d1726b687..4f3ebaba6 100644 --- a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json @@ -1,84 +1,92 @@ { - "gateway": { - "smile_name": "Adam", - "gateway_id": "da224107914542988a88561b4452b0f6", - "heater_id": "056ee145a816487eaa69243c3280f8bf", - "cooling_present": false, - "notifications": {} - }, "devices": { - "ad4838d7d35c4d6ea796ee12ae5aedf8": { - "dev_class": "thermostat", - "location": "f2bf9048bef64cc5b6d5110154e33c81", - "model": "ThermoTouch", - "name": "Anna", - "vendor": "Plugwise", - "thermostat": { - "lower_bound": 1.0, - "upper_bound": 35.0, + "056ee145a816487eaa69243c3280f8bf": { + "available": true, + "binary_sensors": { + "dhw_state": false, + "flame_state": false, + "heating_state": true + }, + "dev_class": "heater_central", + "location": "bc93488efab249e5bc54fd7e175a6f91", + "max_dhw_temperature": { + "lower_bound": 40.0, "resolution": 0.01, - "setpoint": 20.0 + "setpoint": 60.0, + "upper_bound": 60.0 }, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "asleep", - "available_schedules": ["Weekschema", "Badkamer", "Test"], - "selected_schedule": "None", - "last_used": "Weekschema", - "control_state": "heating", - "mode": "heat", + "maximum_boiler_temperature": { + "lower_bound": 25.0, + "resolution": 0.01, + "setpoint": 60.0, + "upper_bound": 95.0 + }, + "model": "Generic heater", + "name": "OpenTherm", "sensors": { - "temperature": 19.1, - "setpoint": 20.0 + "intended_boiler_temperature": 38.1, + "water_temperature": 37.0 }, - "available": true + "switches": { + "dhw_cm_switch": false + } }, "1772a4ea304041adb83f357b751341ff": { + "available": true, "dev_class": "thermo_sensor", "firmware": "2020-11-04T01:00:00+01:00", "hardware": "1", "location": "f871b8c4d63549319221e294e4f88074", "model": "Tom/Floor", "name": "Tom Badkamer", - "zigbee_mac_address": "ABCD012345670A01", - "vendor": "Plugwise", - "available": true, "sensors": { - "temperature": 18.6, "battery": 99, + "temperature": 18.6, "temperature_difference": 2.3, "valve_position": 0.0 - } - }, - "e2f4322d57924fa090fbbc48b3a140dc": { - "dev_class": "zone_thermostat", - "firmware": "2016-10-10T02:00:00+02:00", - "hardware": "255", - "location": "f871b8c4d63549319221e294e4f88074", - "model": "Lisa", - "name": "Lisa Badkamer", - "zigbee_mac_address": "ABCD012345670A04", + }, "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A01" + }, + "ad4838d7d35c4d6ea796ee12ae5aedf8": { + "active_preset": "asleep", + "available": true, + "available_schedules": [ + "Weekschema", + "Badkamer", + "Test" + ], + "control_state": "heating", + "dev_class": "thermostat", + "last_used": "Weekschema", + "location": "f2bf9048bef64cc5b6d5110154e33c81", + "mode": "heat", + "model": "ThermoTouch", + "name": "Anna", + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "None", + "sensors": { + "setpoint": 20.0, + "temperature": 19.1 + }, "thermostat": { - "lower_bound": 0.0, - "upper_bound": 99.9, + "lower_bound": 1.0, "resolution": 0.01, - "setpoint": 15.0 + "setpoint": 20.0, + "upper_bound": 35.0 }, - "available": true, - "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], - "active_preset": "home", - "available_schedules": ["Weekschema", "Badkamer", "Test"], - "selected_schedule": "Badkamer", - "last_used": "Badkamer", - "control_state": "off", - "mode": "auto", - "sensors": { - "temperature": 17.9, - "battery": 56, - "setpoint": 15.0 - } + "vendor": "Plugwise" }, "da224107914542988a88561b4452b0f6": { + "binary_sensors": { + "plugwise_notification": false + }, "dev_class": "gateway", "firmware": "3.6.4", "hardware": "AME Smile 2.0 board", @@ -86,59 +94,76 @@ "mac_address": "012345670001", "model": "Gateway", "name": "Adam", - "zigbee_mac_address": "ABCD012345670101", - "vendor": "Plugwise", "regulation_mode": "heating", - "regulation_modes": ["heating", "off", "bleeding_cold", "bleeding_hot"], - "binary_sensors": { - "plugwise_notification": false - }, + "regulation_modes": [ + "heating", + "off", + "bleeding_cold", + "bleeding_hot" + ], "sensors": { "outdoor_temperature": -1.25 - } - }, - "056ee145a816487eaa69243c3280f8bf": { - "dev_class": "heater_central", - "location": "bc93488efab249e5bc54fd7e175a6f91", - "model": "Generic heater", - "name": "OpenTherm", - "maximum_boiler_temperature": { - "setpoint": 60.0, - "lower_bound": 25.0, - "upper_bound": 95.0, - "resolution": 0.01 }, + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670101" + }, + "e2f4322d57924fa090fbbc48b3a140dc": { + "active_preset": "home", "available": true, - "binary_sensors": { - "dhw_state": false, - "heating_state": true, - "flame_state": false - }, + "available_schedules": [ + "Weekschema", + "Badkamer", + "Test" + ], + "control_state": "off", + "dev_class": "zone_thermostat", + "firmware": "2016-10-10T02:00:00+02:00", + "hardware": "255", + "last_used": "Badkamer", + "location": "f871b8c4d63549319221e294e4f88074", + "mode": "auto", + "model": "Lisa", + "name": "Lisa Badkamer", + "preset_modes": [ + "home", + "asleep", + "away", + "vacation", + "no_frost" + ], + "selected_schedule": "Badkamer", "sensors": { - "water_temperature": 37.0, - "intended_boiler_temperature": 38.1 + "battery": 56, + "setpoint": 15.0, + "temperature": 17.9 }, - "switches": { - "dhw_cm_switch": false + "thermostat": { + "lower_bound": 0.0, + "resolution": 0.01, + "setpoint": 15.0, + "upper_bound": 99.9 }, - "domestic_hot_water_setpoint": { - "setpoint": 60.0, - "lower_bound": 40.0, - "upper_bound": 60.0, - "resolution": 0.01 - } + "vendor": "Plugwise", + "zigbee_mac_address": "ABCD012345670A04" }, "e8ef2a01ed3b4139a53bf749204fe6b4": { "dev_class": "switching", - "model": "Switchgroup", - "name": "Test", "members": [ "2568cc4b9c1e401495d4741a5f89bee1", "29542b2b6a6a4169acecc15c72a599b8" ], + "model": "Switchgroup", + "name": "Test", "switches": { "relay": true } } + }, + "gateway": { + "cooling_present": false, + "gateway_id": "da224107914542988a88561b4452b0f6", + "heater_id": "056ee145a816487eaa69243c3280f8bf", + "notifications": {}, + "smile_name": "Adam" } -} +} \ No newline at end of file diff --git a/tests/components/plugwise/fixtures/m_adam_heating/notifications.json b/tests/components/plugwise/fixtures/m_adam_heating/notifications.json index 0967ef424..9e26dfeeb 100644 --- a/tests/components/plugwise/fixtures/m_adam_heating/notifications.json +++ b/tests/components/plugwise/fixtures/m_adam_heating/notifications.json @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/tests/components/plugwise/test_number.py b/tests/components/plugwise/test_number.py index f2a42bb1d..3f70e3a64 100644 --- a/tests/components/plugwise/test_number.py +++ b/tests/components/plugwise/test_number.py @@ -58,5 +58,5 @@ async def test_adam_dhw_setpoint_change( assert mock_smile_adam_2.set_number_setpoint.call_count == 1 mock_smile_adam_2.set_number_setpoint.assert_called_with( - "domestic_hot_water_setpoint", 55.0 + "max_dhw_temperature", 55.0 ) From 4d4e080ce802c4d3b4882a580e325fa9a455cf54 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Fri, 5 May 2023 09:53:11 +0200 Subject: [PATCH 42/52] Remove fugly ors --- custom_components/plugwise/number.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index fc857b8b2..a94fb0724 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -48,10 +48,10 @@ class PlugwiseNumberEntityDescription(NumberEntityDescription, PlugwiseNumberMix command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["maximum_boiler_temperature"]["upper_bound"] or 0.0, # type: ignore [index] - native_min_value_fn=lambda data: data["maximum_boiler_temperature"]["lower_bound"] or 0.0, # type: ignore [index] - native_step_key_fn=lambda data: data["maximum_boiler_temperature"]["resolution"] or 0.0, # type: ignore [index] - native_value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"] or 0.0, # type: ignore [index] + native_max_value_fn=lambda data: data["maximum_boiler_temperature"]["upper_bound"], # type: ignore [index] + native_min_value_fn=lambda data: data["maximum_boiler_temperature"]["lower_bound"], # type: ignore [index] + native_step_key_fn=lambda data: data["maximum_boiler_temperature"]["resolution"], # type: ignore [index] + native_value_fn=lambda data: data["maximum_boiler_temperature"]["setpoint"], # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), PlugwiseNumberEntityDescription( @@ -60,10 +60,10 @@ class PlugwiseNumberEntityDescription(NumberEntityDescription, PlugwiseNumberMix command=lambda api, number, value: api.set_number_setpoint(number, value), device_class=NumberDeviceClass.TEMPERATURE, entity_category=EntityCategory.CONFIG, - native_max_value_fn=lambda data: data["max_dhw_temperature"]["upper_bound"] or 0.0, # type: ignore [index] - native_min_value_fn=lambda data: data["max_dhw_temperature"]["lower_bound"] or 0.0, # type: ignore [index] - native_step_key_fn=lambda data: data["max_dhw_temperature"]["resolution"] or 0.0, # type: ignore [index] - native_value_fn=lambda data: data["max_dhw_temperature"]["setpoint"] or 0.0, # type: ignore [index] + native_max_value_fn=lambda data: data["max_dhw_temperature"]["upper_bound"], # type: ignore [index] + native_min_value_fn=lambda data: data["max_dhw_temperature"]["lower_bound"], # type: ignore [index] + native_step_key_fn=lambda data: data["max_dhw_temperature"]["resolution"], # type: ignore [index] + native_value_fn=lambda data: data["max_dhw_temperature"]["setpoint"], # type: ignore [index] native_unit_of_measurement=TEMP_CELSIUS, ), ) From db3e67737fdac093431e128a3f076c1678ca2890 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Fri, 5 May 2023 10:53:33 +0200 Subject: [PATCH 43/52] Fixture newlines --- .../fixtures/adam_multiple_devices_per_zone/all_data.json | 2 +- .../fixtures/adam_multiple_devices_per_zone/notifications.json | 2 +- .../plugwise/fixtures/anna_heatpump_heating/all_data.json | 2 +- .../plugwise/fixtures/anna_heatpump_heating/notifications.json | 2 +- tests/components/plugwise/fixtures/m_adam_cooling/all_data.json | 2 +- .../plugwise/fixtures/m_adam_cooling/notifications.json | 2 +- tests/components/plugwise/fixtures/m_adam_heating/all_data.json | 2 +- .../plugwise/fixtures/m_adam_heating/notifications.json | 2 +- .../plugwise/fixtures/m_anna_heatpump_cooling/all_data.json | 2 +- .../fixtures/m_anna_heatpump_cooling/notifications.json | 2 +- .../plugwise/fixtures/m_anna_heatpump_idle/all_data.json | 2 +- .../plugwise/fixtures/m_anna_heatpump_idle/notifications.json | 2 +- .../components/plugwise/fixtures/p1v3_full_option/all_data.json | 2 +- .../plugwise/fixtures/p1v3_full_option/notifications.json | 2 +- .../components/plugwise/fixtures/p1v4_442_triple/all_data.json | 2 +- .../plugwise/fixtures/p1v4_442_triple/notifications.json | 2 +- tests/components/plugwise/fixtures/stretch_v31/all_data.json | 2 +- .../components/plugwise/fixtures/stretch_v31/notifications.json | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json index 8eb362b1e..ae31f09f3 100644 --- a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json +++ b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json @@ -456,4 +456,4 @@ }, "smile_name": "Adam" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/notifications.json b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/notifications.json index f94bce4ef..8749be4c3 100644 --- a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/notifications.json +++ b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/notifications.json @@ -2,4 +2,4 @@ "af82e4ccf9c548528166d38e560662a4": { "warning": "Node Plug (with MAC address 000D6F000D13CB01, in room 'n.a.') has been unreachable since 23:03 2020-01-18. Please check the connection and restart the device." } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json b/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json index b94971cd1..c7393002f 100644 --- a/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json +++ b/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json @@ -95,4 +95,4 @@ "notifications": {}, "smile_name": "Smile Anna" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/anna_heatpump_heating/notifications.json b/tests/components/plugwise/fixtures/anna_heatpump_heating/notifications.json index 9e26dfeeb..0967ef424 100644 --- a/tests/components/plugwise/fixtures/anna_heatpump_heating/notifications.json +++ b/tests/components/plugwise/fixtures/anna_heatpump_heating/notifications.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json b/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json index ca92fc017..995208b84 100644 --- a/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json @@ -166,4 +166,4 @@ "notifications": {}, "smile_name": "Adam" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/m_adam_cooling/notifications.json b/tests/components/plugwise/fixtures/m_adam_cooling/notifications.json index 9e26dfeeb..0967ef424 100644 --- a/tests/components/plugwise/fixtures/m_adam_cooling/notifications.json +++ b/tests/components/plugwise/fixtures/m_adam_cooling/notifications.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json index 4f3ebaba6..e24fbceae 100644 --- a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json @@ -166,4 +166,4 @@ "notifications": {}, "smile_name": "Adam" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/m_adam_heating/notifications.json b/tests/components/plugwise/fixtures/m_adam_heating/notifications.json index 9e26dfeeb..0967ef424 100644 --- a/tests/components/plugwise/fixtures/m_adam_heating/notifications.json +++ b/tests/components/plugwise/fixtures/m_adam_heating/notifications.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json index 53e4d0538..28c72d64b 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json @@ -98,4 +98,4 @@ "notifications": {}, "smile_name": "Smile Anna" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/notifications.json b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/notifications.json index 9e26dfeeb..0967ef424 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/notifications.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/notifications.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json index 9188a68c8..ffba63bb2 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json @@ -98,4 +98,4 @@ "notifications": {}, "smile_name": "Smile Anna" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/notifications.json b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/notifications.json index 9e26dfeeb..0967ef424 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/notifications.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/notifications.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json b/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json index 67400e2e4..0e0b3c51a 100644 --- a/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json +++ b/tests/components/plugwise/fixtures/p1v3_full_option/all_data.json @@ -45,4 +45,4 @@ "notifications": {}, "smile_name": "Smile P1" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/p1v3_full_option/notifications.json b/tests/components/plugwise/fixtures/p1v3_full_option/notifications.json index 9e26dfeeb..0967ef424 100644 --- a/tests/components/plugwise/fixtures/p1v3_full_option/notifications.json +++ b/tests/components/plugwise/fixtures/p1v3_full_option/notifications.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json b/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json index da05edf29..e9a3b4c68 100644 --- a/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json +++ b/tests/components/plugwise/fixtures/p1v4_442_triple/all_data.json @@ -54,4 +54,4 @@ "notifications": {}, "smile_name": "Smile P1" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json b/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json index 9e26dfeeb..0967ef424 100644 --- a/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json +++ b/tests/components/plugwise/fixtures/p1v4_442_triple/notifications.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tests/components/plugwise/fixtures/stretch_v31/all_data.json b/tests/components/plugwise/fixtures/stretch_v31/all_data.json index 51a636ebd..ccd8fc883 100644 --- a/tests/components/plugwise/fixtures/stretch_v31/all_data.json +++ b/tests/components/plugwise/fixtures/stretch_v31/all_data.json @@ -149,4 +149,4 @@ "notifications": {}, "smile_name": "Stretch" } -} \ No newline at end of file +} diff --git a/tests/components/plugwise/fixtures/stretch_v31/notifications.json b/tests/components/plugwise/fixtures/stretch_v31/notifications.json index 9e26dfeeb..0967ef424 100644 --- a/tests/components/plugwise/fixtures/stretch_v31/notifications.json +++ b/tests/components/plugwise/fixtures/stretch_v31/notifications.json @@ -1 +1 @@ -{} \ No newline at end of file +{} From da09458498ca07dadf58bcc0c57aa55351157efa Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 5 May 2023 18:47:36 +0200 Subject: [PATCH 44/52] Optimize --- custom_components/plugwise/binary_sensor.py | 9 ++++----- custom_components/plugwise/sensor.py | 8 +++----- custom_components/plugwise/switch.py | 5 ++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/custom_components/plugwise/binary_sensor.py b/custom_components/plugwise/binary_sensor.py index 05784030d..0057cb07a 100644 --- a/custom_components/plugwise/binary_sensor.py +++ b/custom_components/plugwise/binary_sensor.py @@ -30,13 +30,11 @@ async def async_setup_entry( entities: list[PlugwiseBinarySensorEntity] = [] for device_id, device in coordinator.data.devices.items(): + if "binary_sensors" not in device: + continue for description in PW_BINARY_SENSOR_TYPES: - if ( - "binary_sensors" not in device - or description.key not in device["binary_sensors"] - ): + if description.key not in device["binary_sensors"]: continue - entities.append( PlugwiseBinarySensorEntity( coordinator, @@ -45,6 +43,7 @@ async def async_setup_entry( ) ) LOGGER.debug("Add %s binary sensor", description.key) + async_add_entities(entities) diff --git a/custom_components/plugwise/sensor.py b/custom_components/plugwise/sensor.py index d74a9b144..e5c24eb6f 100644 --- a/custom_components/plugwise/sensor.py +++ b/custom_components/plugwise/sensor.py @@ -25,13 +25,11 @@ async def async_setup_entry( entities: list[PlugwiseSensorEntity] = [] for device_id, device in coordinator.data.devices.items(): + if "sensors" not in device: + continue for description in PW_SENSOR_TYPES: - if ( - "sensors" not in device - or device["sensors"].get(description.key) is None - ): + if description.key not in device["sensors"]: continue - entities.append( PlugwiseSensorEntity( coordinator, diff --git a/custom_components/plugwise/switch.py b/custom_components/plugwise/switch.py index 596af35d8..172b9d07f 100644 --- a/custom_components/plugwise/switch.py +++ b/custom_components/plugwise/switch.py @@ -25,11 +25,14 @@ async def async_setup_entry( coordinator = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR] entities: list[PlugwiseSwitchEntity] = [] for device_id, device in coordinator.data.devices.items(): + if "switches" not in device: + continue for description in PW_SWITCH_TYPES: - if "switches" not in device or description.key not in device["switches"]: + if description.key not in device["switches"]: continue entities.append(PlugwiseSwitchEntity(coordinator, device_id, description)) LOGGER.debug("Add %s switch", description.key) + async_add_entities(entities) From 538c18b62a6fa119125b796f82e9b81c6a0c950b Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Fri, 5 May 2023 19:04:35 +0200 Subject: [PATCH 45/52] Remove (now) redundant TypeVar) --- custom_components/plugwise/number.py | 11 ++++------- custom_components/plugwise/select.py | 8 +++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index a94fb0724..51f6cfd8a 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -3,7 +3,6 @@ from collections.abc import Awaitable, Callable from dataclasses import dataclass -from typing import TypeVar from homeassistant.components.number import ( NumberDeviceClass, @@ -22,18 +21,16 @@ from .coordinator import PlugwiseDataUpdateCoordinator from .entity import PlugwiseEntity -T = TypeVar("T", bound=DeviceData) - @dataclass class PlugwiseNumberMixin: """Mixin values for Plugwse entities.""" command: Callable[[Smile, str, float], Awaitable[None]] - native_max_value_fn: Callable[[T], float] - native_min_value_fn: Callable[[T], float] - native_step_key_fn: Callable[[T], float] - native_value_fn: Callable[[T], float] + native_max_value_fn: Callable[[DeviceData], float] + native_min_value_fn: Callable[[DeviceData], float] + native_step_key_fn: Callable[[DeviceData], float] + native_value_fn: Callable[[DeviceData], float] @dataclass diff --git a/custom_components/plugwise/select.py b/custom_components/plugwise/select.py index c96b556cb..8d999c9c3 100644 --- a/custom_components/plugwise/select.py +++ b/custom_components/plugwise/select.py @@ -3,7 +3,7 @@ from collections.abc import Awaitable, Callable from dataclasses import dataclass -from typing import Any, TypeVar +from typing import Any from homeassistant.components.select import SelectEntity, SelectEntityDescription from homeassistant.config_entries import ConfigEntry @@ -19,16 +19,14 @@ PARALLEL_UPDATES = 0 -T = TypeVar("T", bound=DeviceData) - @dataclass class PlugwiseSelectDescriptionMixin: """Mixin values for Plugwise Select entities.""" command: Callable[[Smile, str, str], Awaitable[Any]] - value_fn: Callable[[T], str] - values_fn: Callable[[T], list[str]] + value_fn: Callable[[DeviceData], str] + values_fn: Callable[[DeviceData], list[str]] current_option_key: str options_key: str From bdcd35e412c6f21ed81674863ceb860d6ea32cd2 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Fri, 5 May 2023 19:15:42 +0200 Subject: [PATCH 46/52] Re-apply prettier, following plugwise-python PR 312 --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0b566858c..a913169fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -70,7 +70,6 @@ repos: hooks: - id: prettier name: "Verifying/updating code with prettier" - exclude_types: [csv, json] - repo: https://github.com/cdce8p/python-typing-update rev: v0.5.1 hooks: From d5da06432caf4d80d0c972e9f693787d07e77ab0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 5 May 2023 19:06:58 +0000 Subject: [PATCH 47/52] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../all_data.json | 40 +++---------------- .../anna_heatpump_heating/all_data.json | 12 +----- .../fixtures/m_adam_cooling/all_data.json | 28 ++----------- .../fixtures/m_adam_heating/all_data.json | 35 +++------------- .../m_anna_heatpump_cooling/all_data.json | 12 +----- .../m_anna_heatpump_idle/all_data.json | 12 +----- .../fixtures/stretch_v31/all_data.json | 4 +- 7 files changed, 21 insertions(+), 122 deletions(-) diff --git a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json index ae31f09f3..ffc2ca8ab 100644 --- a/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json +++ b/tests/components/plugwise/fixtures/adam_multiple_devices_per_zone/all_data.json @@ -116,13 +116,7 @@ "mode": "auto", "model": "Lisa", "name": "Zone Thermostat Jessie", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "CV Jessie", "sensors": { "battery": 37, @@ -244,13 +238,7 @@ "mode": "auto", "model": "Lisa", "name": "Zone Lisa WK", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "GF7 Woonkamer", "sensors": { "battery": 34, @@ -322,13 +310,7 @@ "mode": "heat", "model": "Lisa", "name": "Zone Lisa Bios", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "None", "sensors": { "battery": 67, @@ -362,13 +344,7 @@ "mode": "heat", "model": "Tom/Floor", "name": "CV Kraan Garage", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "None", "sensors": { "battery": 68, @@ -404,13 +380,7 @@ "mode": "auto", "model": "Lisa", "name": "Zone Thermostat Badkamer", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "Badkamer Schema", "sensors": { "battery": 92, diff --git a/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json b/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json index c7393002f..52d76a5b4 100644 --- a/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json +++ b/tests/components/plugwise/fixtures/anna_heatpump_heating/all_data.json @@ -53,9 +53,7 @@ }, "3cb70739631c4d17a86b8b12e8a5161b": { "active_preset": "home", - "available_schedules": [ - "standaard" - ], + "available_schedules": ["standaard"], "dev_class": "thermostat", "firmware": "2018-02-08T11:15:53+01:00", "hardware": "6539-1301-5002", @@ -64,13 +62,7 @@ "mode": "auto", "model": "ThermoTouch", "name": "Anna", - "preset_modes": [ - "no_frost", - "home", - "away", - "asleep", - "vacation" - ], + "preset_modes": ["no_frost", "home", "away", "asleep", "vacation"], "selected_schedule": "standaard", "sensors": { "cooling_activation_outdoor_temperature": 21.0, diff --git a/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json b/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json index 995208b84..4f7de13d9 100644 --- a/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_cooling/all_data.json @@ -46,11 +46,7 @@ "ad4838d7d35c4d6ea796ee12ae5aedf8": { "active_preset": "asleep", "available": true, - "available_schedules": [ - "Weekschema", - "Badkamer", - "Test" - ], + "available_schedules": ["Weekschema", "Badkamer", "Test"], "control_state": "cooling", "dev_class": "thermostat", "last_used": "Weekschema", @@ -58,13 +54,7 @@ "mode": "heat_cool", "model": "ThermoTouch", "name": "Anna", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "None", "sensors": { "setpoint_high": 23.5, @@ -108,11 +98,7 @@ "e2f4322d57924fa090fbbc48b3a140dc": { "active_preset": "home", "available": true, - "available_schedules": [ - "Weekschema", - "Badkamer", - "Test" - ], + "available_schedules": ["Weekschema", "Badkamer", "Test"], "control_state": "off", "dev_class": "zone_thermostat", "firmware": "2016-10-10T02:00:00+02:00", @@ -122,13 +108,7 @@ "mode": "auto", "model": "Lisa", "name": "Lisa Badkamer", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "Badkamer", "sensors": { "battery": 56, diff --git a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json index e24fbceae..3afb112fb 100644 --- a/tests/components/plugwise/fixtures/m_adam_heating/all_data.json +++ b/tests/components/plugwise/fixtures/m_adam_heating/all_data.json @@ -51,11 +51,7 @@ "ad4838d7d35c4d6ea796ee12ae5aedf8": { "active_preset": "asleep", "available": true, - "available_schedules": [ - "Weekschema", - "Badkamer", - "Test" - ], + "available_schedules": ["Weekschema", "Badkamer", "Test"], "control_state": "heating", "dev_class": "thermostat", "last_used": "Weekschema", @@ -63,13 +59,7 @@ "mode": "heat", "model": "ThermoTouch", "name": "Anna", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "None", "sensors": { "setpoint": 20.0, @@ -95,12 +85,7 @@ "model": "Gateway", "name": "Adam", "regulation_mode": "heating", - "regulation_modes": [ - "heating", - "off", - "bleeding_cold", - "bleeding_hot" - ], + "regulation_modes": ["heating", "off", "bleeding_cold", "bleeding_hot"], "sensors": { "outdoor_temperature": -1.25 }, @@ -110,11 +95,7 @@ "e2f4322d57924fa090fbbc48b3a140dc": { "active_preset": "home", "available": true, - "available_schedules": [ - "Weekschema", - "Badkamer", - "Test" - ], + "available_schedules": ["Weekschema", "Badkamer", "Test"], "control_state": "off", "dev_class": "zone_thermostat", "firmware": "2016-10-10T02:00:00+02:00", @@ -124,13 +105,7 @@ "mode": "auto", "model": "Lisa", "name": "Lisa Badkamer", - "preset_modes": [ - "home", - "asleep", - "away", - "vacation", - "no_frost" - ], + "preset_modes": ["home", "asleep", "away", "vacation", "no_frost"], "selected_schedule": "Badkamer", "sensors": { "battery": 56, diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json index 28c72d64b..52cd5d381 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_cooling/all_data.json @@ -54,9 +54,7 @@ }, "3cb70739631c4d17a86b8b12e8a5161b": { "active_preset": "home", - "available_schedules": [ - "standaard" - ], + "available_schedules": ["standaard"], "dev_class": "thermostat", "firmware": "2018-02-08T11:15:53+01:00", "hardware": "6539-1301-5002", @@ -65,13 +63,7 @@ "mode": "auto", "model": "ThermoTouch", "name": "Anna", - "preset_modes": [ - "no_frost", - "home", - "away", - "asleep", - "vacation" - ], + "preset_modes": ["no_frost", "home", "away", "asleep", "vacation"], "selected_schedule": "standaard", "sensors": { "cooling_activation_outdoor_temperature": 21.0, diff --git a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json index ffba63bb2..e9d9d70d3 100644 --- a/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json +++ b/tests/components/plugwise/fixtures/m_anna_heatpump_idle/all_data.json @@ -54,9 +54,7 @@ }, "3cb70739631c4d17a86b8b12e8a5161b": { "active_preset": "home", - "available_schedules": [ - "standaard" - ], + "available_schedules": ["standaard"], "dev_class": "thermostat", "firmware": "2018-02-08T11:15:53+01:00", "hardware": "6539-1301-5002", @@ -65,13 +63,7 @@ "mode": "auto", "model": "ThermoTouch", "name": "Anna", - "preset_modes": [ - "no_frost", - "home", - "away", - "asleep", - "vacation" - ], + "preset_modes": ["no_frost", "home", "away", "asleep", "vacation"], "selected_schedule": "standaard", "sensors": { "cooling_activation_outdoor_temperature": 25.0, diff --git a/tests/components/plugwise/fixtures/stretch_v31/all_data.json b/tests/components/plugwise/fixtures/stretch_v31/all_data.json index ccd8fc883..c336a9cb9 100644 --- a/tests/components/plugwise/fixtures/stretch_v31/all_data.json +++ b/tests/components/plugwise/fixtures/stretch_v31/all_data.json @@ -50,9 +50,7 @@ }, "71e1944f2a944b26ad73323e399efef0": { "dev_class": "switching", - "members": [ - "5ca521ac179d468e91d772eeeb8a2117" - ], + "members": ["5ca521ac179d468e91d772eeeb8a2117"], "model": "Switchgroup", "name": "Test", "switches": { From ec2f7d9fd3dd0f1b28aa4f4ebf517296db28a0ad Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 6 May 2023 09:00:49 +0200 Subject: [PATCH 48/52] Clean translation files --- .../plugwise/translations/en.json | 19 ------------------- .../plugwise/translations/nl.json | 19 ------------------- 2 files changed, 38 deletions(-) diff --git a/custom_components/plugwise/translations/en.json b/custom_components/plugwise/translations/en.json index 8e2b36ce3..63abaee47 100644 --- a/custom_components/plugwise/translations/en.json +++ b/custom_components/plugwise/translations/en.json @@ -19,13 +19,6 @@ "config": { "step": { "user": { - "title": "Plugwise connection type", - "description": "Please select:", - "data": { - "flow_type": "Connection type" - } - }, - "user_gateway": { "title": "Connect to the Plugwise Adam/Smile/Stretch", "description": "Please enter:", "data": { @@ -34,18 +27,6 @@ "host": "IP-address", "port": "Port number" } - }, - "user_usb": { - "title": "Connect to Plugwise Stick", - "description": "Please enter:", - "data": { - "usb_path": "USB-path" - } - }, - "manual_path": { - "data": { - "usb_path": "USB-path" - } } }, "error": { diff --git a/custom_components/plugwise/translations/nl.json b/custom_components/plugwise/translations/nl.json index e0380491a..9d470756d 100644 --- a/custom_components/plugwise/translations/nl.json +++ b/custom_components/plugwise/translations/nl.json @@ -19,13 +19,6 @@ "config": { "step": { "user": { - "title": "Plugwise connectie-type", - "description": "Selecteer aub:", - "data": { - "flow_type": "Connectie-type" - } - }, - "user_gateway": { "title": "Verbinden met de Plugwise Adam/Smile/Stretch", "description": "Aub invoeren:", "data": { @@ -34,18 +27,6 @@ "host": "IP-adres", "port": "Poortnummer" } - }, - "user_usb": { - "title": "Verbinden met de Plugwise Stick", - "description": "Aub invoeren:", - "data": { - "usb_path": "USB-pad" - } - }, - "manual_path": { - "data": { - "usb_path": "USB-pad" - } } }, "error": { From c50dcafdac33edeed00c2186246ee10b79e002ec Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 6 May 2023 12:38:21 +0200 Subject: [PATCH 49/52] Fix unpractical Plugwise-provided resolutions --- custom_components/plugwise/climate.py | 4 ++-- custom_components/plugwise/number.py | 3 ++- tests/components/plugwise/test_climate.py | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/custom_components/plugwise/climate.py b/custom_components/plugwise/climate.py index f27f6fc76..6f7b8f506 100644 --- a/custom_components/plugwise/climate.py +++ b/custom_components/plugwise/climate.py @@ -95,9 +95,9 @@ def __init__( self._attr_min_temp = self.device["thermostat"]["lower_bound"] self._attr_max_temp = self.device["thermostat"]["upper_bound"] - # Ensure we don't drop below 0.1 + # Fix unpractical resolution provided by Plugwise self._attr_target_temperature_step = max( - self.device["thermostat"]["resolution"], 0.1 + self.device["thermostat"]["resolution"], 0.5 ) @property diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 51f6cfd8a..66d6e552e 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -109,7 +109,8 @@ def __init__( @property def native_step(self) -> float: """Return the setpoint step value.""" - return self.entity_description.native_step_key_fn(self.device) + # Fix unpractical resolution provided by Plugwise + return max(self.entity_description.native_step_key_fn(self.device), 0.5) @property def native_value(self) -> float: diff --git a/tests/components/plugwise/test_climate.py b/tests/components/plugwise/test_climate.py index 881d3fd27..a20830e8c 100644 --- a/tests/components/plugwise/test_climate.py +++ b/tests/components/plugwise/test_climate.py @@ -35,7 +35,7 @@ async def test_adam_climate_entity_attributes( assert state.attributes["temperature"] == 21.5 assert state.attributes["min_temp"] == 0.0 assert state.attributes["max_temp"] == 99.9 - assert state.attributes["target_temp_step"] == 0.1 + assert state.attributes["target_temp_step"] == 0.5 state = hass.states.get("climate.zone_thermostat_jessie") assert state @@ -52,7 +52,7 @@ async def test_adam_climate_entity_attributes( assert state.attributes["temperature"] == 15.0 assert state.attributes["min_temp"] == 0.0 assert state.attributes["max_temp"] == 99.9 - assert state.attributes["target_temp_step"] == 0.1 + assert state.attributes["target_temp_step"] == 0.5 async def test_adam_2_climate_entity_attributes( @@ -200,7 +200,7 @@ async def test_anna_climate_entity_attributes( assert state.attributes["temperature"] == 20.5 assert state.attributes["min_temp"] == 4.0 assert state.attributes["max_temp"] == 30.0 - assert state.attributes["target_temp_step"] == 0.1 + assert state.attributes["target_temp_step"] == 0.5 async def test_anna_2_climate_entity_attributes( From 9c7214c88cd53fe8b39644f0ee4fe0d687edb2d9 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Sat, 6 May 2023 12:42:49 +0200 Subject: [PATCH 50/52] Bump to a3 --- custom_components/plugwise/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/plugwise/manifest.json b/custom_components/plugwise/manifest.json index c5d2b826a..e21991a32 100644 --- a/custom_components/plugwise/manifest.json +++ b/custom_components/plugwise/manifest.json @@ -9,5 +9,5 @@ "iot_class": "local_polling", "loggers": ["plugwise"], "requirements": ["plugwise==0.31.3"], - "version": "0.40.2a2" + "version": "0.40.2a3" } From 78b6976747c14833dccf4dcf2735d820f573b41c Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 15 May 2023 18:20:20 +0200 Subject: [PATCH 51/52] Bump to v0.40.2 release-version --- custom_components/plugwise/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/plugwise/manifest.json b/custom_components/plugwise/manifest.json index e21991a32..1c6cdc27f 100644 --- a/custom_components/plugwise/manifest.json +++ b/custom_components/plugwise/manifest.json @@ -9,5 +9,5 @@ "iot_class": "local_polling", "loggers": ["plugwise"], "requirements": ["plugwise==0.31.3"], - "version": "0.40.2a3" + "version": "0.40.2" } From 7d81678bd0552c5d085c2bd271bc1c2e9da89493 Mon Sep 17 00:00:00 2001 From: Bouwe Date: Mon, 15 May 2023 18:24:06 +0200 Subject: [PATCH 52/52] Update CHANGELOG --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c2947dc5..70038a265 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,11 @@ ## Versions from 0.40 and up -### Ongoing / Unreleased +### 0.40.2 - CI improvements -- Typing improvements +- Implement strict typing, also via [plugwise v0.31.3](https://github.com/plugwise/python-plugwise/releases/tag/v0.31.3) - Dynamic generated fixtures re-introduced -- TODO: rework marked TODOs ### 0.40.1