Fix unknown values in onewire (#113731)

* Fix unknown values in onewire

* Update tests
pull/113973/head
epenet 2024-03-18 10:12:46 +01:00 committed by Paulus Schoutsen
parent 6859bae0b1
commit 33678ff5a4
5 changed files with 17 additions and 9 deletions

View File

@ -143,6 +143,8 @@ class OneWireBinarySensor(OneWireEntity, BinarySensorEntity):
entity_description: OneWireBinarySensorEntityDescription entity_description: OneWireBinarySensorEntityDescription
@property @property
def is_on(self) -> bool: def is_on(self) -> bool | None:
"""Return true if sensor is on.""" """Return true if sensor is on."""
if self._state is None:
return None
return bool(self._state) return bool(self._state)

View File

@ -204,8 +204,10 @@ class OneWireSwitch(OneWireEntity, SwitchEntity):
entity_description: OneWireSwitchEntityDescription entity_description: OneWireSwitchEntityDescription
@property @property
def is_on(self) -> bool: def is_on(self) -> bool | None:
"""Return true if sensor is on.""" """Return true if switch is on."""
if self._state is None:
return None
return bool(self._state) return bool(self._state)
def turn_on(self, **kwargs: Any) -> None: def turn_on(self, **kwargs: Any) -> None:

View File

@ -155,7 +155,9 @@ MOCK_OWPROXY_DEVICES = {
{ATTR_INJECT_READS: b" 1"}, {ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 0"}, {
ATTR_INJECT_READS: ProtocolError,
},
{ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 0"},
@ -165,7 +167,9 @@ MOCK_OWPROXY_DEVICES = {
{ATTR_INJECT_READS: b" 1"}, {ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 1"}, {ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"}, {
ATTR_INJECT_READS: ProtocolError,
},
{ATTR_INJECT_READS: b" 1"}, {ATTR_INJECT_READS: b" 1"},
{ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 0"},
{ATTR_INJECT_READS: b" 1"}, {ATTR_INJECT_READS: b" 1"},

View File

@ -851,13 +851,13 @@
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'device_file': '/29.111111111111/sensed.3', 'device_file': '/29.111111111111/sensed.3',
'friendly_name': '29.111111111111 Sensed 3', 'friendly_name': '29.111111111111 Sensed 3',
'raw_value': 0.0, 'raw_value': None,
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'binary_sensor.29_111111111111_sensed_3', 'entity_id': 'binary_sensor.29_111111111111_sensed_3',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'off', 'state': 'unknown',
}), }),
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({

View File

@ -1271,13 +1271,13 @@
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({
'device_file': '/29.111111111111/PIO.3', 'device_file': '/29.111111111111/PIO.3',
'friendly_name': '29.111111111111 Programmed input-output 3', 'friendly_name': '29.111111111111 Programmed input-output 3',
'raw_value': 0.0, 'raw_value': None,
}), }),
'context': <ANY>, 'context': <ANY>,
'entity_id': 'switch.29_111111111111_programmed_input_output_3', 'entity_id': 'switch.29_111111111111_programmed_input_output_3',
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': 'off', 'state': 'unknown',
}), }),
StateSnapshot({ StateSnapshot({
'attributes': ReadOnlyDict({ 'attributes': ReadOnlyDict({