From 3215c17db93be563e9d7fc0373794055ad4e83a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Diego=20Rodr=C3=ADguez=20Royo?= Date: Sun, 19 Apr 2026 23:09:50 +0000 Subject: [PATCH] Generate devices based on the shades --- .../espsomfy_rts/binary_sensor.py | 6 +++--- custom_components/espsomfy_rts/cover.py | 8 ++++---- custom_components/espsomfy_rts/entity.py | 20 +++++++++++++++++++ custom_components/espsomfy_rts/switch.py | 6 +++--- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/custom_components/espsomfy_rts/binary_sensor.py b/custom_components/espsomfy_rts/binary_sensor.py index 36368f0..356def8 100644 --- a/custom_components/espsomfy_rts/binary_sensor.py +++ b/custom_components/espsomfy_rts/binary_sensor.py @@ -9,7 +9,7 @@ from .const import DOMAIN, EVT_CONNECTED, EVT_GROUPSTATE, EVT_SHADESTATE from .controller import ESPSomfyController -from .entity import ESPSomfyEntity +from .entity import ESPSomfyShadeEntity async def async_setup_entry( @@ -54,7 +54,7 @@ async def async_setup_entry( async_add_entities(new_entities) -class ESPSomfySunSensor(ESPSomfyEntity, BinarySensorEntity): +class ESPSomfySunSensor(ESPSomfyShadeEntity, BinarySensorEntity): """A sun flag sensor indicating whether there is sun.""" def __init__(self, controller: ESPSomfyController, data) -> None: @@ -123,7 +123,7 @@ def available(self) -> bool: return self._available -class ESPSomfyWindSensor(ESPSomfyEntity, BinarySensorEntity): +class ESPSomfyWindSensor(ESPSomfyShadeEntity, BinarySensorEntity): """A sun flag sensor indicating whether there is sun.""" def __init__(self, controller: ESPSomfyController, data) -> None: diff --git a/custom_components/espsomfy_rts/cover.py b/custom_components/espsomfy_rts/cover.py index cfebaf7..57428ee 100644 --- a/custom_components/espsomfy_rts/cover.py +++ b/custom_components/espsomfy_rts/cover.py @@ -32,7 +32,7 @@ EVT_SHADESTATE, ) from .controller import ESPSomfyController -from .entity import ESPSomfyEntity +from .entity import ESPSomfyShadeEntity SVC_OPEN_SHADE = "open_shade" SVC_CLOSE_SHADE = "close_shade" @@ -183,14 +183,14 @@ async def async_setup_entry( ) -class ESPSomfyGroup(CoverGroup, ESPSomfyEntity): +class ESPSomfyGroup(CoverGroup, ESPSomfyShadeEntity): """A grpi[] that is associated with a controller.""" def __init__( self, hass: HomeAssistant, controller: ESPSomfyController, data ) -> None: """Initialize a group.""" - ESPSomfyEntity.__init__(self=self, controller=controller, data=data) + ESPSomfyShadeEntity.__init__(self=self, controller=controller, data=data) self._hass = hass self._attr_available = True self._controller = controller @@ -342,7 +342,7 @@ async def async_send_step_command(self, **kwargs: Any) -> None: await self._controller.api.group_command(cmd) -class ESPSomfyShade(ESPSomfyEntity, CoverEntity): +class ESPSomfyShade(ESPSomfyShadeEntity, CoverEntity): """A shade that is associated with a controller.""" def __init__(self, controller: ESPSomfyController, data) -> None: diff --git a/custom_components/espsomfy_rts/entity.py b/custom_components/espsomfy_rts/entity.py index 2154621..83aff00 100644 --- a/custom_components/espsomfy_rts/entity.py +++ b/custom_components/espsomfy_rts/entity.py @@ -34,3 +34,23 @@ def device_info(self) -> DeviceInfo | None: sw_version=self.controller.version, hw_version=None, ) + + +class ESPSomfyShadeEntity(ESPSomfyEntity): + """Base entity for ESPSomfy shades.""" + + def __init__(self, *, data: any, controller: ESPSomfyController) -> None: + """Initialize the entity.""" + super().__init__(data=data, controller=controller) + self._data = data + + @property + def device_info(self) -> DeviceInfo | None: + """Device info.""" + return DeviceInfo( + configuration_url=self.controller.api.get_config_url(), + identifiers={ + (DOMAIN, f"{self.controller.unique_id}_shade_{self._data['shadeId']}"), + }, + name=self._data["name"], + ) diff --git a/custom_components/espsomfy_rts/switch.py b/custom_components/espsomfy_rts/switch.py index 30c4f39..0374132 100644 --- a/custom_components/espsomfy_rts/switch.py +++ b/custom_components/espsomfy_rts/switch.py @@ -11,7 +11,7 @@ from .const import DOMAIN, EVT_CONNECTED, EVT_GROUPSTATE, EVT_SHADESTATE from .controller import ESPSomfyController -from .entity import ESPSomfyEntity +from .entity import ESPSomfyShadeEntity async def async_setup_entry( @@ -60,7 +60,7 @@ async def async_setup_entry( async_add_entities(new_entities) -class ESPSomfySunSwitch(ESPSomfyEntity, SwitchEntity): +class ESPSomfySunSwitch(ESPSomfyShadeEntity, SwitchEntity): """A sun flag switch for toggling sun mode.""" def __init__(self, controller: ESPSomfyController, data) -> None: @@ -145,7 +145,7 @@ def available(self) -> bool: return self._available -class ESPSomfyBinarySwitch(ESPSomfyEntity, SwitchEntity): +class ESPSomfyBinarySwitch(ESPSomfyShadeEntity, SwitchEntity): """A binary switch for toggling a dry contact.""" def __init__(self, controller: ESPSomfyController, data) -> None: