mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Move zwave_me base entity to separate module (#126200)
This commit is contained in:
parent
1893545705
commit
8827b5510f
@ -1,21 +1,16 @@
|
||||
"""The Z-Wave-Me WS integration."""
|
||||
|
||||
import logging
|
||||
|
||||
from zwave_me_ws import ZWaveMe, ZWaveMeData
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_TOKEN, CONF_URL
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
|
||||
from .const import DOMAIN, PLATFORMS, ZWaveMePlatform
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
ZWAVE_ME_PLATFORMS = [platform.value for platform in ZWaveMePlatform]
|
||||
|
||||
|
||||
@ -111,66 +106,3 @@ async def async_setup_platforms(
|
||||
controller.platforms_inited = True
|
||||
|
||||
await hass.async_add_executor_job(controller.zwave_api.get_devices)
|
||||
|
||||
|
||||
class ZWaveMeEntity(Entity):
|
||||
"""Representation of a ZWaveMe device."""
|
||||
|
||||
def __init__(self, controller, device):
|
||||
"""Initialize the device."""
|
||||
self.controller = controller
|
||||
self.device = device
|
||||
self._attr_name = device.title
|
||||
self._attr_unique_id: str = (
|
||||
f"{self.controller.config.unique_id}-{self.device.id}"
|
||||
)
|
||||
self._attr_should_poll = False
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device specific attributes."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device.deviceIdentifier)},
|
||||
name=self._attr_name,
|
||||
manufacturer=self.device.manufacturer,
|
||||
sw_version=self.device.firmware,
|
||||
suggested_area=self.device.locationName,
|
||||
)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Connect to an updater."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, f"ZWAVE_ME_INFO_{self.device.id}", self.get_new_data
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"ZWAVE_ME_UNAVAILABLE_{self.device.id}",
|
||||
self.set_unavailable_status,
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, f"ZWAVE_ME_DESTROY_{self.device.id}", self.delete_entity
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def get_new_data(self, new_data: ZWaveMeData) -> None:
|
||||
"""Update info in the HAss."""
|
||||
self.device = new_data
|
||||
self._attr_available = not new_data.isFailed
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def set_unavailable_status(self):
|
||||
"""Update status in the HAss."""
|
||||
self._attr_available = False
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def delete_entity(self) -> None:
|
||||
"""Remove this entity."""
|
||||
self.hass.async_create_task(self.async_remove(force_remove=True))
|
||||
|
@ -14,8 +14,9 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeController, ZWaveMeEntity
|
||||
from . import ZWaveMeController
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
BINARY_SENSORS_MAP: dict[str, BinarySensorEntityDescription] = {
|
||||
"generic": BinarySensorEntityDescription(
|
||||
|
@ -6,8 +6,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
DEVICE_NAME = ZWaveMePlatform.BUTTON
|
||||
|
||||
|
@ -17,8 +17,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
TEMPERATURE_DEFAULT_STEP = 0.5
|
||||
|
||||
|
@ -14,8 +14,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
DEVICE_NAME = ZWaveMePlatform.COVER
|
||||
|
||||
|
73
homeassistant/components/zwave_me/entity.py
Normal file
73
homeassistant/components/zwave_me/entity.py
Normal file
@ -0,0 +1,73 @@
|
||||
"""The Z-Wave-Me WS integration."""
|
||||
|
||||
from zwave_me_ws import ZWaveMeData
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class ZWaveMeEntity(Entity):
|
||||
"""Representation of a ZWaveMe device."""
|
||||
|
||||
def __init__(self, controller, device):
|
||||
"""Initialize the device."""
|
||||
self.controller = controller
|
||||
self.device = device
|
||||
self._attr_name = device.title
|
||||
self._attr_unique_id: str = (
|
||||
f"{self.controller.config.unique_id}-{self.device.id}"
|
||||
)
|
||||
self._attr_should_poll = False
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device specific attributes."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device.deviceIdentifier)},
|
||||
name=self._attr_name,
|
||||
manufacturer=self.device.manufacturer,
|
||||
sw_version=self.device.firmware,
|
||||
suggested_area=self.device.locationName,
|
||||
)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Connect to an updater."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, f"ZWAVE_ME_INFO_{self.device.id}", self.get_new_data
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"ZWAVE_ME_UNAVAILABLE_{self.device.id}",
|
||||
self.set_unavailable_status,
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, f"ZWAVE_ME_DESTROY_{self.device.id}", self.delete_entity
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def get_new_data(self, new_data: ZWaveMeData) -> None:
|
||||
"""Update info in the HAss."""
|
||||
self.device = new_data
|
||||
self._attr_available = not new_data.isFailed
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def set_unavailable_status(self):
|
||||
"""Update status in the HAss."""
|
||||
self._attr_available = False
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def delete_entity(self) -> None:
|
||||
"""Remove this entity."""
|
||||
self.hass.async_create_task(self.async_remove(force_remove=True))
|
@ -10,8 +10,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
DEVICE_NAME = ZWaveMePlatform.FAN
|
||||
|
||||
|
@ -17,8 +17,9 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeController, ZWaveMeEntity
|
||||
from . import ZWaveMeController
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
@ -12,8 +12,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
DEVICE_NAME = ZWaveMePlatform.LOCK
|
||||
|
||||
|
@ -6,8 +6,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
DEVICE_NAME = ZWaveMePlatform.NUMBER
|
||||
|
||||
|
@ -28,8 +28,9 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeController, ZWaveMeEntity
|
||||
from . import ZWaveMeController
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
@ -8,8 +8,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
DEVICE_NAME = ZWaveMePlatform.SIREN
|
||||
|
||||
|
@ -13,8 +13,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ZWaveMeEntity
|
||||
from .const import DOMAIN, ZWaveMePlatform
|
||||
from .entity import ZWaveMeEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
DEVICE_NAME = ZWaveMePlatform.SWITCH
|
||||
|
Loading…
x
Reference in New Issue
Block a user