Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/onewire/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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)
6 changes: 4 additions & 2 deletions homeassistant/components/onewire/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,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:
Expand Down
8 changes: 6 additions & 2 deletions tests/components/onewire/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@
{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"},
Expand All @@ -166,7 +168,9 @@
{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"},
Expand Down
4 changes: 2 additions & 2 deletions tests/components/onewire/snapshots/test_binary_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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': <ANY>,
'entity_id': 'binary_sensor.29_111111111111_sensed_3',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'off',
'state': 'unknown',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
Expand Down
4 changes: 2 additions & 2 deletions tests/components/onewire/snapshots/test_switch.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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': <ANY>,
'entity_id': 'switch.29_111111111111_programmed_input_output_3',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'off',
'state': 'unknown',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
Expand Down