Skip to content

Commit 37778b0

Browse files
prairiesnprpuddly
andauthored
Add AnalogInput, MultistateInput, use description attribute for fallback_name (#197)
* Use description attribute for fallback_name * Update AnalogIn, MultistateIn, and BinIn CL Handlers * Register AnalogInput as Sensor * Add MultistateInput and AnalogInput Sensor * Add Binary Sensor Test * Add Sensor - General test * Remove xbee AI, Update Dev Sig * The empty enum is required * Clean up Multistate Input, better tests * cp errors * Remove constants, update tests and Analog Input * Remove changed device signatures * Update tests due to upsteam changes * Update tests. * Revert "Remove changed device signatures" This reverts commit ab1e9d9. * Clean up analog input handling * Fix up multistate input * Fix up binary input * Regenerate diagnostics (unaffected) * Regenerate diagnostics (affected) * Redo the BACnet units * Fix formatting for multistate input sensor * Add fallback name to analog input sensor * Remove apptype unit conversions * Fix app type conversion * Fix unit tests * Regenerate diagnostics * Remove multistate input, for now * Regenerate diagnostics * New algorithm for resolution to decimal precision * Use parent class implementation of formatter for `EnumSensor` * Bring up test coverage * Remove multistate cluster handler definitions, for now * Revert `options` in info object * Revert behavior of `EnumSensor` returning `None` --------- Co-authored-by: puddly <[email protected]>
1 parent 4afffe1 commit 37778b0

18 files changed

+1306
-242
lines changed

tests/data/devices/espressif-zigbeeanalogdevice.json

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,12 @@
486486
"number": [
487487
{
488488
"info_object": {
489-
"fallback_name": null,
489+
"fallback_name": "Fan Speed (RPM)",
490490
"unique_id": "ab:cd:ef:12:39:a2:73:55-1-13",
491491
"migrate_unique_ids": [],
492492
"platform": "number",
493493
"class_name": "Number",
494-
"translation_key": "number",
494+
"translation_key": null,
495495
"device_class": null,
496496
"state_class": null,
497497
"entity_category": null,
@@ -650,6 +650,61 @@
650650
"available": true,
651651
"state": null
652652
}
653+
},
654+
{
655+
"info_object": {
656+
"fallback_name": "Power Consumption (Watts)",
657+
"unique_id": "ab:cd:ef:12:39:a2:73:55-1-12-analog_input",
658+
"migrate_unique_ids": [],
659+
"platform": "sensor",
660+
"class_name": "AnalogInputSensor",
661+
"translation_key": null,
662+
"device_class": "power",
663+
"state_class": "measurement",
664+
"entity_category": null,
665+
"entity_registry_enabled_default": true,
666+
"enabled": true,
667+
"primary": false,
668+
"cluster_handlers": [
669+
{
670+
"class_name": "AnalogInputClusterHandler",
671+
"generic_id": "cluster_handler_0x000c",
672+
"endpoint_id": 1,
673+
"cluster": {
674+
"id": 12,
675+
"name": "AnalogInput",
676+
"type": "server"
677+
},
678+
"id": "1:0x000c",
679+
"unique_id": "ab:cd:ef:12:39:a2:73:55:1:0x000c",
680+
"status": "INITIALIZED",
681+
"value_attribute": "present_value"
682+
}
683+
],
684+
"device_ieee": [
685+
85,
686+
115,
687+
162,
688+
57,
689+
18,
690+
239,
691+
205,
692+
171
693+
],
694+
"endpoint_id": 1,
695+
"available": true,
696+
"group_id": null,
697+
"attribute": "present_value",
698+
"suggested_display_precision": null,
699+
"divisor": 1,
700+
"multiplier": 1,
701+
"unit": "W"
702+
},
703+
"state": {
704+
"class_name": "AnalogInputSensor",
705+
"available": true,
706+
"state": 280.0
707+
}
653708
}
654709
]
655710
},

tests/data/devices/isilentllc-dog-feeder.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,12 @@
965965
"binary_sensor": [
966966
{
967967
"info_object": {
968-
"fallback_name": null,
968+
"fallback_name": "Jammed",
969969
"unique_id": "00:13:a2:00:41:67:1f:d7-1-15",
970970
"migrate_unique_ids": [],
971971
"platform": "binary_sensor",
972-
"class_name": "BinaryInput",
973-
"translation_key": "binary_input",
972+
"class_name": "BinaryInputWithDescription",
973+
"translation_key": null,
974974
"device_class": null,
975975
"state_class": null,
976976
"entity_category": null,
@@ -1009,7 +1009,7 @@
10091009
"attribute_name": "present_value"
10101010
},
10111011
"state": {
1012-
"class_name": "BinaryInput",
1012+
"class_name": "BinaryInputWithDescription",
10131013
"available": true,
10141014
"state": false
10151015
}

tests/data/devices/tze200-2aaelwxk-ts0225.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,12 +1874,12 @@
18741874
},
18751875
{
18761876
"info_object": {
1877-
"fallback_name": null,
1877+
"fallback_name": "fading_time",
18781878
"unique_id": "ab:cd:ef:12:94:85:f7:5f-2-13",
18791879
"migrate_unique_ids": [],
18801880
"platform": "number",
18811881
"class_name": "Number",
1882-
"translation_key": "number",
1882+
"translation_key": null,
18831883
"device_class": null,
18841884
"state_class": null,
18851885
"entity_category": null,
@@ -1929,12 +1929,12 @@
19291929
},
19301930
{
19311931
"info_object": {
1932-
"fallback_name": null,
1932+
"fallback_name": "large_sensitivity",
19331933
"unique_id": "ab:cd:ef:12:94:85:f7:5f-3-13",
19341934
"migrate_unique_ids": [],
19351935
"platform": "number",
19361936
"class_name": "Number",
1937-
"translation_key": "number",
1937+
"translation_key": null,
19381938
"device_class": null,
19391939
"state_class": null,
19401940
"entity_category": null,
@@ -1984,12 +1984,12 @@
19841984
},
19851985
{
19861986
"info_object": {
1987-
"fallback_name": null,
1987+
"fallback_name": "large_distance",
19881988
"unique_id": "ab:cd:ef:12:94:85:f7:5f-4-13",
19891989
"migrate_unique_ids": [],
19901990
"platform": "number",
19911991
"class_name": "Number",
1992-
"translation_key": "number",
1992+
"translation_key": null,
19931993
"device_class": null,
19941994
"state_class": null,
19951995
"entity_category": null,
@@ -2039,12 +2039,12 @@
20392039
},
20402040
{
20412041
"info_object": {
2042-
"fallback_name": null,
2042+
"fallback_name": "small_sensitivity",
20432043
"unique_id": "ab:cd:ef:12:94:85:f7:5f-5-13",
20442044
"migrate_unique_ids": [],
20452045
"platform": "number",
20462046
"class_name": "Number",
2047-
"translation_key": "number",
2047+
"translation_key": null,
20482048
"device_class": null,
20492049
"state_class": null,
20502050
"entity_category": null,
@@ -2094,12 +2094,12 @@
20942094
},
20952095
{
20962096
"info_object": {
2097-
"fallback_name": null,
2097+
"fallback_name": "small_distance",
20982098
"unique_id": "ab:cd:ef:12:94:85:f7:5f-6-13",
20992099
"migrate_unique_ids": [],
21002100
"platform": "number",
21012101
"class_name": "Number",
2102-
"translation_key": "number",
2102+
"translation_key": null,
21032103
"device_class": null,
21042104
"state_class": null,
21052105
"entity_category": null,
@@ -2149,12 +2149,12 @@
21492149
},
21502150
{
21512151
"info_object": {
2152-
"fallback_name": null,
2152+
"fallback_name": "static_sensitivity",
21532153
"unique_id": "ab:cd:ef:12:94:85:f7:5f-7-13",
21542154
"migrate_unique_ids": [],
21552155
"platform": "number",
21562156
"class_name": "Number",
2157-
"translation_key": "number",
2157+
"translation_key": null,
21582158
"device_class": null,
21592159
"state_class": null,
21602160
"entity_category": null,
@@ -2204,12 +2204,12 @@
22042204
},
22052205
{
22062206
"info_object": {
2207-
"fallback_name": null,
2207+
"fallback_name": "static_distance",
22082208
"unique_id": "ab:cd:ef:12:94:85:f7:5f-8-13",
22092209
"migrate_unique_ids": [],
22102210
"platform": "number",
22112211
"class_name": "Number",
2212-
"translation_key": "number",
2212+
"translation_key": null,
22132213
"device_class": null,
22142214
"state_class": null,
22152215
"entity_category": null,

tests/data/devices/tze204-iaeejhvf-ts0601.json

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,12 +1461,12 @@
14611461
"number": [
14621462
{
14631463
"info_object": {
1464-
"fallback_name": null,
1464+
"fallback_name": "Sensitivity",
14651465
"unique_id": "ab:cd:ef:12:52:88:1c:b0-1-13",
14661466
"migrate_unique_ids": [],
14671467
"platform": "number",
14681468
"class_name": "Number",
1469-
"translation_key": "number",
1469+
"translation_key": null,
14701470
"device_class": null,
14711471
"state_class": null,
14721472
"entity_category": null,
@@ -2002,12 +2002,12 @@
20022002
},
20032003
{
20042004
"info_object": {
2005-
"fallback_name": null,
2005+
"fallback_name": "Min range",
20062006
"unique_id": "ab:cd:ef:12:52:88:1c:b0-2-13",
20072007
"migrate_unique_ids": [],
20082008
"platform": "number",
20092009
"class_name": "Number",
2010-
"translation_key": "number",
2010+
"translation_key": null,
20112011
"device_class": null,
20122012
"state_class": null,
20132013
"entity_category": null,
@@ -2057,12 +2057,12 @@
20572057
},
20582058
{
20592059
"info_object": {
2060-
"fallback_name": null,
2060+
"fallback_name": "Max range",
20612061
"unique_id": "ab:cd:ef:12:52:88:1c:b0-3-13",
20622062
"migrate_unique_ids": [],
20632063
"platform": "number",
20642064
"class_name": "Number",
2065-
"translation_key": "number",
2065+
"translation_key": null,
20662066
"device_class": null,
20672067
"state_class": null,
20682068
"entity_category": null,
@@ -2112,12 +2112,12 @@
21122112
},
21132113
{
21142114
"info_object": {
2115-
"fallback_name": null,
2115+
"fallback_name": "Detection delay",
21162116
"unique_id": "ab:cd:ef:12:52:88:1c:b0-4-13",
21172117
"migrate_unique_ids": [],
21182118
"platform": "number",
21192119
"class_name": "Number",
2120-
"translation_key": "number",
2120+
"translation_key": null,
21212121
"device_class": null,
21222122
"state_class": null,
21232123
"entity_category": null,
@@ -2167,12 +2167,12 @@
21672167
},
21682168
{
21692169
"info_object": {
2170-
"fallback_name": null,
2170+
"fallback_name": "Fading time",
21712171
"unique_id": "ab:cd:ef:12:52:88:1c:b0-5-13",
21722172
"migrate_unique_ids": [],
21732173
"platform": "number",
21742174
"class_name": "Number",
2175-
"translation_key": "number",
2175+
"translation_key": null,
21762176
"device_class": null,
21772177
"state_class": null,
21782178
"entity_category": null,
@@ -2666,6 +2666,61 @@
26662666
"state": 768
26672667
}
26682668
},
2669+
{
2670+
"info_object": {
2671+
"fallback_name": "Target distance",
2672+
"unique_id": "ab:cd:ef:12:52:88:1c:b0-1-12-analog_input",
2673+
"migrate_unique_ids": [],
2674+
"platform": "sensor",
2675+
"class_name": "AnalogInputSensor",
2676+
"translation_key": null,
2677+
"device_class": null,
2678+
"state_class": "measurement",
2679+
"entity_category": null,
2680+
"entity_registry_enabled_default": true,
2681+
"enabled": true,
2682+
"primary": false,
2683+
"cluster_handlers": [
2684+
{
2685+
"class_name": "AnalogInputClusterHandler",
2686+
"generic_id": "cluster_handler_0x000c",
2687+
"endpoint_id": 1,
2688+
"cluster": {
2689+
"id": 12,
2690+
"name": "AnalogInput",
2691+
"type": "server"
2692+
},
2693+
"id": "1:0x000c",
2694+
"unique_id": "ab:cd:ef:12:52:88:1c:b0:1:0x000c",
2695+
"status": "INITIALIZED",
2696+
"value_attribute": "present_value"
2697+
}
2698+
],
2699+
"device_ieee": [
2700+
176,
2701+
28,
2702+
136,
2703+
82,
2704+
18,
2705+
239,
2706+
205,
2707+
171
2708+
],
2709+
"endpoint_id": 1,
2710+
"available": true,
2711+
"group_id": null,
2712+
"attribute": "present_value",
2713+
"suggested_display_precision": null,
2714+
"divisor": 1,
2715+
"multiplier": 1,
2716+
"unit": "m"
2717+
},
2718+
"state": {
2719+
"class_name": "AnalogInputSensor",
2720+
"available": true,
2721+
"state": 0.0
2722+
}
2723+
},
26692724
{
26702725
"info_object": {
26712726
"fallback_name": "Target distance",

tests/test_binary_sensor.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
}
5454
}
5555

56+
DEVICE_GENERAL = {
57+
1: {
58+
SIG_EP_PROFILE: zigpy.profiles.zha.PROFILE_ID,
59+
SIG_EP_TYPE: zigpy.profiles.zha.DeviceType.ON_OFF_SENSOR,
60+
SIG_EP_INPUT: [general.BinaryInput.cluster_id],
61+
SIG_EP_OUTPUT: [],
62+
}
63+
}
5664

5765
DEVICE_SMARTTHINGS_MULTI = {
5866
1: {
@@ -172,13 +180,35 @@ async def test_binary_sensor(
172180
assert entity is not None
173181
assert isinstance(entity, entity_type)
174182
assert entity.PLATFORM == Platform.BINARY_SENSOR
183+
184+
assert entity.fallback_name is None
175185
assert entity.is_on is False
176186

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

181191

192+
async def test_binary_sensor_general(
193+
zha_gateway: Gateway,
194+
) -> None:
195+
"""Test binary sensor general - description."""
196+
zigpy_device = create_mock_zigpy_device(
197+
zha_gateway, DEVICE_GENERAL, manufacturer="DevManuf", model="DevModel"
198+
)
199+
200+
cluster = getattr(zigpy_device.endpoints[1], "binary_input")
201+
cluster.PLUGGED_ATTR_READS = {"description": "Binary Input", "present_value": 1}
202+
update_attribute_cache(cluster)
203+
zha_device = await join_zigpy_device(zha_gateway, zigpy_device)
204+
entity: PlatformEntity = find_entity(zha_device, Platform.BINARY_SENSOR)
205+
206+
await entity.async_update()
207+
await zha_gateway.async_block_till_done()
208+
assert entity.fallback_name == "Binary Input"
209+
assert entity.translation_key is None
210+
211+
182212
async def test_smarttthings_multi(
183213
zha_gateway: Gateway,
184214
) -> None:

0 commit comments

Comments
 (0)