Skip to content

Commit

Permalink
Fix #674: RSSI sensor creates issues on log
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Oct 28, 2024
1 parent 965d785 commit 2c91a8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions custom_components/tapo_control/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def updateTapo(self, camData: dict | None) -> None:
or camData["connectionInformation"] is False
or "rssiValue" not in camData["connectionInformation"]
):
self._attr_native_value = "unavailable"
self._attr_native_value = STATE_UNAVAILABLE
else:
self._attr_native_value = camData["connectionInformation"]["rssiValue"]

Expand Down Expand Up @@ -140,7 +140,7 @@ def updateTapo(self, camData: dict | None) -> None:
or camData["connectionInformation"] is False
or "link_type" not in camData["connectionInformation"]
):
self._attr_native_value = "unavailable"
self._attr_native_value = STATE_UNAVAILABLE
else:
self._attr_native_value = camData["connectionInformation"]["link_type"]

Expand Down Expand Up @@ -175,7 +175,7 @@ def updateTapo(self, camData: dict | None) -> None:
or camData["connectionInformation"] is False
or "ssid" not in camData["connectionInformation"]
):
self._attr_native_value = "unavailable"
self._attr_native_value = STATE_UNAVAILABLE
else:
self._attr_native_value = camData["connectionInformation"]["ssid"]

Expand Down Expand Up @@ -209,7 +209,7 @@ async def async_update(self) -> None:
def updateTapo(self, camData: dict | None) -> None:
"""Update the entity."""
if not camData:
self._attr_native_value = "unavailable"
self._attr_native_value = STATE_UNAVAILABLE
else:
self._attr_native_value = camData["basic_info"]["battery_percent"]

Expand Down
8 changes: 8 additions & 0 deletions custom_components/tapo_control/tapo/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.entity import EntityCategory
from homeassistant.util import slugify
from homeassistant.const import (
STATE_UNAVAILABLE,
)

from ..const import BRAND, LOGGER, DOMAIN
from ..utils import build_device_info
Expand Down Expand Up @@ -146,6 +149,11 @@ def __init__(
self.updateTapo(entry["camData"])
LOGGER.debug(f"Tapo {name_suffix} - init - end")

@property
def available(self) -> bool:
"""Return if the entity is available."""
return self._attr_native_value != STATE_UNAVAILABLE


class TapoButtonEntity(ButtonEntity, TapoEntity):
def __init__(
Expand Down

0 comments on commit 2c91a8b

Please sign in to comment.