From 0287889de9026ca185ad7f839009b510cbaf8070 Mon Sep 17 00:00:00 2001 From: Seb Ruiz Date: Fri, 30 Apr 2021 08:07:27 +1000 Subject: [PATCH] Don't create battery sensors for devices which do not report a battery state. Fixes #61 --- custom_components/bhyve/sensor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/bhyve/sensor.py b/custom_components/bhyve/sensor.py index 07a7c86..7a46f94 100644 --- a/custom_components/bhyve/sensor.py +++ b/custom_components/bhyve/sensor.py @@ -34,11 +34,13 @@ async def async_setup_platform(hass, config, async_add_entities, _discovery_info devices = await bhyve.devices for device in devices: if device.get("type") == DEVICE_SPRINKLER: - sensors.append(BHyveBatterySensor(hass, bhyve, device)) sensors.append(BHyveStateSensor(hass, bhyve, device)) for zone in device.get("zones"): sensors.append(BHyveZoneHistorySensor(hass, bhyve, device, zone)) + if device.get("battery", None) is not None: + sensors.append(BHyveBatterySensor(hass, bhyve, device)) + async_add_entities(sensors, True)