Skip to content

Add AnalogInput sensor, use description attribute for fallback_name #197

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

Merged
merged 50 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
fb7e071
Use description attribute for fallback_name
prairiesnpr Sep 7, 2024
abdd5c6
Update AnalogIn, MultistateIn, and BinIn CL Handlers
prairiesnpr Sep 7, 2024
86003fe
Register AnalogInput as Sensor
prairiesnpr Sep 7, 2024
2c3a9d9
Add MultistateInput and AnalogInput Sensor
prairiesnpr Sep 7, 2024
7c803b8
Add Binary Sensor Test
prairiesnpr Sep 7, 2024
fa4e91c
Add Sensor - General test
prairiesnpr Sep 7, 2024
75bb500
Remove xbee AI, Update Dev Sig
prairiesnpr Sep 7, 2024
efb6c06
The empty enum is required
prairiesnpr Sep 8, 2024
aaf6ad0
Clean up Multistate Input, better tests
prairiesnpr Sep 9, 2024
831442b
cp errors
prairiesnpr Sep 10, 2024
1d0f706
Remove constants, update tests and Analog Input
prairiesnpr Sep 17, 2024
ab1e9d9
Remove changed device signatures
prairiesnpr Sep 25, 2024
bd34bfd
Update tests due to upsteam changes
prairiesnpr Oct 4, 2024
4dd2e05
Merge remote-tracking branch 'origin' into use_description_attr
prairiesnpr Oct 18, 2024
2fffecc
Merge branch 'dev' into use_description_attr
prairiesnpr Oct 19, 2024
93f54ad
Merge branch 'dev' into use_description_attr
prairiesnpr Oct 25, 2024
1c30930
Merge branch 'dev' into use_description_attr
prairiesnpr Nov 2, 2024
a9704b5
Merge branch 'zigpy:dev' into use_description_attr
prairiesnpr Nov 9, 2024
b43e578
Merge branch 'zigpy:dev' into use_description_attr
prairiesnpr Nov 27, 2024
259284f
Update tests.
prairiesnpr Nov 27, 2024
5215228
Merge branch 'dev' into use_description_attr
prairiesnpr Dec 7, 2024
3a9f79e
Merge branch 'dev' into use_description_attr
prairiesnpr Dec 24, 2024
5b17d66
Merge branch 'zigpy:dev' into use_description_attr
prairiesnpr Jan 4, 2025
f746e21
Merge branch 'dev' into use_description_attr
prairiesnpr Jan 5, 2025
c93a9a5
Merge branch 'dev' into use_description_attr
prairiesnpr Jan 17, 2025
d2d3c16
Revert "Remove changed device signatures"
puddly Jan 17, 2025
193ebdc
Merge branch 'dev' into use_description_attr
puddly Apr 24, 2025
7cdfdca
Clean up analog input handling
puddly Apr 25, 2025
dfa0374
Fix up multistate input
puddly Apr 25, 2025
a98785a
Fix up binary input
puddly Apr 25, 2025
f1057d0
Regenerate diagnostics (unaffected)
puddly Apr 25, 2025
94cf488
Regenerate diagnostics (affected)
puddly Apr 25, 2025
519f6c0
Redo the BACnet units
puddly Apr 26, 2025
9ee428b
Fix formatting for multistate input sensor
puddly Apr 26, 2025
9fca8c1
Add fallback name to analog input sensor
puddly Apr 26, 2025
eba23d3
Remove apptype unit conversions
puddly Apr 26, 2025
a2354ec
Fix app type conversion
puddly Apr 26, 2025
3b21131
Fix unit tests
puddly Apr 26, 2025
fe3a7e7
Merge branch 'dev' into use_description_attr
puddly Apr 29, 2025
3c6dff3
Regenerate diagnostics
puddly Apr 29, 2025
cbcd964
Merge branch 'dev' into use_description_attr
puddly Apr 29, 2025
521c904
Merge branch 'dev' into use_description_attr
puddly May 1, 2025
5e0ff63
Remove multistate input, for now
puddly May 1, 2025
929d473
Regenerate diagnostics
puddly May 1, 2025
0e12c74
New algorithm for resolution to decimal precision
puddly May 2, 2025
876264c
Use parent class implementation of formatter for `EnumSensor`
puddly May 2, 2025
969fa50
Bring up test coverage
puddly May 2, 2025
b0dc46e
Remove multistate cluster handler definitions, for now
puddly May 2, 2025
7fa8420
Revert `options` in info object
puddly May 2, 2025
1639dd1
Revert behavior of `EnumSensor` returning `None`
puddly May 2, 2025
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
59 changes: 57 additions & 2 deletions tests/data/devices/espressif-zigbeeanalogdevice.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,12 @@
"number": [
{
"info_object": {
"fallback_name": null,
"fallback_name": "Fan Speed (RPM)",
"unique_id": "ab:cd:ef:12:39:a2:73:55-1-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -650,6 +650,61 @@
"available": true,
"state": null
}
},
{
"info_object": {
"fallback_name": "Power Consumption (Watts)",
"unique_id": "ab:cd:ef:12:39:a2:73:55-1-12-analog_input",
"migrate_unique_ids": [],
"platform": "sensor",
"class_name": "AnalogInputSensor",
"translation_key": null,
"device_class": "power",
"state_class": "measurement",
"entity_category": null,
"entity_registry_enabled_default": true,
"enabled": true,
"primary": false,
"cluster_handlers": [
{
"class_name": "AnalogInputClusterHandler",
"generic_id": "cluster_handler_0x000c",
"endpoint_id": 1,
"cluster": {
"id": 12,
"name": "AnalogInput",
"type": "server"
},
"id": "1:0x000c",
"unique_id": "ab:cd:ef:12:39:a2:73:55:1:0x000c",
"status": "INITIALIZED",
"value_attribute": "present_value"
}
],
"device_ieee": [
85,
115,
162,
57,
18,
239,
205,
171
],
"endpoint_id": 1,
"available": true,
"group_id": null,
"attribute": "present_value",
"suggested_display_precision": null,
"divisor": 1,
"multiplier": 1,
"unit": "W"
},
"state": {
"class_name": "AnalogInputSensor",
"available": true,
"state": 280.0
}
}
]
},
Expand Down
8 changes: 4 additions & 4 deletions tests/data/devices/isilentllc-dog-feeder.json
Original file line number Diff line number Diff line change
Expand Up @@ -965,12 +965,12 @@
"binary_sensor": [
{
"info_object": {
"fallback_name": null,
"fallback_name": "Jammed",
"unique_id": "00:13:a2:00:41:67:1f:d7-1-15",
"migrate_unique_ids": [],
"platform": "binary_sensor",
"class_name": "BinaryInput",
"translation_key": "binary_input",
"class_name": "BinaryInputWithDescription",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -1009,7 +1009,7 @@
"attribute_name": "present_value"
},
"state": {
"class_name": "BinaryInput",
"class_name": "BinaryInputWithDescription",
"available": true,
"state": false
}
Expand Down
28 changes: 14 additions & 14 deletions tests/data/devices/tze200-2aaelwxk-ts0225.json
Original file line number Diff line number Diff line change
Expand Up @@ -1874,12 +1874,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "fading_time",
"unique_id": "ab:cd:ef:12:94:85:f7:5f-2-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Comment on lines 1876 to 1885
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a note: These entities shouldn't be present anymore.

We've replaced these AnalogOutput config entities for a lot of Tuya sensors with proper quirks v2 entities.
However, they'll still be in the zigpy attribute cache, until the device is re-paired.

I thought that the quirks v1 signature/replacement shouldn't persist to the database, but I remember we've had that issue at one point, so the quirked signature might be stuck in the database, or these were saved when the v1 quirks were still present and the regeneration of diagnostics just looked at the quirked signature and not the original signature?

We might wanna add a .removes(AnalogInput.cluster_id, endpoint_id=xx) to a whole lot of Tuya quirks for the various fake config entities that were added in the past...
Assuming these entities are still "provided" (but non-functional) for real users.

Expand Down Expand Up @@ -1929,12 +1929,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "large_sensitivity",
"unique_id": "ab:cd:ef:12:94:85:f7:5f-3-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -1984,12 +1984,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "large_distance",
"unique_id": "ab:cd:ef:12:94:85:f7:5f-4-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2039,12 +2039,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "small_sensitivity",
"unique_id": "ab:cd:ef:12:94:85:f7:5f-5-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2094,12 +2094,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "small_distance",
"unique_id": "ab:cd:ef:12:94:85:f7:5f-6-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2149,12 +2149,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "static_sensitivity",
"unique_id": "ab:cd:ef:12:94:85:f7:5f-7-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2204,12 +2204,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "static_distance",
"unique_id": "ab:cd:ef:12:94:85:f7:5f-8-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down
75 changes: 65 additions & 10 deletions tests/data/devices/tze204-iaeejhvf-ts0601.json
Original file line number Diff line number Diff line change
Expand Up @@ -1461,12 +1461,12 @@
"number": [
{
"info_object": {
"fallback_name": null,
"fallback_name": "Sensitivity",
"unique_id": "ab:cd:ef:12:52:88:1c:b0-1-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2002,12 +2002,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "Min range",
"unique_id": "ab:cd:ef:12:52:88:1c:b0-2-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2057,12 +2057,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "Max range",
"unique_id": "ab:cd:ef:12:52:88:1c:b0-3-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2112,12 +2112,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "Detection delay",
"unique_id": "ab:cd:ef:12:52:88:1c:b0-4-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2167,12 +2167,12 @@
},
{
"info_object": {
"fallback_name": null,
"fallback_name": "Fading time",
"unique_id": "ab:cd:ef:12:52:88:1c:b0-5-13",
"migrate_unique_ids": [],
"platform": "number",
"class_name": "Number",
"translation_key": "number",
"translation_key": null,
"device_class": null,
"state_class": null,
"entity_category": null,
Expand Down Expand Up @@ -2666,6 +2666,61 @@
"state": 768
}
},
{
"info_object": {
"fallback_name": "Target distance",
"unique_id": "ab:cd:ef:12:52:88:1c:b0-1-12-analog_input",
"migrate_unique_ids": [],
"platform": "sensor",
"class_name": "AnalogInputSensor",
"translation_key": null,
"device_class": null,
"state_class": "measurement",
"entity_category": null,
"entity_registry_enabled_default": true,
"enabled": true,
"primary": false,
"cluster_handlers": [
{
"class_name": "AnalogInputClusterHandler",
"generic_id": "cluster_handler_0x000c",
"endpoint_id": 1,
"cluster": {
"id": 12,
"name": "AnalogInput",
"type": "server"
},
"id": "1:0x000c",
"unique_id": "ab:cd:ef:12:52:88:1c:b0:1:0x000c",
"status": "INITIALIZED",
"value_attribute": "present_value"
}
],
"device_ieee": [
176,
28,
136,
82,
18,
239,
205,
171
],
"endpoint_id": 1,
"available": true,
"group_id": null,
"attribute": "present_value",
"suggested_display_precision": null,
"divisor": 1,
"multiplier": 1,
"unit": "m"
},
"state": {
"class_name": "AnalogInputSensor",
"available": true,
"state": 0.0
}
},
{
"info_object": {
"fallback_name": "Target distance",
Expand Down
30 changes: 30 additions & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
}
}

DEVICE_GENERAL = {
1: {
SIG_EP_PROFILE: zigpy.profiles.zha.PROFILE_ID,
SIG_EP_TYPE: zigpy.profiles.zha.DeviceType.ON_OFF_SENSOR,
SIG_EP_INPUT: [general.BinaryInput.cluster_id],
SIG_EP_OUTPUT: [],
}
}

DEVICE_SMARTTHINGS_MULTI = {
1: {
Expand Down Expand Up @@ -172,13 +180,35 @@ async def test_binary_sensor(
assert entity is not None
assert isinstance(entity, entity_type)
assert entity.PLATFORM == Platform.BINARY_SENSOR

assert entity.fallback_name is None
assert entity.is_on is False

# test getting messages that trigger and reset the sensors
cluster = getattr(zigpy_device.endpoints[1], cluster_name)
await on_off_test(zha_gateway, cluster, entity, plugs)


async def test_binary_sensor_general(
zha_gateway: Gateway,
) -> None:
"""Test binary sensor general - description."""
zigpy_device = create_mock_zigpy_device(
zha_gateway, DEVICE_GENERAL, manufacturer="DevManuf", model="DevModel"
)

cluster = getattr(zigpy_device.endpoints[1], "binary_input")
cluster.PLUGGED_ATTR_READS = {"description": "Binary Input", "present_value": 1}
update_attribute_cache(cluster)
zha_device = await join_zigpy_device(zha_gateway, zigpy_device)
entity: PlatformEntity = find_entity(zha_device, Platform.BINARY_SENSOR)

await entity.async_update()
await zha_gateway.async_block_till_done()
assert entity.fallback_name == "Binary Input"
assert entity.translation_key is None


async def test_smarttthings_multi(
zha_gateway: Gateway,
) -> None:
Expand Down
Loading
Loading