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
12 changes: 6 additions & 6 deletions homeassistant/components/homekit/type_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, *args):
def async_update_state(self, new_state):
"""Update temperature after state changed."""
unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS)
if temperature := convert_to_float(new_state.state):
if (temperature := convert_to_float(new_state.state)) is not None:
temperature = temperature_to_homekit(temperature, unit)
self.char_temp.set_value(temperature)
_LOGGER.debug(
Expand All @@ -144,7 +144,7 @@ def __init__(self, *args):
@callback
def async_update_state(self, new_state):
"""Update accessory after state change."""
if humidity := convert_to_float(new_state.state):
if (humidity := convert_to_float(new_state.state)) is not None:
self.char_humidity.set_value(humidity)
_LOGGER.debug("%s: Percent set to %d%%", self.entity_id, humidity)

Expand All @@ -171,7 +171,7 @@ def __init__(self, *args):
@callback
def async_update_state(self, new_state):
"""Update accessory after state change."""
if density := convert_to_float(new_state.state):
if (density := convert_to_float(new_state.state)) is not None:
if self.char_density.value != density:
self.char_density.set_value(density)
_LOGGER.debug("%s: Set density to %d", self.entity_id, density)
Expand Down Expand Up @@ -206,7 +206,7 @@ def __init__(self, *args):
@callback
def async_update_state(self, new_state):
"""Update accessory after state change."""
if value := convert_to_float(new_state.state):
if (value := convert_to_float(new_state.state)) is not None:
self.char_level.set_value(value)
if value > self.char_peak.value:
self.char_peak.set_value(value)
Expand Down Expand Up @@ -241,7 +241,7 @@ def __init__(self, *args):
@callback
def async_update_state(self, new_state):
"""Update accessory after state change."""
if value := convert_to_float(new_state.state):
if (value := convert_to_float(new_state.state)) is not None:
self.char_level.set_value(value)
if value > self.char_peak.value:
self.char_peak.set_value(value)
Expand Down Expand Up @@ -269,7 +269,7 @@ def __init__(self, *args):
@callback
def async_update_state(self, new_state):
"""Update accessory after state change."""
if luminance := convert_to_float(new_state.state):
if (luminance := convert_to_float(new_state.state)) is not None:
self.char_light.set_value(luminance)
_LOGGER.debug("%s: Set to %d", self.entity_id, luminance)

Expand Down
12 changes: 12 additions & 0 deletions tests/components/homekit/test_type_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ async def test_temperature(hass, hk_driver):
await hass.async_block_till_done()
assert acc.char_temp.value == 20

hass.states.async_set(entity_id, "0", {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
await hass.async_block_till_done()
assert acc.char_temp.value == 0

hass.states.async_set(
entity_id, "75.2", {ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT}
)
Expand Down Expand Up @@ -91,6 +95,10 @@ async def test_humidity(hass, hk_driver):
await hass.async_block_till_done()
assert acc.char_humidity.value == 20

hass.states.async_set(entity_id, "0")
await hass.async_block_till_done()
assert acc.char_humidity.value == 0


async def test_air_quality(hass, hk_driver):
"""Test if accessory is updated after state change."""
Expand Down Expand Up @@ -227,6 +235,10 @@ async def test_light(hass, hk_driver):
await hass.async_block_till_done()
assert acc.char_light.value == 300

hass.states.async_set(entity_id, "0")
await hass.async_block_till_done()
assert acc.char_light.value == 0.0001


async def test_binary(hass, hk_driver):
"""Test if accessory is updated after state change."""
Expand Down