Skip to content
Snippets Groups Projects
Unverified Commit b5bb97c8 authored by Florian Kisser's avatar Florian Kisser Committed by GitHub
Browse files

Fix zha illuminance measured value mapping (#108547)

parent 3c6e7b18
No related branches found
No related tags found
No related merge requests found
...@@ -483,8 +483,12 @@ class Illuminance(Sensor): ...@@ -483,8 +483,12 @@ class Illuminance(Sensor):
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT _attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = LIGHT_LUX _attr_native_unit_of_measurement = LIGHT_LUX
def formatter(self, value: int) -> int: def formatter(self, value: int) -> int | None:
"""Convert illumination data.""" """Convert illumination data."""
if value == 0:
return 0
if value == 0xFFFF:
return None
return round(pow(10, ((value - 1) / 10000))) return round(pow(10, ((value - 1) / 10000)))
......
...@@ -136,6 +136,12 @@ async def async_test_illuminance(hass, cluster, entity_id): ...@@ -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}) await send_attributes_report(hass, cluster, {1: 1, 0: 10, 2: 20})
assert_state(hass, entity_id, "1", LIGHT_LUX) 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): async def async_test_metering(hass, cluster, entity_id):
"""Test Smart Energy metering sensor.""" """Test Smart Energy metering sensor."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment