Skip to content

Commit

Permalink
🏃 add support for ainice.sensor_occupy.3b (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Mar 6, 2024
1 parent 1b1729c commit d45425c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
15 changes: 15 additions & 0 deletions custom_components/xiaomi_miot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,21 @@ def __init__(self, parent, miot_property: MiotProperty, option=None, **kwargs):
'property_description': miot_property.description or miot_property.name,
})

def update_with_properties(self):
pls = self.custom_config_list('with_properties', [])
for p in pls:
prop = self._miot_service.get_property(p) or self._miot_service.spec.get_property(p)
if not prop:
continue
val = prop.from_dict(self.parent_attributes)
self._extra_attrs[prop.name] = val

def update(self, data=None):
super().update(data)
if not self._available:
return
self.update_with_properties()

def set_parent_property(self, val, prop=None):
if prop is None:
prop = self._miot_property
Expand Down
25 changes: 24 additions & 1 deletion custom_components/xiaomi_miot/core/device_customizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,32 @@
'sensor_properties': 'total_occupied',
'switch_properties': 'radar_switch,count_switch',
'select_properties': 'map_index,traction',
'number_properties': 'radar_duration',
'button_actions': 'reboot',
},
'ainice.sensor_occupy.3b:current_occupied': {
'with_properties': 'has_someone_duration,no_one_duration,total_occupied',
'device_class': 'occupancy',
},
'ainice.sensor_occupy.3b:a_occupied': {
'with_properties': 'a_someone_duration,a_noone_duration',
'device_class': 'occupancy',
},
'ainice.sensor_occupy.3b:b_occupied': {
'with_properties': 'b_someone_duration,b_noone_duration',
'device_class': 'occupancy',
},
'ainice.sensor_occupy.3b:c_occupied': {
'with_properties': 'c_someone_duration,c_noone_duration',
'device_class': 'occupancy',
},
'ainice.sensor_occupy.3b:d_occupied': {
'with_properties': 'd_someone_duration,d_noone_duration',
'device_class': 'occupancy',
},
'ainice.sensor_occupy.3b:e_occupied': {
'with_properties': 'e_someone_duration,e_noone_duration',
'device_class': 'occupancy',
},
'ainice.sensor_occupy.pr': {
'main_miot_services': 'occupancy_sensor',
'state_property': 'occupancy_sensor.occupancy_status',
Expand Down
1 change: 1 addition & 0 deletions custom_components/xiaomi_miot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ def update(self, data=None):
super().update(data)
if not self._available:
return
self.update_with_properties()
self._miot_property.description_to_dict(self._state_attrs)

@property
Expand Down

0 comments on commit d45425c

Please sign in to comment.