diff --git a/homeassistant/components/onewire/binary_sensor.py b/homeassistant/components/onewire/binary_sensor.py index e7e30588f8a..5cd3fa65a60 100644 --- a/homeassistant/components/onewire/binary_sensor.py +++ b/homeassistant/components/onewire/binary_sensor.py @@ -143,6 +143,8 @@ class OneWireBinarySensor(OneWireEntity, BinarySensorEntity): entity_description: OneWireBinarySensorEntityDescription @property - def is_on(self) -> bool: + def is_on(self) -> bool | None: """Return true if sensor is on.""" + if self._state is None: + return None return bool(self._state) diff --git a/homeassistant/components/onewire/switch.py b/homeassistant/components/onewire/switch.py index 00a3f8f65f4..c63198ccf05 100644 --- a/homeassistant/components/onewire/switch.py +++ b/homeassistant/components/onewire/switch.py @@ -204,8 +204,10 @@ class OneWireSwitch(OneWireEntity, SwitchEntity): entity_description: OneWireSwitchEntityDescription @property - def is_on(self) -> bool: - """Return true if sensor is on.""" + def is_on(self) -> bool | None: + """Return true if switch is on.""" + if self._state is None: + return None return bool(self._state) def turn_on(self, **kwargs: Any) -> None: diff --git a/tests/components/onewire/const.py b/tests/components/onewire/const.py index 3da37a72459..cb9fca54f3d 100644 --- a/tests/components/onewire/const.py +++ b/tests/components/onewire/const.py @@ -155,7 +155,9 @@ MOCK_OWPROXY_DEVICES = { {ATTR_INJECT_READS: b" 1"}, {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"}, @@ -165,7 +167,9 @@ MOCK_OWPROXY_DEVICES = { {ATTR_INJECT_READS: b" 1"}, {ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 1"}, - {ATTR_INJECT_READS: b" 0"}, + { + ATTR_INJECT_READS: ProtocolError, + }, {ATTR_INJECT_READS: b" 1"}, {ATTR_INJECT_READS: b" 0"}, {ATTR_INJECT_READS: b" 1"}, diff --git a/tests/components/onewire/snapshots/test_binary_sensor.ambr b/tests/components/onewire/snapshots/test_binary_sensor.ambr index 2aa415f0345..0523c969ade 100644 --- a/tests/components/onewire/snapshots/test_binary_sensor.ambr +++ b/tests/components/onewire/snapshots/test_binary_sensor.ambr @@ -851,13 +851,13 @@ 'attributes': ReadOnlyDict({ 'device_file': '/29.111111111111/sensed.3', 'friendly_name': '29.111111111111 Sensed 3', - 'raw_value': 0.0, + 'raw_value': None, }), 'context': , 'entity_id': 'binary_sensor.29_111111111111_sensed_3', 'last_changed': , 'last_updated': , - 'state': 'off', + 'state': 'unknown', }), StateSnapshot({ 'attributes': ReadOnlyDict({ diff --git a/tests/components/onewire/snapshots/test_switch.ambr b/tests/components/onewire/snapshots/test_switch.ambr index 8fbb977948b..4f6498419a9 100644 --- a/tests/components/onewire/snapshots/test_switch.ambr +++ b/tests/components/onewire/snapshots/test_switch.ambr @@ -1271,13 +1271,13 @@ 'attributes': ReadOnlyDict({ 'device_file': '/29.111111111111/PIO.3', 'friendly_name': '29.111111111111 Programmed input-output 3', - 'raw_value': 0.0, + 'raw_value': None, }), 'context': , 'entity_id': 'switch.29_111111111111_programmed_input_output_3', 'last_changed': , 'last_updated': , - 'state': 'off', + 'state': 'unknown', }), StateSnapshot({ 'attributes': ReadOnlyDict({