@@ -63,14 +63,14 @@ common_utils.COLOR_TEMP_LIGHT_DEVICE_TYPE_ID = 0x010C
63
63
common_utils .EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID = 0x010D
64
64
common_utils .ON_OFF_PLUG_DEVICE_TYPE_ID = 0x010A
65
65
common_utils .DIMMABLE_PLUG_DEVICE_TYPE_ID = 0x010B
66
- common_utils .ON_OFF_SWITCH_ID = 0x0103
67
- common_utils .ON_OFF_DIMMER_SWITCH_ID = 0x0104
68
- common_utils .ON_OFF_COLOR_DIMMER_SWITCH_ID = 0x0105
69
- common_utils .MOUNTED_ON_OFF_CONTROL_ID = 0x010F
70
- common_utils .MOUNTED_DIMMABLE_LOAD_CONTROL_ID = 0x0110
71
- common_utils .GENERIC_SWITCH_ID = 0x000F
72
- common_utils .ELECTRICAL_SENSOR_ID = 0x0510
73
- common_utils .WATER_VALVE_ID = 0x0042
66
+ common_utils .ON_OFF_SWITCH_DEVICE_TYPE_ID = 0x0103
67
+ common_utils .ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID = 0x0104
68
+ common_utils .ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID = 0x0105
69
+ common_utils .MOUNTED_ON_OFF_CONTROL_DEVICE_TYPE_ID = 0x010F
70
+ common_utils .MOUNTED_DIMMABLE_LOAD_CONTROL_DEVICE_TYPE_ID = 0x0110
71
+ common_utils .GENERIC_SWITCH_DEVICE_TYPE_ID = 0x000F
72
+ common_utils .ELECTRICAL_SENSOR_DEVICE_TYPE_ID = 0x0510
73
+ common_utils .WATER_VALVE_DEVICE_TYPE_ID = 0x0042
74
74
75
75
common_utils .device_type_profile_map = {
76
76
[common_utils .ON_OFF_LIGHT_DEVICE_TYPE_ID ] = " light-binary" ,
@@ -79,14 +79,14 @@ common_utils.device_type_profile_map = {
79
79
[common_utils .EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID ] = " light-color-level" ,
80
80
[common_utils .ON_OFF_PLUG_DEVICE_TYPE_ID ] = " plug-binary" ,
81
81
[common_utils .DIMMABLE_PLUG_DEVICE_TYPE_ID ] = " plug-level" ,
82
- [common_utils .ON_OFF_SWITCH_ID ] = " switch-binary" ,
83
- [common_utils .ON_OFF_DIMMER_SWITCH_ID ] = " switch-level" ,
84
- [common_utils .ON_OFF_COLOR_DIMMER_SWITCH_ID ] = " switch-color-level" ,
85
- [common_utils .MOUNTED_ON_OFF_CONTROL_ID ] = " switch-binary" ,
86
- [common_utils .MOUNTED_DIMMABLE_LOAD_CONTROL_ID ] = " switch-level" ,
82
+ [common_utils .ON_OFF_SWITCH_DEVICE_TYPE_ID ] = " switch-binary" ,
83
+ [common_utils .ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID ] = " switch-level" ,
84
+ [common_utils .ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID ] = " switch-color-level" ,
85
+ [common_utils .MOUNTED_ON_OFF_CONTROL_DEVICE_TYPE_ID ] = " switch-binary" ,
86
+ [common_utils .MOUNTED_DIMMABLE_LOAD_CONTROL_DEVICE_TYPE_ID ] = " switch-level" ,
87
87
}
88
88
89
- common_utils . device_type_attribute_map = {
89
+ local device_type_attribute_map = {
90
90
[common_utils .ON_OFF_LIGHT_DEVICE_TYPE_ID ] = {
91
91
clusters .OnOff .attributes .OnOff
92
92
},
@@ -127,16 +127,16 @@ common_utils.device_type_attribute_map = {
127
127
clusters .LevelControl .attributes .MaxLevel ,
128
128
clusters .LevelControl .attributes .MinLevel
129
129
},
130
- [common_utils .ON_OFF_SWITCH_ID ] = {
130
+ [common_utils .ON_OFF_SWITCH_DEVICE_TYPE_ID ] = {
131
131
clusters .OnOff .attributes .OnOff
132
132
},
133
- [common_utils .ON_OFF_DIMMER_SWITCH_ID ] = {
133
+ [common_utils .ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID ] = {
134
134
clusters .OnOff .attributes .OnOff ,
135
135
clusters .LevelControl .attributes .CurrentLevel ,
136
136
clusters .LevelControl .attributes .MaxLevel ,
137
137
clusters .LevelControl .attributes .MinLevel
138
138
},
139
- [common_utils .ON_OFF_COLOR_DIMMER_SWITCH_ID ] = {
139
+ [common_utils .ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID ] = {
140
140
clusters .OnOff .attributes .OnOff ,
141
141
clusters .LevelControl .attributes .CurrentLevel ,
142
142
clusters .LevelControl .attributes .MaxLevel ,
@@ -149,14 +149,14 @@ common_utils.device_type_attribute_map = {
149
149
clusters .ColorControl .attributes .CurrentX ,
150
150
clusters .ColorControl .attributes .CurrentY
151
151
},
152
- [common_utils .GENERIC_SWITCH_ID ] = {
152
+ [common_utils .GENERIC_SWITCH_DEVICE_TYPE_ID ] = {
153
153
clusters .PowerSource .attributes .BatPercentRemaining ,
154
154
clusters .Switch .events .InitialPress ,
155
155
clusters .Switch .events .LongPress ,
156
156
clusters .Switch .events .ShortRelease ,
157
157
clusters .Switch .events .MultiPressComplete
158
158
},
159
- [common_utils .ELECTRICAL_SENSOR_ID ] = {
159
+ [common_utils .ELECTRICAL_SENSOR_DEVICE_TYPE_ID ] = {
160
160
clusters .ElectricalPowerMeasurement .attributes .ActivePower ,
161
161
clusters .ElectricalEnergyMeasurement .attributes .CumulativeEnergyImported ,
162
162
clusters .ElectricalEnergyMeasurement .attributes .PeriodicEnergyImported
@@ -185,7 +185,7 @@ common_utils.battery_support = {
185
185
BATTERY_PERCENTAGE = " BATTERY_PERCENTAGE"
186
186
}
187
187
188
- common_utils . updated_fields = {
188
+ local updated_fields = {
189
189
{ current_field_name = " __component_to_endpoint_map_button" , updated_field_name = common_utils .COMPONENT_TO_ENDPOINT_MAP },
190
190
{ current_field_name = " __switch_intialized" , updated_field_name = nil }
191
191
}
@@ -205,13 +205,13 @@ local device_type_category_map = {
205
205
[common_utils .EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID ] = common_utils .device_categories .LIGHT ,
206
206
[common_utils .ON_OFF_PLUG_DEVICE_TYPE_ID ] = common_utils .device_categories .PLUG ,
207
207
[common_utils .DIMMABLE_PLUG_DEVICE_TYPE_ID ] = common_utils .device_categories .PLUG ,
208
- [common_utils .ON_OFF_SWITCH_ID ] = common_utils .device_categories .SWITCH ,
209
- [common_utils .ON_OFF_DIMMER_SWITCH_ID ] = common_utils .device_categories .SWITCH ,
210
- [common_utils .ON_OFF_COLOR_DIMMER_SWITCH_ID ] = common_utils .device_categories .SWITCH ,
211
- [common_utils .MOUNTED_ON_OFF_CONTROL_ID ] = common_utils .device_categories .SWITCH ,
212
- [common_utils .MOUNTED_DIMMABLE_LOAD_CONTROL_ID ] = common_utils .device_categories .SWITCH ,
213
- [common_utils .GENERIC_SWITCH_ID ] = common_utils .device_categories .BUTTON ,
214
- [common_utils .WATER_VALVE_ID ] = common_utils .device_categories .WATER_VALVE
208
+ [common_utils .ON_OFF_SWITCH_DEVICE_TYPE_ID ] = common_utils .device_categories .SWITCH ,
209
+ [common_utils .ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID ] = common_utils .device_categories .SWITCH ,
210
+ [common_utils .ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID ] = common_utils .device_categories .SWITCH ,
211
+ [common_utils .MOUNTED_ON_OFF_CONTROL_DEVICE_TYPE_ID ] = common_utils .device_categories .SWITCH ,
212
+ [common_utils .MOUNTED_DIMMABLE_LOAD_CONTROL_DEVICE_TYPE_ID ] = common_utils .device_categories .SWITCH ,
213
+ [common_utils .GENERIC_SWITCH_DEVICE_TYPE_ID ] = common_utils .device_categories .BUTTON ,
214
+ [common_utils .WATER_VALVE_DEVICE_TYPE_ID ] = common_utils .device_categories .WATER_VALVE
215
215
}
216
216
217
217
function common_utils .get_first_non_zero_endpoint (endpoints )
@@ -315,10 +315,7 @@ function common_utils.get_device_category(device, main_endpoint)
315
315
end
316
316
317
317
local function supports_modular_profile (device )
318
- local modular_profiles_supported = version .api >= 14 and version .rpc >= 8 and
319
- not (device .manufacturer_info and
320
- device .manufacturer_info .vendor_id == common_utils .AQARA_MANUFACTURER_ID and
321
- device .manufacturer_info .product_id == common_utils .AQARA_CLIMATE_SENSOR_W100_ID )
318
+ local modular_profiles_supported = version .api >= 14 and version .rpc >= 8
322
319
if not modular_profiles_supported then
323
320
device :set_field (SUPPORTS_MODULAR_PROFILE , false )
324
321
return false
@@ -366,7 +363,7 @@ function common_utils.detect_bridge(device)
366
363
end
367
364
368
365
function common_utils .check_field_name_updates (device )
369
- for _ , field in ipairs (common_utils . updated_fields ) do
366
+ for _ , field in ipairs (updated_fields ) do
370
367
if device :get_field (field .current_field_name ) then
371
368
if field .updated_field_name ~= nil then
372
369
device :set_field (field .updated_field_name , device :get_field (field .current_field_name ), {persist = true })
@@ -443,8 +440,8 @@ function common_utils.add_subscribed_attributes_and_events(device, main_endpoint
443
440
for _ , dt in ipairs (ep .device_types ) do
444
441
id = math.max (id , dt .device_type_id )
445
442
end
446
- for _ , attr in pairs (common_utils . device_type_attribute_map [id ] or {}) do
447
- if id == common_utils .GENERIC_SWITCH_ID and
443
+ for _ , attr in pairs (device_type_attribute_map [id ] or {}) do
444
+ if id == common_utils .GENERIC_SWITCH_DEVICE_TYPE_ID and
448
445
attr ~= clusters .PowerSource .attributes .BatPercentRemaining and
449
446
attr ~= clusters .PowerSource .attributes .BatChargeLevel then
450
447
device :add_subscribed_event (attr )
0 commit comments