2019-12-04 16:09:30 +01:00
|
|
|
"""Support for the Mikrotik Router binary sensor service."""
|
|
|
|
|
|
|
|
import logging
|
2020-12-25 20:28:36 +01:00
|
|
|
from typing import Any, Dict, Optional
|
2020-03-21 19:02:28 +03:00
|
|
|
|
2020-12-25 17:50:21 +01:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
BinarySensorEntity,
|
|
|
|
DEVICE_CLASS_CONNECTIVITY,
|
|
|
|
)
|
2019-12-04 16:09:30 +01:00
|
|
|
from homeassistant.const import (
|
|
|
|
CONF_NAME,
|
|
|
|
ATTR_ATTRIBUTION,
|
|
|
|
)
|
2020-03-21 19:02:28 +03:00
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2020-12-25 18:24:47 +01:00
|
|
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
2019-12-04 16:09:30 +01:00
|
|
|
|
|
|
|
from .const import (
|
|
|
|
DOMAIN,
|
|
|
|
DATA_CLIENT,
|
|
|
|
ATTRIBUTION,
|
2020-12-25 17:50:21 +01:00
|
|
|
CONF_SENSOR_PPP,
|
|
|
|
DEFAULT_SENSOR_PPP,
|
2020-12-25 18:24:47 +01:00
|
|
|
CONF_SENSOR_PORT_TRACKER,
|
|
|
|
DEFAULT_SENSOR_PORT_TRACKER,
|
2019-12-04 16:09:30 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
ATTR_LABEL = "label"
|
|
|
|
ATTR_GROUP = "group"
|
|
|
|
ATTR_PATH = "data_path"
|
|
|
|
ATTR_ATTR = "data_attr"
|
|
|
|
|
|
|
|
SENSOR_TYPES = {
|
2020-03-16 04:51:41 +01:00
|
|
|
"system_fwupdate": {
|
|
|
|
ATTR_LABEL: "Firmware update",
|
2019-12-04 16:09:30 +01:00
|
|
|
ATTR_GROUP: "System",
|
|
|
|
ATTR_PATH: "fw-update",
|
|
|
|
ATTR_ATTR: "available",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-12-25 18:24:47 +01:00
|
|
|
DEVICE_ATTRIBUTES_IFACE = [
|
|
|
|
"running",
|
|
|
|
"enabled",
|
|
|
|
"comment",
|
|
|
|
"client-ip-address",
|
|
|
|
"client-mac-address",
|
|
|
|
"port-mac-address",
|
|
|
|
"last-link-down-time",
|
|
|
|
"last-link-up-time",
|
|
|
|
"link-downs",
|
|
|
|
"actual-mtu",
|
|
|
|
"type",
|
|
|
|
"name",
|
|
|
|
"default-name",
|
|
|
|
"poe-out",
|
|
|
|
]
|
|
|
|
|
2020-12-25 17:50:21 +01:00
|
|
|
DEVICE_ATTRIBUTES_PPP_SECRET = [
|
|
|
|
"connected",
|
|
|
|
"service",
|
|
|
|
"profile",
|
|
|
|
"comment",
|
|
|
|
"caller-id",
|
|
|
|
"encoding",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------
|
|
|
|
# format_attribute
|
|
|
|
# ---------------------------
|
|
|
|
def format_attribute(attr):
|
|
|
|
res = attr.replace("-", " ")
|
|
|
|
res = res.capitalize()
|
|
|
|
res = res.replace(" ip ", " IP ")
|
|
|
|
res = res.replace(" mac ", " MAC ")
|
|
|
|
res = res.replace(" mtu", " MTU")
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------
|
|
|
|
# format_value
|
|
|
|
# ---------------------------
|
|
|
|
def format_value(res):
|
|
|
|
res = res.replace("dhcp", "DHCP")
|
|
|
|
res = res.replace("dns", "DNS")
|
|
|
|
res = res.replace("capsman", "CAPsMAN")
|
|
|
|
res = res.replace("wireless", "Wireless")
|
|
|
|
res = res.replace("restored", "Restored")
|
|
|
|
return res
|
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
|
|
|
|
# ---------------------------
|
|
|
|
# async_setup_entry
|
|
|
|
# ---------------------------
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up device tracker for Mikrotik Router component."""
|
2019-12-06 01:22:34 +01:00
|
|
|
inst = config_entry.data[CONF_NAME]
|
2019-12-04 16:09:30 +01:00
|
|
|
mikrotik_controller = hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id]
|
|
|
|
sensors = {}
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
@callback
|
|
|
|
def update_controller():
|
|
|
|
"""Update the values of the controller."""
|
2020-12-25 17:50:21 +01:00
|
|
|
update_items(
|
|
|
|
inst, config_entry, mikrotik_controller, async_add_entities, sensors
|
|
|
|
)
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
mikrotik_controller.listeners.append(
|
2020-03-16 04:51:41 +01:00
|
|
|
async_dispatcher_connect(
|
|
|
|
hass, mikrotik_controller.signal_update, update_controller
|
|
|
|
)
|
2019-12-04 16:09:30 +01:00
|
|
|
)
|
|
|
|
update_controller()
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------
|
|
|
|
# update_items
|
|
|
|
# ---------------------------
|
|
|
|
@callback
|
2020-12-25 17:50:21 +01:00
|
|
|
def update_items(inst, config_entry, mikrotik_controller, async_add_entities, sensors):
|
2019-12-04 16:09:30 +01:00
|
|
|
"""Update sensor state from the controller."""
|
|
|
|
new_sensors = []
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2020-12-25 17:50:21 +01:00
|
|
|
# Add switches
|
|
|
|
for sid, sid_uid, sid_name, sid_ref, sid_func in zip(
|
|
|
|
# Data point name
|
2020-12-25 18:24:47 +01:00
|
|
|
["ppp_secret", "interface"],
|
2020-12-25 17:50:21 +01:00
|
|
|
# Data point unique id
|
2020-12-25 18:24:47 +01:00
|
|
|
["name", "default-name"],
|
2020-12-25 17:50:21 +01:00
|
|
|
# Entry Name
|
2020-12-25 18:24:47 +01:00
|
|
|
["name", "name"],
|
2020-12-25 17:50:21 +01:00
|
|
|
# Entry Unique id
|
2020-12-25 18:24:47 +01:00
|
|
|
["name", "port-mac-address"],
|
2020-12-25 17:50:21 +01:00
|
|
|
# Tracker function
|
|
|
|
[
|
|
|
|
MikrotikControllerPPPSecretBinarySensor,
|
2020-12-25 18:24:47 +01:00
|
|
|
MikrotikControllerPortBinarySensor,
|
2020-12-25 17:50:21 +01:00
|
|
|
],
|
|
|
|
):
|
2020-12-25 18:24:47 +01:00
|
|
|
if (
|
|
|
|
sid_func == MikrotikControllerPortBinarySensor
|
|
|
|
and not config_entry.options.get(
|
|
|
|
CONF_SENSOR_PORT_TRACKER, DEFAULT_SENSOR_PORT_TRACKER
|
|
|
|
)
|
|
|
|
):
|
|
|
|
continue
|
2020-12-25 17:50:21 +01:00
|
|
|
for uid in mikrotik_controller.data[sid]:
|
2020-12-25 18:24:47 +01:00
|
|
|
if (
|
|
|
|
# Skip if interface is wlan
|
|
|
|
sid == "interface"
|
|
|
|
and mikrotik_controller.data[sid][uid]["type"] == "wlan"
|
|
|
|
):
|
|
|
|
continue
|
2020-12-25 17:50:21 +01:00
|
|
|
# Update entity
|
|
|
|
item_id = f"{inst}-{sid}-{mikrotik_controller.data[sid][uid][sid_uid]}"
|
|
|
|
_LOGGER.debug("Updating binary_sensor %s", item_id)
|
|
|
|
if item_id in sensors:
|
|
|
|
if sensors[item_id].enabled:
|
|
|
|
sensors[item_id].async_schedule_update_ha_state()
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Create new entity
|
|
|
|
sid_data = {
|
|
|
|
"sid": sid,
|
|
|
|
"sid_uid": sid_uid,
|
|
|
|
"sid_name": sid_name,
|
|
|
|
"sid_ref": sid_ref,
|
|
|
|
}
|
|
|
|
sensors[item_id] = sid_func(
|
|
|
|
inst, uid, mikrotik_controller, config_entry, sid_data
|
|
|
|
)
|
|
|
|
new_sensors.append(sensors[item_id])
|
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
for sensor in SENSOR_TYPES:
|
2020-03-16 19:02:54 +01:00
|
|
|
item_id = f"{inst}-{sensor}"
|
2020-04-04 19:46:40 +02:00
|
|
|
_LOGGER.debug("Updating binary_sensor %s", item_id)
|
2019-12-04 16:09:30 +01:00
|
|
|
if item_id in sensors:
|
|
|
|
if sensors[item_id].enabled:
|
|
|
|
sensors[item_id].async_schedule_update_ha_state()
|
|
|
|
continue
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2020-03-16 04:51:41 +01:00
|
|
|
sensors[item_id] = MikrotikControllerBinarySensor(
|
|
|
|
mikrotik_controller=mikrotik_controller, inst=inst, sensor=sensor
|
|
|
|
)
|
2019-12-04 16:09:30 +01:00
|
|
|
new_sensors.append(sensors[item_id])
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
if new_sensors:
|
|
|
|
async_add_entities(new_sensors, True)
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
|
2020-05-20 16:01:32 +02:00
|
|
|
class MikrotikControllerBinarySensor(BinarySensorEntity):
|
2019-12-04 16:09:30 +01:00
|
|
|
"""Define an Mikrotik Controller Binary Sensor."""
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-06 01:22:34 +01:00
|
|
|
def __init__(self, mikrotik_controller, inst, sensor):
|
2019-12-04 16:09:30 +01:00
|
|
|
"""Initialize."""
|
2019-12-06 01:22:34 +01:00
|
|
|
self._inst = inst
|
|
|
|
self._sensor = sensor
|
|
|
|
self._ctrl = mikrotik_controller
|
2020-12-25 17:50:21 +01:00
|
|
|
if sensor in SENSOR_TYPES:
|
|
|
|
self._data = mikrotik_controller.data[SENSOR_TYPES[sensor][ATTR_PATH]]
|
|
|
|
self._type = SENSOR_TYPES[sensor]
|
|
|
|
self._attr = SENSOR_TYPES[sensor][ATTR_ATTR]
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
self._device_class = None
|
|
|
|
self._state = None
|
|
|
|
self._icon = None
|
|
|
|
self._unit_of_measurement = None
|
|
|
|
self._attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def name(self) -> str:
|
2019-12-04 16:09:30 +01:00
|
|
|
"""Return the name."""
|
2020-03-16 19:02:54 +01:00
|
|
|
return f"{self._inst} {self._type[ATTR_LABEL]}"
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def device_state_attributes(self) -> Dict[str, Any]:
|
2019-12-04 16:09:30 +01:00
|
|
|
"""Return the state attributes."""
|
|
|
|
return self._attrs
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def unique_id(self) -> str:
|
|
|
|
"""Return a unique id for this entity."""
|
2020-03-16 19:02:54 +01:00
|
|
|
return f"{self._inst.lower()}-{self._sensor.lower()}"
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
@property
|
2019-12-08 22:42:54 +01:00
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return if controller is available."""
|
|
|
|
return self._ctrl.connected()
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def device_info(self) -> Dict[str, Any]:
|
|
|
|
"""Return a description for device registry."""
|
2019-12-04 16:09:30 +01:00
|
|
|
info = {
|
2020-04-10 09:22:28 +02:00
|
|
|
"manufacturer": self._ctrl.data["resource"]["platform"],
|
|
|
|
"model": self._ctrl.data["resource"]["board-name"],
|
|
|
|
"name": f"{self._inst} {self._type[ATTR_GROUP]}",
|
|
|
|
}
|
|
|
|
if ATTR_GROUP in self._type:
|
|
|
|
info["identifiers"] = {
|
2020-03-16 04:51:41 +01:00
|
|
|
(
|
|
|
|
DOMAIN,
|
|
|
|
"serial-number",
|
|
|
|
self._ctrl.data["routerboard"]["serial-number"],
|
|
|
|
"switch",
|
2020-04-10 09:22:28 +02:00
|
|
|
self._type[ATTR_GROUP],
|
2020-03-16 04:51:41 +01:00
|
|
|
)
|
2020-04-10 09:22:28 +02:00
|
|
|
}
|
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
return info
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if device is on."""
|
2019-12-04 16:09:30 +01:00
|
|
|
val = False
|
2019-12-06 01:22:34 +01:00
|
|
|
if self._attr in self._data:
|
|
|
|
val = self._data[self._attr]
|
2019-12-05 20:45:04 +01:00
|
|
|
|
2019-12-04 16:09:30 +01:00
|
|
|
return val
|
2020-12-25 17:50:21 +01:00
|
|
|
|
2020-12-25 20:28:36 +01:00
|
|
|
async def async_update(self):
|
|
|
|
"""Synchronize state with controller."""
|
|
|
|
|
|
|
|
async def async_added_to_hass(self):
|
|
|
|
"""Run when entity about to be added to hass."""
|
|
|
|
_LOGGER.debug("New sensor %s (%s)", self._inst, self._sensor)
|
|
|
|
|
2020-12-25 17:50:21 +01:00
|
|
|
|
|
|
|
# ---------------------------
|
|
|
|
# MikrotikControllerPPPSecretBinarySensor
|
|
|
|
# ---------------------------
|
|
|
|
class MikrotikControllerPPPSecretBinarySensor(MikrotikControllerBinarySensor):
|
|
|
|
"""Representation of a network device."""
|
|
|
|
|
|
|
|
def __init__(self, inst, uid, mikrotik_controller, config_entry, sid_data):
|
2020-12-25 20:28:36 +01:00
|
|
|
"""Initialize."""
|
2020-12-25 17:50:21 +01:00
|
|
|
super().__init__(mikrotik_controller, inst, uid)
|
|
|
|
self._sid_data = sid_data
|
|
|
|
self._data = mikrotik_controller.data[self._sid_data["sid"]][uid]
|
|
|
|
self._config_entry = config_entry
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def option_sensor_ppp(self) -> bool:
|
|
|
|
"""Config entry option."""
|
2020-12-25 17:50:21 +01:00
|
|
|
return self._config_entry.options.get(CONF_SENSOR_PPP, DEFAULT_SENSOR_PPP)
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def name(self) -> str:
|
|
|
|
"""Return the name."""
|
2020-12-25 17:50:21 +01:00
|
|
|
return f"{self._inst} PPP {self._data['name']}"
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if device is on."""
|
2020-12-25 17:50:21 +01:00
|
|
|
if not self.option_sensor_ppp:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return self._data["connected"]
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def device_class(self) -> Optional[str]:
|
2020-12-25 17:50:21 +01:00
|
|
|
"""Return the device class."""
|
|
|
|
return DEVICE_CLASS_CONNECTIVITY
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return if controller is available."""
|
|
|
|
if not self.option_sensor_ppp:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return self._ctrl.connected()
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def unique_id(self) -> str:
|
|
|
|
"""Return a unique id for this entity."""
|
2020-12-25 17:50:21 +01:00
|
|
|
return f"{self._inst.lower()}-{self._sid_data['sid']}_tracker-{self._data[self._sid_data['sid_ref']]}"
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def icon(self) -> str:
|
2020-12-25 17:50:21 +01:00
|
|
|
"""Return the icon."""
|
|
|
|
if self._data["connected"]:
|
|
|
|
return "mdi:account-network-outline"
|
|
|
|
else:
|
|
|
|
return "mdi:account-off-outline"
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def device_state_attributes(self) -> Dict[str, Any]:
|
|
|
|
"""Return the state attributes."""
|
2020-12-25 17:50:21 +01:00
|
|
|
attributes = self._attrs
|
|
|
|
for variable in DEVICE_ATTRIBUTES_PPP_SECRET:
|
|
|
|
if variable in self._data:
|
|
|
|
attributes[format_attribute(variable)] = self._data[variable]
|
|
|
|
|
|
|
|
return attributes
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def device_info(self) -> Dict[str, Any]:
|
|
|
|
"""Return a description for device registry."""
|
2020-12-25 17:50:21 +01:00
|
|
|
info = {
|
|
|
|
"identifiers": {
|
|
|
|
(
|
|
|
|
DOMAIN,
|
|
|
|
"serial-number",
|
|
|
|
self._ctrl.data["routerboard"]["serial-number"],
|
|
|
|
"switch",
|
|
|
|
"PPP",
|
|
|
|
)
|
|
|
|
},
|
|
|
|
"manufacturer": self._ctrl.data["resource"]["platform"],
|
|
|
|
"model": self._ctrl.data["resource"]["board-name"],
|
|
|
|
"name": f"{self._inst} PPP",
|
|
|
|
}
|
|
|
|
return info
|
2020-12-25 18:24:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------
|
|
|
|
# MikrotikControllerPortBinarySensor
|
|
|
|
# ---------------------------
|
|
|
|
class MikrotikControllerPortBinarySensor(MikrotikControllerBinarySensor):
|
|
|
|
"""Representation of a network port."""
|
|
|
|
|
|
|
|
def __init__(self, inst, uid, mikrotik_controller, config_entry, sid_data):
|
2020-12-25 20:28:36 +01:00
|
|
|
"""Initialize."""
|
2020-12-25 18:24:47 +01:00
|
|
|
super().__init__(mikrotik_controller, inst, uid)
|
|
|
|
self._sid_data = sid_data
|
|
|
|
self._data = mikrotik_controller.data[self._sid_data["sid"]][uid]
|
|
|
|
self._config_entry = config_entry
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def option_sensor_port_tracker(self) -> bool:
|
2020-12-25 18:24:47 +01:00
|
|
|
"""Config entry option to not track ARP."""
|
|
|
|
return self._config_entry.options.get(
|
|
|
|
CONF_SENSOR_PORT_TRACKER, DEFAULT_SENSOR_PORT_TRACKER
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def name(self) -> str:
|
|
|
|
"""Return the name."""
|
2020-12-25 18:24:47 +01:00
|
|
|
return f"{self._inst} {self._data[self._sid_data['sid_name']]}"
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def unique_id(self) -> str:
|
|
|
|
"""Return a unique id for this entity."""
|
2020-12-25 18:24:47 +01:00
|
|
|
return f"{self._inst.lower()}-{self._sid_data['sid']}-{self._data['port-mac-address']}_{self._data['default-name']}"
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Return true if device is on."""
|
2020-12-25 18:24:47 +01:00
|
|
|
return self._data["running"]
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def device_class(self) -> Optional[str]:
|
2020-12-25 18:24:47 +01:00
|
|
|
"""Return the device class."""
|
|
|
|
return DEVICE_CLASS_CONNECTIVITY
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return if controller is available."""
|
|
|
|
if not self.option_sensor_port_tracker:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return self._ctrl.connected()
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def icon(self) -> str:
|
2020-12-25 18:24:47 +01:00
|
|
|
"""Return the icon."""
|
|
|
|
if self._data["running"]:
|
|
|
|
icon = "mdi:lan-connect"
|
|
|
|
else:
|
|
|
|
icon = "mdi:lan-pending"
|
|
|
|
|
|
|
|
if not self._data["enabled"]:
|
|
|
|
icon = "mdi:lan-disconnect"
|
|
|
|
|
|
|
|
return icon
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def device_state_attributes(self) -> Dict[str, Any]:
|
|
|
|
"""Return the state attributes."""
|
2020-12-25 18:24:47 +01:00
|
|
|
attributes = self._attrs
|
|
|
|
for variable in DEVICE_ATTRIBUTES_IFACE:
|
|
|
|
if variable in self._data:
|
|
|
|
attributes[format_attribute(variable)] = self._data[variable]
|
|
|
|
|
|
|
|
return attributes
|
|
|
|
|
|
|
|
@property
|
2020-12-25 20:28:36 +01:00
|
|
|
def device_info(self) -> Dict[str, Any]:
|
2020-12-25 18:24:47 +01:00
|
|
|
"""Return a description for device registry."""
|
|
|
|
info = {
|
|
|
|
"connections": {
|
|
|
|
(CONNECTION_NETWORK_MAC, self._data[self._sid_data["sid_ref"]])
|
|
|
|
},
|
|
|
|
"manufacturer": self._ctrl.data["resource"]["platform"],
|
|
|
|
"model": self._ctrl.data["resource"]["board-name"],
|
|
|
|
"name": f"{self._inst} {self._data[self._sid_data['sid_name']]}",
|
|
|
|
}
|
|
|
|
|
|
|
|
return info
|