diff --git a/custom_components/mikrotik_router/binary_sensor.py b/custom_components/mikrotik_router/binary_sensor.py index 221d8d7..5f9fc7e 100644 --- a/custom_components/mikrotik_router/binary_sensor.py +++ b/custom_components/mikrotik_router/binary_sensor.py @@ -177,7 +177,7 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se new_sensors = [] # 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 ["ppp_secret", "interface"], # Data point unique id @@ -186,6 +186,8 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se ["name", "name"], # Entry Unique id ["name", "port-mac-address"], + # Attr + [None, DEVICE_ATTRIBUTES_IFACE], # Tracker function [ MikrotikControllerPPPSecretBinarySensor, @@ -220,6 +222,7 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, se "sid_uid": sid_uid, "sid_name": sid_name, "sid_ref": sid_ref, + "sid_attr": sid_attr, } sensors[item_id] = sid_func( inst, uid, mikrotik_controller, config_entry, sid_data diff --git a/custom_components/mikrotik_router/sensor.py b/custom_components/mikrotik_router/sensor.py index 0847a81..712269e 100644 --- a/custom_components/mikrotik_router/sensor.py +++ b/custom_components/mikrotik_router/sensor.py @@ -377,17 +377,12 @@ class MikrotikControllerSensor(SensorEntity): self._data = mikrotik_controller.data[SENSOR_TYPES[sid_data][ATTR_PATH]] self._type = SENSOR_TYPES[sid_data] 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._dcls = self._type[ATTR_DEVICE_CLASS] self._ctgr = self._type[ATTR_CTGR] else: self._type = {} self._icon = None - self._unit = None self._attr = None self._dcls = None self._ctgr = None @@ -437,7 +432,11 @@ class MikrotikControllerSensor(SensorEntity): @property def unit_of_measurement(self): """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 def available(self) -> bool: