mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Introduce common base entity for Comelit bridge (#142855)
This commit is contained in:
parent
0a424f53b1
commit
9e93d1fd7e
@ -83,7 +83,6 @@ class ComelitAlarmEntity(CoordinatorEntity[ComelitVedoSystem], AlarmControlPanel
|
|||||||
config_entry_entry_id: str,
|
config_entry_entry_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the alarm panel."""
|
"""Initialize the alarm panel."""
|
||||||
self._api = coordinator.api
|
|
||||||
self._area_index = area.index
|
self._area_index = area.index
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
# Use config_entry.entry_id as base for unique_id
|
# Use config_entry.entry_id as base for unique_id
|
||||||
@ -137,30 +136,38 @@ class ComelitAlarmEntity(CoordinatorEntity[ComelitVedoSystem], AlarmControlPanel
|
|||||||
|
|
||||||
async def async_alarm_disarm(self, code: str | None = None) -> None:
|
async def async_alarm_disarm(self, code: str | None = None) -> None:
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
if code != str(self._api.device_pin):
|
if code != str(self.coordinator.api.device_pin):
|
||||||
return
|
return
|
||||||
await self._api.set_zone_status(self._area.index, ALARM_ACTIONS[DISABLE])
|
await self.coordinator.api.set_zone_status(
|
||||||
|
self._area.index, ALARM_ACTIONS[DISABLE]
|
||||||
|
)
|
||||||
await self._async_update_state(
|
await self._async_update_state(
|
||||||
AlarmAreaState.DISARMED, ALARM_AREA_ARMED_STATUS[DISABLE]
|
AlarmAreaState.DISARMED, ALARM_AREA_ARMED_STATUS[DISABLE]
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_alarm_arm_away(self, code: str | None = None) -> None:
|
async def async_alarm_arm_away(self, code: str | None = None) -> None:
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
await self._api.set_zone_status(self._area.index, ALARM_ACTIONS[AWAY])
|
await self.coordinator.api.set_zone_status(
|
||||||
|
self._area.index, ALARM_ACTIONS[AWAY]
|
||||||
|
)
|
||||||
await self._async_update_state(
|
await self._async_update_state(
|
||||||
AlarmAreaState.ARMED, ALARM_AREA_ARMED_STATUS[AWAY]
|
AlarmAreaState.ARMED, ALARM_AREA_ARMED_STATUS[AWAY]
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_alarm_arm_home(self, code: str | None = None) -> None:
|
async def async_alarm_arm_home(self, code: str | None = None) -> None:
|
||||||
"""Send arm home command."""
|
"""Send arm home command."""
|
||||||
await self._api.set_zone_status(self._area.index, ALARM_ACTIONS[HOME])
|
await self.coordinator.api.set_zone_status(
|
||||||
|
self._area.index, ALARM_ACTIONS[HOME]
|
||||||
|
)
|
||||||
await self._async_update_state(
|
await self._async_update_state(
|
||||||
AlarmAreaState.ARMED, ALARM_AREA_ARMED_STATUS[HOME_P1]
|
AlarmAreaState.ARMED, ALARM_AREA_ARMED_STATUS[HOME_P1]
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_alarm_arm_night(self, code: str | None = None) -> None:
|
async def async_alarm_arm_night(self, code: str | None = None) -> None:
|
||||||
"""Send arm night command."""
|
"""Send arm night command."""
|
||||||
await self._api.set_zone_status(self._area.index, ALARM_ACTIONS[NIGHT])
|
await self.coordinator.api.set_zone_status(
|
||||||
|
self._area.index, ALARM_ACTIONS[NIGHT]
|
||||||
|
)
|
||||||
await self._async_update_state(
|
await self._async_update_state(
|
||||||
AlarmAreaState.ARMED, ALARM_AREA_ARMED_STATUS[NIGHT]
|
AlarmAreaState.ARMED, ALARM_AREA_ARMED_STATUS[NIGHT]
|
||||||
)
|
)
|
||||||
|
@ -50,7 +50,6 @@ class ComelitVedoBinarySensorEntity(
|
|||||||
config_entry_entry_id: str,
|
config_entry_entry_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init sensor entity."""
|
"""Init sensor entity."""
|
||||||
self._api = coordinator.api
|
|
||||||
self._zone_index = zone.index
|
self._zone_index = zone.index
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
# Use config_entry.entry_id as base for unique_id
|
# Use config_entry.entry_id as base for unique_id
|
||||||
|
@ -19,10 +19,10 @@ from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
||||||
|
from .entity import ComelitBridgeBaseEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
@ -89,7 +89,7 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ComelitClimateEntity(CoordinatorEntity[ComelitSerialBridge], ClimateEntity):
|
class ComelitClimateEntity(ComelitBridgeBaseEntity, ClimateEntity):
|
||||||
"""Climate device."""
|
"""Climate device."""
|
||||||
|
|
||||||
_attr_hvac_modes = [HVACMode.AUTO, HVACMode.COOL, HVACMode.HEAT, HVACMode.OFF]
|
_attr_hvac_modes = [HVACMode.AUTO, HVACMode.COOL, HVACMode.HEAT, HVACMode.OFF]
|
||||||
@ -102,7 +102,6 @@ class ComelitClimateEntity(CoordinatorEntity[ComelitSerialBridge], ClimateEntity
|
|||||||
)
|
)
|
||||||
_attr_target_temperature_step = PRECISION_TENTHS
|
_attr_target_temperature_step = PRECISION_TENTHS
|
||||||
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -112,13 +111,7 @@ class ComelitClimateEntity(CoordinatorEntity[ComelitSerialBridge], ClimateEntity
|
|||||||
config_entry_entry_id: str,
|
config_entry_entry_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init light entity."""
|
"""Init light entity."""
|
||||||
self._api = coordinator.api
|
super().__init__(coordinator, device, config_entry_entry_id)
|
||||||
self._device = device
|
|
||||||
super().__init__(coordinator)
|
|
||||||
# Use config_entry.entry_id as base for unique_id
|
|
||||||
# because no serial number or mac is available
|
|
||||||
self._attr_unique_id = f"{config_entry_entry_id}-{device.index}"
|
|
||||||
self._attr_device_info = coordinator.platform_device_info(device, device.type)
|
|
||||||
self._update_attributes()
|
self._update_attributes()
|
||||||
|
|
||||||
def _update_attributes(self) -> None:
|
def _update_attributes(self) -> None:
|
||||||
|
@ -11,9 +11,9 @@ from homeassistant.components.cover import CoverDeviceClass, CoverEntity, CoverS
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
|
|
||||||
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
||||||
|
from .entity import ComelitBridgeBaseEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
@ -34,13 +34,10 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ComelitCoverEntity(
|
class ComelitCoverEntity(ComelitBridgeBaseEntity, RestoreEntity, CoverEntity):
|
||||||
CoordinatorEntity[ComelitSerialBridge], RestoreEntity, CoverEntity
|
|
||||||
):
|
|
||||||
"""Cover device."""
|
"""Cover device."""
|
||||||
|
|
||||||
_attr_device_class = CoverDeviceClass.SHUTTER
|
_attr_device_class = CoverDeviceClass.SHUTTER
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -50,13 +47,7 @@ class ComelitCoverEntity(
|
|||||||
config_entry_entry_id: str,
|
config_entry_entry_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init cover entity."""
|
"""Init cover entity."""
|
||||||
self._api = coordinator.api
|
super().__init__(coordinator, device, config_entry_entry_id)
|
||||||
self._device = device
|
|
||||||
super().__init__(coordinator)
|
|
||||||
# Use config_entry.entry_id as base for unique_id
|
|
||||||
# because no serial number or mac is available
|
|
||||||
self._attr_unique_id = f"{config_entry_entry_id}-{device.index}"
|
|
||||||
self._attr_device_info = coordinator.platform_device_info(device, device.type)
|
|
||||||
# Device doesn't provide a status so we assume UNKNOWN at first startup
|
# Device doesn't provide a status so we assume UNKNOWN at first startup
|
||||||
self._last_action: int | None = None
|
self._last_action: int | None = None
|
||||||
self._last_state: str | None = None
|
self._last_state: str | None = None
|
||||||
@ -101,7 +92,7 @@ class ComelitCoverEntity(
|
|||||||
async def _cover_set_state(self, action: int, state: int) -> None:
|
async def _cover_set_state(self, action: int, state: int) -> None:
|
||||||
"""Set desired cover state."""
|
"""Set desired cover state."""
|
||||||
self._last_state = self.state
|
self._last_state = self.state
|
||||||
await self._api.set_device_status(COVER, self._device.index, action)
|
await self.coordinator.api.set_device_status(COVER, self._device.index, action)
|
||||||
self.coordinator.data[COVER][self._device.index].status = state
|
self.coordinator.data[COVER][self._device.index].status = state
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
29
homeassistant/components/comelit/entity.py
Normal file
29
homeassistant/components/comelit/entity.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""Base entity for Comelit."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from aiocomelit import ComelitSerialBridgeObject
|
||||||
|
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .coordinator import ComelitSerialBridge
|
||||||
|
|
||||||
|
|
||||||
|
class ComelitBridgeBaseEntity(CoordinatorEntity[ComelitSerialBridge]):
|
||||||
|
"""Comelit Bridge base entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: ComelitSerialBridge,
|
||||||
|
device: ComelitSerialBridgeObject,
|
||||||
|
config_entry_entry_id: str,
|
||||||
|
) -> None:
|
||||||
|
"""Init cover entity."""
|
||||||
|
self._device = device
|
||||||
|
super().__init__(coordinator)
|
||||||
|
# Use config_entry.entry_id as base for unique_id
|
||||||
|
# because no serial number or mac is available
|
||||||
|
self._attr_unique_id = f"{config_entry_entry_id}-{device.index}"
|
||||||
|
self._attr_device_info = coordinator.platform_device_info(device, device.type)
|
@ -19,10 +19,10 @@ from homeassistant.components.humidifier import (
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
||||||
|
from .entity import ComelitBridgeBaseEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
@ -92,14 +92,13 @@ async def async_setup_entry(
|
|||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class ComelitHumidifierEntity(CoordinatorEntity[ComelitSerialBridge], HumidifierEntity):
|
class ComelitHumidifierEntity(ComelitBridgeBaseEntity, HumidifierEntity):
|
||||||
"""Humidifier device."""
|
"""Humidifier device."""
|
||||||
|
|
||||||
_attr_supported_features = HumidifierEntityFeature.MODES
|
_attr_supported_features = HumidifierEntityFeature.MODES
|
||||||
_attr_available_modes = [MODE_NORMAL, MODE_AUTO]
|
_attr_available_modes = [MODE_NORMAL, MODE_AUTO]
|
||||||
_attr_min_humidity = 10
|
_attr_min_humidity = 10
|
||||||
_attr_max_humidity = 90
|
_attr_max_humidity = 90
|
||||||
_attr_has_entity_name = True
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -112,13 +111,8 @@ class ComelitHumidifierEntity(CoordinatorEntity[ComelitSerialBridge], Humidifier
|
|||||||
device_class: HumidifierDeviceClass,
|
device_class: HumidifierDeviceClass,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init light entity."""
|
"""Init light entity."""
|
||||||
self._api = coordinator.api
|
super().__init__(coordinator, device, config_entry_entry_id)
|
||||||
self._device = device
|
|
||||||
super().__init__(coordinator)
|
|
||||||
# Use config_entry.entry_id as base for unique_id
|
|
||||||
# because no serial number or mac is available
|
|
||||||
self._attr_unique_id = f"{config_entry_entry_id}-{device.index}-{device_class}"
|
self._attr_unique_id = f"{config_entry_entry_id}-{device.index}-{device_class}"
|
||||||
self._attr_device_info = coordinator.platform_device_info(device, device_class)
|
|
||||||
self._attr_device_class = device_class
|
self._attr_device_class = device_class
|
||||||
self._attr_translation_key = device_class.value
|
self._attr_translation_key = device_class.value
|
||||||
self._active_mode = active_mode
|
self._active_mode = active_mode
|
||||||
|
@ -4,15 +4,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from aiocomelit import ComelitSerialBridgeObject
|
|
||||||
from aiocomelit.const import LIGHT, STATE_OFF, STATE_ON
|
from aiocomelit.const import LIGHT, STATE_OFF, STATE_ON
|
||||||
|
|
||||||
from homeassistant.components.light import ColorMode, LightEntity
|
from homeassistant.components.light import ColorMode, LightEntity
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
|
|
||||||
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
||||||
|
from .entity import ComelitBridgeBaseEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
@ -33,29 +32,13 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ComelitLightEntity(CoordinatorEntity[ComelitSerialBridge], LightEntity):
|
class ComelitLightEntity(ComelitBridgeBaseEntity, LightEntity):
|
||||||
"""Light device."""
|
"""Light device."""
|
||||||
|
|
||||||
_attr_color_mode = ColorMode.ONOFF
|
_attr_color_mode = ColorMode.ONOFF
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
_attr_supported_color_modes = {ColorMode.ONOFF}
|
_attr_supported_color_modes = {ColorMode.ONOFF}
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
coordinator: ComelitSerialBridge,
|
|
||||||
device: ComelitSerialBridgeObject,
|
|
||||||
config_entry_entry_id: str,
|
|
||||||
) -> None:
|
|
||||||
"""Init light entity."""
|
|
||||||
self._api = coordinator.api
|
|
||||||
self._device = device
|
|
||||||
super().__init__(coordinator)
|
|
||||||
# Use config_entry.entry_id as base for unique_id
|
|
||||||
# because no serial number or mac is available
|
|
||||||
self._attr_unique_id = f"{config_entry_entry_id}-{device.index}"
|
|
||||||
self._attr_device_info = coordinator.platform_device_info(device, device.type)
|
|
||||||
|
|
||||||
async def _light_set_state(self, state: int) -> None:
|
async def _light_set_state(self, state: int) -> None:
|
||||||
"""Set desired light state."""
|
"""Set desired light state."""
|
||||||
await self.coordinator.api.set_device_status(LIGHT, self._device.index, state)
|
await self.coordinator.api.set_device_status(LIGHT, self._device.index, state)
|
||||||
|
@ -7,5 +7,6 @@
|
|||||||
"integration_type": "hub",
|
"integration_type": "hub",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["aiocomelit"],
|
"loggers": ["aiocomelit"],
|
||||||
|
"quality_scale": "bronze",
|
||||||
"requirements": ["aiocomelit==0.11.3"]
|
"requirements": ["aiocomelit==0.11.3"]
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,7 @@ rules:
|
|||||||
comment: no actions
|
comment: no actions
|
||||||
appropriate-polling: done
|
appropriate-polling: done
|
||||||
brands: done
|
brands: done
|
||||||
common-modules:
|
common-modules: done
|
||||||
status: todo
|
|
||||||
comment: PR in progress
|
|
||||||
config-flow-test-coverage: done
|
config-flow-test-coverage: done
|
||||||
config-flow: done
|
config-flow: done
|
||||||
dependency-transparency: done
|
dependency-transparency: done
|
||||||
|
@ -19,6 +19,7 @@ from homeassistant.helpers.typing import StateType
|
|||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .coordinator import ComelitConfigEntry, ComelitSerialBridge, ComelitVedoSystem
|
from .coordinator import ComelitConfigEntry, ComelitSerialBridge, ComelitVedoSystem
|
||||||
|
from .entity import ComelitBridgeBaseEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
@ -95,10 +96,9 @@ async def async_setup_vedo_entry(
|
|||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class ComelitBridgeSensorEntity(CoordinatorEntity[ComelitSerialBridge], SensorEntity):
|
class ComelitBridgeSensorEntity(ComelitBridgeBaseEntity, SensorEntity):
|
||||||
"""Sensor device."""
|
"""Sensor device."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -109,13 +109,7 @@ class ComelitBridgeSensorEntity(CoordinatorEntity[ComelitSerialBridge], SensorEn
|
|||||||
description: SensorEntityDescription,
|
description: SensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init sensor entity."""
|
"""Init sensor entity."""
|
||||||
self._api = coordinator.api
|
super().__init__(coordinator, device, config_entry_entry_id)
|
||||||
self._device = device
|
|
||||||
super().__init__(coordinator)
|
|
||||||
# Use config_entry.entry_id as base for unique_id
|
|
||||||
# because no serial number or mac is available
|
|
||||||
self._attr_unique_id = f"{config_entry_entry_id}-{device.index}"
|
|
||||||
self._attr_device_info = coordinator.platform_device_info(device, device.type)
|
|
||||||
|
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@ -144,7 +138,6 @@ class ComelitVedoSensorEntity(CoordinatorEntity[ComelitVedoSystem], SensorEntity
|
|||||||
description: SensorEntityDescription,
|
description: SensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init sensor entity."""
|
"""Init sensor entity."""
|
||||||
self._api = coordinator.api
|
|
||||||
self._zone_index = zone.index
|
self._zone_index = zone.index
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
# Use config_entry.entry_id as base for unique_id
|
# Use config_entry.entry_id as base for unique_id
|
||||||
|
@ -10,9 +10,9 @@ from aiocomelit.const import IRRIGATION, OTHER, STATE_OFF, STATE_ON
|
|||||||
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
|
|
||||||
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
from .coordinator import ComelitConfigEntry, ComelitSerialBridge
|
||||||
|
from .entity import ComelitBridgeBaseEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
@ -39,10 +39,9 @@ async def async_setup_entry(
|
|||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class ComelitSwitchEntity(CoordinatorEntity[ComelitSerialBridge], SwitchEntity):
|
class ComelitSwitchEntity(ComelitBridgeBaseEntity, SwitchEntity):
|
||||||
"""Switch device."""
|
"""Switch device."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -52,13 +51,8 @@ class ComelitSwitchEntity(CoordinatorEntity[ComelitSerialBridge], SwitchEntity):
|
|||||||
config_entry_entry_id: str,
|
config_entry_entry_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Init switch entity."""
|
"""Init switch entity."""
|
||||||
self._api = coordinator.api
|
super().__init__(coordinator, device, config_entry_entry_id)
|
||||||
self._device = device
|
|
||||||
super().__init__(coordinator)
|
|
||||||
# Use config_entry.entry_id as base for unique_id
|
|
||||||
# because no serial number or mac is available
|
|
||||||
self._attr_unique_id = f"{config_entry_entry_id}-{device.type}-{device.index}"
|
self._attr_unique_id = f"{config_entry_entry_id}-{device.type}-{device.index}"
|
||||||
self._attr_device_info = coordinator.platform_device_info(device, device.type)
|
|
||||||
if device.type == OTHER:
|
if device.type == OTHER:
|
||||||
self._attr_device_class = SwitchDeviceClass.OUTLET
|
self._attr_device_class = SwitchDeviceClass.OUTLET
|
||||||
|
|
||||||
|
@ -1304,7 +1304,6 @@ INTEGRATIONS_WITHOUT_SCALE = [
|
|||||||
"coinbase",
|
"coinbase",
|
||||||
"color_extractor",
|
"color_extractor",
|
||||||
"comed_hourly_pricing",
|
"comed_hourly_pricing",
|
||||||
"comelit",
|
|
||||||
"comfoconnect",
|
"comfoconnect",
|
||||||
"command_line",
|
"command_line",
|
||||||
"compensation",
|
"compensation",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user