2020-05-08 05:52:20 +00:00
|
|
|
"""Adapter to wrap the pyjuicenet api for home assistant."""
|
|
|
|
|
2022-05-12 11:14:52 +00:00
|
|
|
from pyjuicenet import Charger
|
|
|
|
|
2021-10-22 15:40:13 +00:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
2022-05-12 11:14:52 +00:00
|
|
|
from homeassistant.helpers.update_coordinator import (
|
|
|
|
CoordinatorEntity,
|
|
|
|
DataUpdateCoordinator,
|
|
|
|
)
|
2020-05-08 05:52:20 +00:00
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
2020-08-30 14:38:15 +00:00
|
|
|
class JuiceNetDevice(CoordinatorEntity):
|
2020-05-08 05:52:20 +00:00
|
|
|
"""Represent a base JuiceNet device."""
|
|
|
|
|
2022-05-12 11:14:52 +00:00
|
|
|
def __init__(
|
|
|
|
self, device: Charger, key: str, coordinator: DataUpdateCoordinator
|
|
|
|
) -> None:
|
2020-05-08 05:52:20 +00:00
|
|
|
"""Initialise the sensor."""
|
2020-08-30 14:38:15 +00:00
|
|
|
super().__init__(coordinator)
|
2020-05-08 05:52:20 +00:00
|
|
|
self.device = device
|
2022-05-12 11:14:52 +00:00
|
|
|
self.key = key
|
2020-05-08 05:52:20 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return a unique ID."""
|
2022-05-12 11:14:52 +00:00
|
|
|
return f"{self.device.id}-{self.key}"
|
2020-05-08 05:52:20 +00:00
|
|
|
|
|
|
|
@property
|
2021-10-22 15:40:13 +00:00
|
|
|
def device_info(self) -> DeviceInfo:
|
2020-05-08 05:52:20 +00:00
|
|
|
"""Return device information about this JuiceNet Device."""
|
2021-10-22 15:40:13 +00:00
|
|
|
return DeviceInfo(
|
2021-10-23 18:42:50 +00:00
|
|
|
configuration_url=f"https://home.juice.net/Portal/Details?unitID={self.device.id}",
|
2021-10-22 15:40:13 +00:00
|
|
|
identifiers={(DOMAIN, self.device.id)},
|
|
|
|
manufacturer="JuiceNet",
|
2021-10-23 18:42:50 +00:00
|
|
|
name=self.device.name,
|
2021-10-22 15:40:13 +00:00
|
|
|
)
|