1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-21 07:50:23 +01:00
Files
Matthew Gibson 8c8a863867 Add ptdevices Integration (#156307)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2026-05-04 22:15:52 +02:00

50 lines
1.6 KiB
Python

"""PTDevices integration."""
from typing import Any
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .coordinator import PTDevicesCoordinator
class PTDevicesEntity(CoordinatorEntity[PTDevicesCoordinator]):
"""Defines a base PTDevices entity."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: PTDevicesCoordinator,
sensor_key: str,
device_id: str,
) -> None:
"""Initialize."""
super().__init__(coordinator=coordinator)
self._sensor_key = sensor_key
self._device_id = device_id
self._user_id = coordinator.data[self._device_id]["user_id"]
self._attr_unique_id = f"{self._user_id}_{device_id}_{sensor_key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{self._user_id}_{self._device_id}")},
connections={(CONNECTION_NETWORK_MAC, self._device_id)},
configuration_url=f"https://www.ptdevices.com/device/level/{self.device['id']}",
manufacturer="ParemTech Inc.",
model=self.device["device_type"],
sw_version=str(self.device["version"]),
name=self.device["title"],
)
@property
def device(self) -> dict[str, Any]:
"""Return the device data."""
return self.coordinator.data[self._device_id]
@property
def available(self) -> bool:
"""Return if the device is available."""
return super().available and self._device_id in self.coordinator.data