Skip to content

Commit d3e0d29

Browse files
authored
Update binary_sensor.py
Fix for home-assistant/core#143149 Thanks to @PineappleEmperor for the quick fix of the official surepetcare integration! 🙌 (home-assistant/core#143286)
1 parent af00c3e commit d3e0d29

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

custom_components/sureha/binary_sensor.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,17 @@ def extra_state_attributes(self) -> dict[str, Any]:
241241
attrs: dict[str, Any] = {}
242242

243243
if (device := self._coordinator.data[self._id]) and (
244-
state := device.raw_data().get("status")
245-
):
244+
state := device.raw_data().get("status", {})
245+
) and (bool(state.get("online", False))):
246+
device_rssi = state.get("signal", {}).get("device_rssi")
247+
self._attr_extra_state_attributes["device_rssi"] = f"{device_rssi:.2f}" if device_rssi else "Unknown"
248+
hub_rssi = state.get("signal", {}).get("hub_rssi")
249+
if hub_rssi is not None:
250+
self._attr_extra_state_attributes["hub_rssi"] = f"{hub_rssi:.2f}"
251+
246252
attrs = {
247-
"device_rssi": f'{state["signal"]["device_rssi"]:.2f}',
248-
"hub_rssi": f'{state["signal"]["hub_rssi"]:.2f}',
253+
"device_rssi": device_rssi,
254+
"hub_rssi": hub_rssi,
249255
}
250256

251257
return attrs

0 commit comments

Comments
 (0)