From 486c068111ca9f7ea81e99faa5f1adb35b338af9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 7 Feb 2022 14:06:40 +0100 Subject: [PATCH] Allow None on Renault binary sensors (#65997) * Enable None on renault binary sensors * Adjust tests Co-authored-by: epenet --- homeassistant/components/renault/binary_sensor.py | 7 +++---- tests/components/renault/test_binary_sensor.py | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/renault/binary_sensor.py b/homeassistant/components/renault/binary_sensor.py index c2ebdb5cb0f50c..ec8ca77bded49f 100644 --- a/homeassistant/components/renault/binary_sensor.py +++ b/homeassistant/components/renault/binary_sensor.py @@ -64,10 +64,9 @@ class RenaultBinarySensor( @property def is_on(self) -> bool | None: """Return true if the binary sensor is on.""" - return ( - self._get_data_attr(self.entity_description.on_key) - == self.entity_description.on_value - ) + if (data := self._get_data_attr(self.entity_description.on_key)) is None: + return None + return data == self.entity_description.on_value BINARY_SENSOR_TYPES: tuple[RenaultBinarySensorEntityDescription, ...] = ( diff --git a/tests/components/renault/test_binary_sensor.py b/tests/components/renault/test_binary_sensor.py index 0a2460edca14a3..feef06746bd20c 100644 --- a/tests/components/renault/test_binary_sensor.py +++ b/tests/components/renault/test_binary_sensor.py @@ -4,7 +4,7 @@ import pytest from homeassistant.config_entries import ConfigEntry -from homeassistant.const import STATE_OFF, Platform +from homeassistant.const import STATE_UNKNOWN, Platform from homeassistant.core import HomeAssistant from . import ( @@ -63,7 +63,7 @@ async def test_binary_sensor_empty( expected_entities = mock_vehicle[Platform.BINARY_SENSOR] assert len(entity_registry.entities) == len(expected_entities) - check_entities_no_data(hass, entity_registry, expected_entities, STATE_OFF) + check_entities_no_data(hass, entity_registry, expected_entities, STATE_UNKNOWN) @pytest.mark.usefixtures("fixtures_with_invalid_upstream_exception")