Fixed sensor and binary sensor attributes #147

This commit is contained in:
tomaae 2021-12-16 06:16:02 +01:00
parent b04a0a5b26
commit 6129e18cc3
2 changed files with 9 additions and 7 deletions

View file

@ -177,7 +177,7 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se
new_sensors = [] new_sensors = []
# Add switches # Add switches
for sid, sid_uid, sid_name, sid_ref, sid_func in zip( for sid, sid_uid, sid_name, sid_ref, sid_attr, sid_func in zip(
# Data point name # Data point name
["ppp_secret", "interface"], ["ppp_secret", "interface"],
# Data point unique id # Data point unique id
@ -186,6 +186,8 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se
["name", "name"], ["name", "name"],
# Entry Unique id # Entry Unique id
["name", "port-mac-address"], ["name", "port-mac-address"],
# Attr
[None, DEVICE_ATTRIBUTES_IFACE],
# Tracker function # Tracker function
[ [
MikrotikControllerPPPSecretBinarySensor, MikrotikControllerPPPSecretBinarySensor,
@ -220,6 +222,7 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se
"sid_uid": sid_uid, "sid_uid": sid_uid,
"sid_name": sid_name, "sid_name": sid_name,
"sid_ref": sid_ref, "sid_ref": sid_ref,
"sid_attr": sid_attr,
} }
sensors[item_id] = sid_func( sensors[item_id] = sid_func(
inst, uid, mikrotik_controller, config_entry, sid_data inst, uid, mikrotik_controller, config_entry, sid_data

View file

@ -377,17 +377,12 @@ class MikrotikControllerSensor(SensorEntity):
self._data = mikrotik_controller.data[SENSOR_TYPES[sid_data][ATTR_PATH]] self._data = mikrotik_controller.data[SENSOR_TYPES[sid_data][ATTR_PATH]]
self._type = SENSOR_TYPES[sid_data] self._type = SENSOR_TYPES[sid_data]
self._icon = self._type[ATTR_ICON] self._icon = self._type[ATTR_ICON]
if ATTR_UNIT in self._type:
self._unit = self._type[ATTR_UNIT]
if ATTR_UNIT_ATTR in self._type:
self._unit = self._data[SENSOR_TYPES[self._sensor][ATTR_UNIT_ATTR]]
self._attr = self._type[ATTR_ATTR] self._attr = self._type[ATTR_ATTR]
self._dcls = self._type[ATTR_DEVICE_CLASS] self._dcls = self._type[ATTR_DEVICE_CLASS]
self._ctgr = self._type[ATTR_CTGR] self._ctgr = self._type[ATTR_CTGR]
else: else:
self._type = {} self._type = {}
self._icon = None self._icon = None
self._unit = None
self._attr = None self._attr = None
self._dcls = None self._dcls = None
self._ctgr = None self._ctgr = None
@ -437,7 +432,11 @@ class MikrotikControllerSensor(SensorEntity):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
return self._unit if ATTR_UNIT_ATTR in self._type:
return self._data[SENSOR_TYPES[self._sensor][ATTR_UNIT_ATTR]]
if ATTR_UNIT in self._type:
return self._type[ATTR_UNIT]
@property @property
def available(self) -> bool: def available(self) -> bool: