Skip to content

Commit

Permalink
Fix zha illuminance measured value mapping (#108547)
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankisser authored Jan 21, 2024
1 parent 3c6e7b1 commit b5bb97c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion homeassistant/components/zha/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,12 @@ class Illuminance(Sensor):
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = LIGHT_LUX

def formatter(self, value: int) -> int:
def formatter(self, value: int) -> int | None:
"""Convert illumination data."""
if value == 0:
return 0
if value == 0xFFFF:
return None
return round(pow(10, ((value - 1) / 10000)))


Expand Down
6 changes: 6 additions & 0 deletions tests/components/zha/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ async def async_test_illuminance(hass, cluster, entity_id):
await send_attributes_report(hass, cluster, {1: 1, 0: 10, 2: 20})
assert_state(hass, entity_id, "1", LIGHT_LUX)

await send_attributes_report(hass, cluster, {1: 0, 0: 0, 2: 20})
assert_state(hass, entity_id, "0", LIGHT_LUX)

await send_attributes_report(hass, cluster, {1: 0, 0: 0xFFFF, 2: 20})
assert_state(hass, entity_id, "unknown", LIGHT_LUX)


async def async_test_metering(hass, cluster, entity_id):
"""Test Smart Energy metering sensor."""
Expand Down

0 comments on commit b5bb97c

Please sign in to comment.