From 74647e1fa862fcc537494fa384550a5d2c4d1448 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 10 Feb 2021 16:30:16 +0100 Subject: [PATCH] Add guards for missing value in binary_sensor platform of zwave_js integration (#46293) --- homeassistant/components/zwave_js/binary_sensor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/zwave_js/binary_sensor.py b/homeassistant/components/zwave_js/binary_sensor.py index 8a483c34e12..8c56869449a 100644 --- a/homeassistant/components/zwave_js/binary_sensor.py +++ b/homeassistant/components/zwave_js/binary_sensor.py @@ -268,8 +268,10 @@ class ZWaveBooleanBinarySensor(ZWaveBaseEntity, BinarySensorEntity): self._name = self.generate_name(include_value_name=True) @property - def is_on(self) -> bool: + def is_on(self) -> Optional[bool]: """Return if the sensor is on or off.""" + if self.info.primary_value.value is None: + return None return bool(self.info.primary_value.value) @property @@ -312,8 +314,10 @@ class ZWaveNotificationBinarySensor(ZWaveBaseEntity, BinarySensorEntity): self._mapping_info = self._get_sensor_mapping() @property - def is_on(self) -> bool: + def is_on(self) -> Optional[bool]: """Return if the sensor is on or off.""" + if self.info.primary_value.value is None: + return None return int(self.info.primary_value.value) == int(self.state_key) @property @@ -361,8 +365,10 @@ class ZWavePropertyBinarySensor(ZWaveBaseEntity, BinarySensorEntity): self._name = self.generate_name(include_value_name=True) @property - def is_on(self) -> bool: + def is_on(self) -> Optional[bool]: """Return if the sensor is on or off.""" + if self.info.primary_value.value is None: + return None return self.info.primary_value.value in self._mapping_info["on_states"] @property