Skip to content

Commit

Permalink
feat(sensors): add rssi sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
IATkachenko committed Sep 24, 2022
1 parent 7ed1ac0 commit db6d13a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/ha_tion_btle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry):
self.__tion: Tion = self.getTion(self.model, btle_device)
self.__keep_alive = datetime.timedelta(seconds=self.__keep_alive)
self._delay = datetime.timedelta(seconds=self._delay)
self.rssi: int = 0

if self._config_entry.unique_id is None:
_LOGGER.critical(f"Unique id is None for {self._config_entry.title}! "
Expand Down Expand Up @@ -127,6 +128,7 @@ async def async_update_state(self):
response["is_heating"] = self._decode_state(response["heating"])
response["filter_remain"] = math.ceil(response["filter_remain"])
response["fan_speed"] = int(response["fan_speed"])
response["rssi"] = self.rssi

self.logger.debug(f"Result is {response}")
return response
Expand Down Expand Up @@ -209,4 +211,5 @@ def update_btle_device(
) -> None:
_LOGGER.info(f"update_btle_device called with {service_info=}, {_change=}")
if service_info.device is not None:
self.rssi = service_info.rssi
self.__tion.update_btle_device(service_info.device)
8 changes: 8 additions & 0 deletions custom_components/ha_tion_btle/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:fan",
),
SensorEntityDescription(
key="rssi",
name="rssi",
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:access-point",
),
)


Expand Down

0 comments on commit db6d13a

Please sign in to comment.