Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix illuminance formulas to actually reach 0 #3297

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: CI

on:
push:
branches:
- dev
- master
pull_request: ~

jobs:
Expand Down
15 changes: 5 additions & 10 deletions tests/test_xiaomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ async def test_xiaomi_p1_t1_motion_sensor(
# confirm illuminance report (with conversion)
assert len(illuminance_listener.attribute_updates) == 1
assert illuminance_listener.attribute_updates[0][0] == zcl_iilluminance_id
assert illuminance_listener.attribute_updates[0][1] == 10000 * math.log10(10) + 1
assert illuminance_listener.attribute_updates[0][1] == 10000 * math.log10(10 + 1)

# send invalid illuminance report 0xFFFF (and motion)
opple_cluster.update_attribute(274, 0xFFFF)
Expand All @@ -1204,7 +1204,7 @@ async def test_xiaomi_p1_t1_motion_sensor(
)
assert len(illuminance_listener.attribute_updates) == 3
assert illuminance_listener.attribute_updates[2][0] == zcl_iilluminance_id
assert illuminance_listener.attribute_updates[2][1] == 10000 * math.log10(20) + 1
assert illuminance_listener.attribute_updates[2][1] == 10000 * math.log10(20 + 1)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1299,7 +1299,7 @@ async def test_xiaomi_weather(
"1C5F11C10A01FF41210121DB0B03281F0421A8430521B60006240B000000000A21CA356410000B210800",
[
3100, # temperature
9031.899869919436, # illuminance
9542.42509439325, # illuminance
30.4, # battery voltage
154, # battery percent * 2
],
Expand Down Expand Up @@ -1578,13 +1578,8 @@ async def test_xiaomi_e1_driver_light_level(
assert len(illuminance_listener.attribute_updates) == 1
assert illuminance_listener.attribute_updates[0][0] == zcl_iilluminance_id

assert (
device_level == 0
and converted_level == 0
or (
illuminance_listener.attribute_updates[0][1]
== 10000 * math.log10(converted_level) + 1
)
assert illuminance_listener.attribute_updates[0][1] == 10000 * math.log10(
converted_level + 1
)


Expand Down
2 changes: 1 addition & 1 deletion zhaquirks/terncy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

def _update_attribute(self, attrid, value):
if attrid == self.ATTR_ID and value > 0:
value = 10000 * math.log10(value) + 1
value = 10000 * math.log10(value + 1)

Check warning on line 65 in zhaquirks/terncy/__init__.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/terncy/__init__.py#L65

Added line #L65 was not covered by tests
super()._update_attribute(attrid, value)


Expand Down
2 changes: 1 addition & 1 deletion zhaquirks/tuya/ts0601_illuminance.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TuyaIlluminanceCluster(TuyaMCUCluster):
TUYA_ILLUMINANCE_DP: DPToAttributeMapping(
TuyaIlluminanceMeasurement.ep_attribute,
"measured_value",
converter=lambda x: (10000.0 * math.log10(x) + 1.0 if x != 0 else 0),
converter=lambda x: 10000 * math.log10(x + 1),
),
}

Expand Down
2 changes: 1 addition & 1 deletion zhaquirks/tuya/ts0601_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class MmwRadarManufCluster(TuyaMCUCluster):
104: DPToAttributeMapping(
TuyaIlluminanceMeasurement.ep_attribute,
"measured_value",
lambda x: 10000 * math.log10(x) + 1 if x != 0 else 0,
lambda x: 10000 * math.log10(x + 1),
),
105: DPToAttributeMapping(
TuyaMCUCluster.ep_attribute,
Expand Down
2 changes: 1 addition & 1 deletion zhaquirks/xiaomi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ class IlluminanceMeasurementCluster(CustomCluster, IlluminanceMeasurement):

def _update_attribute(self, attrid, value):
if attrid == self.AttributeDefs.measured_value.id and value > 0:
value = 10000 * math.log10(value) + 1
value = 10000 * math.log10(value + 1)
super()._update_attribute(attrid, value)


Expand Down
Loading