mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Fix surepetcare sensor error (#143286)
* fix: changed boolean to map to 'online' attribute. * fix: added catch in case of future changes to prevent complete sensor failure. * fix: surepetcare - added additional catches in case rssi values aren't included in online status. * fix: remove hub_rssi when not defined. * fix: proper code spacing * fix: use .get for clarity instead of try. * fix: now written in Python. * fix: renamed variables for clarity. * Update homeassistant/components/surepetcare/binary_sensor.py * fix: update surepetcare test __init__.py mock_feeder with online status. --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
a783b6a0ab
commit
94b0800989
@ -133,12 +133,15 @@ class DeviceConnectivity(SurePetcareBinarySensor):
|
|||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _update_attr(self, surepy_entity: SurepyEntity) -> None:
|
def _update_attr(self, surepy_entity: SurepyEntity) -> None:
|
||||||
state = surepy_entity.raw_data()["status"]
|
state = surepy_entity.raw_data().get("status", {})
|
||||||
self._attr_is_on = bool(state)
|
online = bool(state.get("online", False))
|
||||||
if state:
|
self._attr_is_on = online
|
||||||
self._attr_extra_state_attributes = {
|
|
||||||
"device_rssi": f"{state['signal']['device_rssi']:.2f}",
|
|
||||||
"hub_rssi": f"{state['signal']['hub_rssi']:.2f}",
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
self._attr_extra_state_attributes = {}
|
self._attr_extra_state_attributes = {}
|
||||||
|
if online:
|
||||||
|
device_rssi = state.get("signal", {}).get("device_rssi")
|
||||||
|
self._attr_extra_state_attributes["device_rssi"] = (
|
||||||
|
f"{device_rssi:.2f}" if device_rssi else "Unknown"
|
||||||
|
)
|
||||||
|
hub_rssi = state.get("signal", {}).get("hub_rssi")
|
||||||
|
if hub_rssi is not None:
|
||||||
|
self._attr_extra_state_attributes["hub_rssi"] = f"{hub_rssi:.2f}"
|
||||||
|
@ -8,7 +8,11 @@ MOCK_HUB = {
|
|||||||
"product_id": 1,
|
"product_id": 1,
|
||||||
"household_id": HOUSEHOLD_ID,
|
"household_id": HOUSEHOLD_ID,
|
||||||
"name": "Hub",
|
"name": "Hub",
|
||||||
"status": {"online": True, "led_mode": 0, "pairing_mode": 0},
|
"status": {
|
||||||
|
"led_mode": 0,
|
||||||
|
"pairing_mode": 0,
|
||||||
|
"online": True,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_FEEDER = {
|
MOCK_FEEDER = {
|
||||||
@ -22,6 +26,7 @@ MOCK_FEEDER = {
|
|||||||
"locking": {"mode": 0},
|
"locking": {"mode": 0},
|
||||||
"learn_mode": 0,
|
"learn_mode": 0,
|
||||||
"signal": {"device_rssi": 60, "hub_rssi": 65},
|
"signal": {"device_rssi": 60, "hub_rssi": 65},
|
||||||
|
"online": True,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user