From 94ee9bf8d90f3854a2cd74b88606460ea5d45bfc Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Fri, 24 Dec 2021 09:42:28 +0000 Subject: [PATCH 1/7] Address late feedback --- homeassistant/components/overkiz/button.py | 22 ++++++++-------- homeassistant/components/overkiz/sensor.py | 30 ++++++++++++---------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/overkiz/button.py b/homeassistant/components/overkiz/button.py index 85e7ea8c61303..7a2c0b0448ced 100644 --- a/homeassistant/components/overkiz/button.py +++ b/homeassistant/components/overkiz/button.py @@ -57,18 +57,20 @@ async def async_setup_entry( for device in data.coordinator.data.values(): if ( - device.widget not in IGNORED_OVERKIZ_DEVICES - and device.ui_class not in IGNORED_OVERKIZ_DEVICES + device.widget in IGNORED_OVERKIZ_DEVICES + or device.ui_class in IGNORED_OVERKIZ_DEVICES ): - for command in device.definition.commands: - if description := supported_commands.get(command.command_name): - entities.append( - OverkizButton( - device.device_url, - data.coordinator, - description, - ) + continue + + for command in device.definition.commands: + if description := supported_commands.get(command.command_name): + entities.append( + OverkizButton( + device.device_url, + data.coordinator, + description, ) + ) async_add_entities(entities) diff --git a/homeassistant/components/overkiz/sensor.py b/homeassistant/components/overkiz/sensor.py index a00587328b825..5e6d19e018f4f 100644 --- a/homeassistant/components/overkiz/sensor.py +++ b/homeassistant/components/overkiz/sensor.py @@ -347,20 +347,6 @@ async def async_setup_entry( } for device in data.coordinator.data.values(): - if ( - device.widget not in IGNORED_OVERKIZ_DEVICES - and device.ui_class not in IGNORED_OVERKIZ_DEVICES - ): - for state in device.definition.states: - if description := key_supported_states.get(state.qualified_name): - entities.append( - OverkizStateSensor( - device.device_url, - data.coordinator, - description, - ) - ) - if device.widget == UIWidget.HOMEKIT_STACK: entities.append( OverkizHomeKitSetupCodeSensor( @@ -369,6 +355,22 @@ async def async_setup_entry( ) ) + if ( + device.widget in IGNORED_OVERKIZ_DEVICES + or device.ui_class in IGNORED_OVERKIZ_DEVICES + ): + continue + + for state in device.definition.states: + if description := key_supported_states.get(state.qualified_name): + entities.append( + OverkizStateSensor( + device.device_url, + data.coordinator, + description, + ) + ) + async_add_entities(entities) From 776676233be75df360421abae84c712a7b48a21b Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Fri, 24 Dec 2021 10:06:53 +0000 Subject: [PATCH 2/7] Add number entity --- homeassistant/components/overkiz/entity.py | 17 ++++- homeassistant/components/overkiz/number.py | 86 ++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/overkiz/number.py diff --git a/homeassistant/components/overkiz/entity.py b/homeassistant/components/overkiz/entity.py index 0c931bc598594..53d3c2211ce79 100644 --- a/homeassistant/components/overkiz/entity.py +++ b/homeassistant/components/overkiz/entity.py @@ -8,6 +8,7 @@ from pyoverkiz.models import Device from homeassistant.components.button import ButtonEntityDescription +from homeassistant.components.number import NumberEntityDescription from homeassistant.components.sensor import SensorEntityDescription from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -93,6 +94,18 @@ class OverkizSensorDescription(SensorEntityDescription): ] | None = lambda val: val +@dataclass +class OverkizNumberDescriptionMixin: + """Define an entity description mixin for number entities.""" + + command: str + + +@dataclass +class OverkizNumberDescription(NumberEntityDescription, OverkizNumberDescriptionMixin): + """Class to describe an Overkiz number.""" + + class OverkizDescriptiveEntity(OverkizEntity): """Representation of a Overkiz device entity based on a description.""" @@ -100,7 +113,9 @@ def __init__( self, device_url: str, coordinator: OverkizDataUpdateCoordinator, - description: OverkizSensorDescription | ButtonEntityDescription, + description: OverkizSensorDescription + | ButtonEntityDescription + | OverkizNumberDescription, ) -> None: """Initialize the device.""" super().__init__(device_url, coordinator) diff --git a/homeassistant/components/overkiz/number.py b/homeassistant/components/overkiz/number.py new file mode 100644 index 0000000000000..c699eb6a9ec88 --- /dev/null +++ b/homeassistant/components/overkiz/number.py @@ -0,0 +1,86 @@ +"""Support for Overkiz (virtual) numbers.""" +from __future__ import annotations + +from pyoverkiz.enums import OverkizCommand, OverkizState + +from homeassistant.components.number import NumberEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import EntityCategory +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from . import HomeAssistantOverkizData +from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES +from .entity import OverkizDescriptiveEntity, OverkizNumberDescription + +NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [ + # Cover: My Position (0 - 100) + OverkizNumberDescription( + key=OverkizState.CORE_MEMORIZED_1_POSITION, + name="My Position", + icon="mdi:content-save-cog", + command=OverkizCommand.SET_MEMORIZED_1_POSITION, + entity_category=EntityCategory.CONFIG, + ), + # WaterHeater: Expected Number Of Shower (2 - 4) + OverkizNumberDescription( + key=OverkizState.CORE_EXPECTED_NUMBER_OF_SHOWER, + name="Expected Number Of Shower", + icon="mdi:shower-head", + command=OverkizCommand.SET_EXPECTED_NUMBER_OF_SHOWER, + min_value=2, + max_value=4, + entity_category=EntityCategory.CONFIG, + ), +] + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +): + """Set up the Overkiz number from a config entry.""" + data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id] + entities: list[OverkizNumber] = [] + + key_supported_states = { + description.key: description for description in NUMBER_DESCRIPTIONS + } + + for device in data.coordinator.data.values(): + if ( + device.widget in IGNORED_OVERKIZ_DEVICES + or device.ui_class in IGNORED_OVERKIZ_DEVICES + ): + continue + + for state in device.definition.states: + if description := key_supported_states.get(state.qualified_name): + entities.append( + OverkizNumber( + device.device_url, + data.coordinator, + description, + ) + ) + + async_add_entities(entities) + + +class OverkizNumber(OverkizDescriptiveEntity, NumberEntity): + """Representation of an Overkiz Number.""" + + @property + def value(self) -> float: + """Return the entity value to represent the entity state.""" + if state := self.device.states.get(self.entity_description.key): + return state.value + + return 0 + + async def async_set_value(self, value: float) -> None: + """Set new value.""" + await self.executor.async_execute_command( + self.entity_description.command, value + ) From 72c1d4bff86a850b77061311625f648e485f69fe Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Fri, 24 Dec 2021 10:14:03 +0000 Subject: [PATCH 3/7] Add number entity to const --- homeassistant/components/overkiz/const.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/overkiz/const.py b/homeassistant/components/overkiz/const.py index 60591d9d7615b..f1d1d0fdb7438 100644 --- a/homeassistant/components/overkiz/const.py +++ b/homeassistant/components/overkiz/const.py @@ -20,6 +20,7 @@ PLATFORMS: list[Platform] = [ Platform.BUTTON, Platform.LOCK, + Platform.NUMBER, Platform.SENSOR, ] From 91daacfc0adefe7a5d25991ef14aaa489737445a Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Fri, 24 Dec 2021 10:22:51 +0000 Subject: [PATCH 4/7] Override type hint --- homeassistant/components/overkiz/number.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/overkiz/number.py b/homeassistant/components/overkiz/number.py index c699eb6a9ec88..5bf1d75385b28 100644 --- a/homeassistant/components/overkiz/number.py +++ b/homeassistant/components/overkiz/number.py @@ -71,6 +71,8 @@ async def async_setup_entry( class OverkizNumber(OverkizDescriptiveEntity, NumberEntity): """Representation of an Overkiz Number.""" + entity_description: OverkizNumberDescription + @property def value(self) -> float: """Return the entity value to represent the entity state.""" From ebd139f3cf7862dfb63a284738fe9100b80d8bba Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Fri, 24 Dec 2021 10:28:31 +0000 Subject: [PATCH 5/7] Exclude from codecoverage --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index 48c8425eed864..2113ea0c2022e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -808,6 +808,7 @@ omit = homeassistant/components/overkiz/entity.py homeassistant/components/overkiz/executor.py homeassistant/components/overkiz/lock.py + homeassistant/components/overkiz/number.py homeassistant/components/overkiz/sensor.py homeassistant/components/ovo_energy/__init__.py homeassistant/components/ovo_energy/const.py From 5d6ca57201f6d8f9e259dd499e19b4fa917ea493 Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Fri, 24 Dec 2021 12:20:51 +0000 Subject: [PATCH 6/7] Revert "Address late feedback" This reverts commit 94ee9bf8d90f3854a2cd74b88606460ea5d45bfc. --- homeassistant/components/overkiz/button.py | 22 ++++++++-------- homeassistant/components/overkiz/sensor.py | 30 ++++++++++------------ 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/overkiz/button.py b/homeassistant/components/overkiz/button.py index 7a2c0b0448ced..85e7ea8c61303 100644 --- a/homeassistant/components/overkiz/button.py +++ b/homeassistant/components/overkiz/button.py @@ -57,20 +57,18 @@ async def async_setup_entry( for device in data.coordinator.data.values(): if ( - device.widget in IGNORED_OVERKIZ_DEVICES - or device.ui_class in IGNORED_OVERKIZ_DEVICES + device.widget not in IGNORED_OVERKIZ_DEVICES + and device.ui_class not in IGNORED_OVERKIZ_DEVICES ): - continue - - for command in device.definition.commands: - if description := supported_commands.get(command.command_name): - entities.append( - OverkizButton( - device.device_url, - data.coordinator, - description, + for command in device.definition.commands: + if description := supported_commands.get(command.command_name): + entities.append( + OverkizButton( + device.device_url, + data.coordinator, + description, + ) ) - ) async_add_entities(entities) diff --git a/homeassistant/components/overkiz/sensor.py b/homeassistant/components/overkiz/sensor.py index 5e6d19e018f4f..a00587328b825 100644 --- a/homeassistant/components/overkiz/sensor.py +++ b/homeassistant/components/overkiz/sensor.py @@ -347,6 +347,20 @@ async def async_setup_entry( } for device in data.coordinator.data.values(): + if ( + device.widget not in IGNORED_OVERKIZ_DEVICES + and device.ui_class not in IGNORED_OVERKIZ_DEVICES + ): + for state in device.definition.states: + if description := key_supported_states.get(state.qualified_name): + entities.append( + OverkizStateSensor( + device.device_url, + data.coordinator, + description, + ) + ) + if device.widget == UIWidget.HOMEKIT_STACK: entities.append( OverkizHomeKitSetupCodeSensor( @@ -355,22 +369,6 @@ async def async_setup_entry( ) ) - if ( - device.widget in IGNORED_OVERKIZ_DEVICES - or device.ui_class in IGNORED_OVERKIZ_DEVICES - ): - continue - - for state in device.definition.states: - if description := key_supported_states.get(state.qualified_name): - entities.append( - OverkizStateSensor( - device.device_url, - data.coordinator, - description, - ) - ) - async_add_entities(entities) From d8d7d3f020ed59e89dba34cd96389ae6cb51434a Mon Sep 17 00:00:00 2001 From: Mick Vleeshouwer Date: Fri, 24 Dec 2021 12:22:31 +0000 Subject: [PATCH 7/7] Address feedback --- homeassistant/components/overkiz/entity.py | 20 ++------------------ homeassistant/components/overkiz/number.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/overkiz/entity.py b/homeassistant/components/overkiz/entity.py index 53d3c2211ce79..b88417b0d2b97 100644 --- a/homeassistant/components/overkiz/entity.py +++ b/homeassistant/components/overkiz/entity.py @@ -7,10 +7,8 @@ from pyoverkiz.enums import OverkizAttribute, OverkizState from pyoverkiz.models import Device -from homeassistant.components.button import ButtonEntityDescription -from homeassistant.components.number import NumberEntityDescription from homeassistant.components.sensor import SensorEntityDescription -from homeassistant.helpers.entity import DeviceInfo +from homeassistant.helpers.entity import DeviceInfo, EntityDescription from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN @@ -94,18 +92,6 @@ class OverkizSensorDescription(SensorEntityDescription): ] | None = lambda val: val -@dataclass -class OverkizNumberDescriptionMixin: - """Define an entity description mixin for number entities.""" - - command: str - - -@dataclass -class OverkizNumberDescription(NumberEntityDescription, OverkizNumberDescriptionMixin): - """Class to describe an Overkiz number.""" - - class OverkizDescriptiveEntity(OverkizEntity): """Representation of a Overkiz device entity based on a description.""" @@ -113,9 +99,7 @@ def __init__( self, device_url: str, coordinator: OverkizDataUpdateCoordinator, - description: OverkizSensorDescription - | ButtonEntityDescription - | OverkizNumberDescription, + description: EntityDescription, ) -> None: """Initialize the device.""" super().__init__(device_url, coordinator) diff --git a/homeassistant/components/overkiz/number.py b/homeassistant/components/overkiz/number.py index 5bf1d75385b28..d13370207faa7 100644 --- a/homeassistant/components/overkiz/number.py +++ b/homeassistant/components/overkiz/number.py @@ -1,9 +1,11 @@ """Support for Overkiz (virtual) numbers.""" from __future__ import annotations +from dataclasses import dataclass + from pyoverkiz.enums import OverkizCommand, OverkizState -from homeassistant.components.number import NumberEntity +from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory @@ -11,7 +13,20 @@ from . import HomeAssistantOverkizData from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES -from .entity import OverkizDescriptiveEntity, OverkizNumberDescription +from .entity import OverkizDescriptiveEntity + + +@dataclass +class OverkizNumberDescriptionMixin: + """Define an entity description mixin for number entities.""" + + command: str + + +@dataclass +class OverkizNumberDescription(NumberEntityDescription, OverkizNumberDescriptionMixin): + """Class to describe an Overkiz number.""" + NUMBER_DESCRIPTIONS: list[OverkizNumberDescription] = [ # Cover: My Position (0 - 100)