Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions custom_components/espsomfy_rts/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions custom_components/espsomfy_rts/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions custom_components/espsomfy_rts/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
6 changes: 3 additions & 3 deletions custom_components/espsomfy_rts/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down