From dc56ed219b593b8957b21101833118f0b0f4379f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Nenz=C3=A9n?= Date: Tue, 27 Aug 2024 20:52:48 +0200 Subject: [PATCH] Fixes state sensor for A7 (#141) --- custom_components/wellbeing/__init__.py | 17 ++++++++++++++--- custom_components/wellbeing/api.py | 7 ++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/custom_components/wellbeing/__init__.py b/custom_components/wellbeing/__init__.py index 068b8e7..9e8f69c 100644 --- a/custom_components/wellbeing/__init__.py +++ b/custom_components/wellbeing/__init__.py @@ -102,11 +102,22 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry): def update(self, access_token: str, refresh_token: str, api_key: str | None = None): super().update(access_token, refresh_token, api_key) _LOGGER.debug("Tokens updated") - _LOGGER.debug(f"Api key: {api_key} : {self.api_key}") - _LOGGER.debug(f"Access token: {access_token}") - _LOGGER.debug(f"Refresh token: {refresh_token}") + _LOGGER.debug(f"Api key: {self._mask_access_token(self.api_key)}") + _LOGGER.debug(f"Access token: {self._mask_access_token(access_token)}") + _LOGGER.debug(f"Refresh token: {self._mask_access_token(refresh_token)}") self._hass.config_entries.async_update_entry( self._entry, data={CONF_API_KEY: self.api_key, CONF_REFRESH_TOKEN: refresh_token, CONF_ACCESS_TOKEN: access_token}, ) + + @staticmethod + def _mask_access_token(token: str): + if len(token) == 1: + return "*" + elif len(token) < 4: + return token[:2] + "*" * (len(token) - 2) + elif len(token) < 10: + return token[:2] + "*****" + token[-2:] + else: + return token[:5] + "*****" + token[-5:] diff --git a/custom_components/wellbeing/api.py b/custom_components/wellbeing/api.py index ed5e90b..54ad477 100644 --- a/custom_components/wellbeing/api.py +++ b/custom_components/wellbeing/api.py @@ -163,7 +163,12 @@ def _create_entities(data): attr="FilterLife_2", unit=PERCENTAGE, ), - ApplianceSensor(name="State", attr="State", entity_category=EntityCategory.DIAGNOSTIC), + ApplianceSensor( + name="State", + attr="State", + device_class=SensorDeviceClass.ENUM, + entity_category=EntityCategory.DIAGNOSTIC + ), ApplianceBinary( name="PM Sensor State", attr="PMSensState",