Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into async-cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Aug 9, 2024
2 parents 3452a22 + df9a476 commit 44efde7
Show file tree
Hide file tree
Showing 16 changed files with 256 additions and 172 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/device-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ body:
- type: input
attributes:
label: HA core version / HA版本
placeholder: 2022.12.x
placeholder: 2024.x.x
description: |
> [⚙️ Settings > ℹ️️ About](https://my.home-assistant.io/redirect/info)
> [⚙️ 配置 > ℹ️️ 关于](https://my.home-assistant.io/redirect/info)
Expand All @@ -47,6 +47,7 @@ body:
required: true
attributes:
label: Entity attributes / 实体属性
render: yaml
description: |
> [🔨 Developer tools > ℹ️ State](https://my.home-assistant.io/redirect/developer_states) > 🔍 Filter (Entity with most attributes)
> [🔨 开发者工具 > ℹ️ 状态](https://my.home-assistant.io/redirect/developer_states) > 🔍 筛选 (属性最多的实体)
Expand Down
42 changes: 32 additions & 10 deletions custom_components/xiaomi_miot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,14 @@ async def async_setup(hass, hass_config: dict):
config = hass_config.get(DOMAIN) or {}
await async_reload_integration_config(hass, config)

with open(os.path.dirname(__file__) + '/core/miot_specs_extend.json') as file:
models = json.load(file) or {}
for m, specs in models.items():
DEVICE_CUSTOMIZES.setdefault(m, {})
DEVICE_CUSTOMIZES[m]['extend_miot_specs'] = specs
def extend_miot_specs():
with open(os.path.dirname(__file__) + '/core/miot_specs_extend.json') as file:
models = json.load(file) or {}
for m, specs in models.items():
DEVICE_CUSTOMIZES.setdefault(m, {})
DEVICE_CUSTOMIZES[m]['extend_miot_specs'] = specs

await hass.async_add_executor_job(extend_miot_specs)

component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
hass.data[DOMAIN]['component'] = component
Expand Down Expand Up @@ -273,10 +276,7 @@ async def async_setup_entry(hass: hass_core.HomeAssistant, config_entry: config_
if not config_entry.update_listeners:
config_entry.add_update_listener(async_update_options)

for sd in SUPPORTED_DOMAINS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, sd)
)
await hass.config_entries.async_forward_entry_setups(config_entry, SUPPORTED_DOMAINS)
return True


Expand Down Expand Up @@ -854,8 +854,29 @@ def update_custom_scan_interval(self, only_custom=False):
tim = timedelta(seconds=sec)
if sec > 0 and tim != self.platform.scan_interval:
self.platform.scan_interval = tim
if hasattr(self.platform, 'scan_interval_seconds'):
self.platform.scan_interval_seconds = tim.total_seconds()
_LOGGER.debug('%s: Update custom scan interval: %s', self.name_model, tim)

def update_custom_parallel_updates(self):
if not self.hass:
return False
if not hasattr(self, '_unique_did'):
return False
num = self.custom_config_integer('parallel_updates', 0)
if not num:
return False
did = self._unique_did
self.hass.data[DOMAIN].setdefault(did, {})
dcs = self.hass.data[DOMAIN].get(did, {})
pus = dcs.get('parallel_updates')
if not pus:
pus = asyncio.Semaphore(num)
self.hass.data[DOMAIN][did]['parallel_updates'] = pus
_LOGGER.debug('%s: Update custom parallel updates: %s', self.name_model, num)
self.parallel_updates = pus
return pus

def filter_state_attributes(self, dat: dict):
if exl := self.global_config('exclude_state_attributes'):
exl = cv.ensure_list(exl)
Expand Down Expand Up @@ -986,6 +1007,7 @@ async def async_added_to_hass(self):
await super().async_added_to_hass()
if self.platform:
self.update_custom_scan_interval()
self.update_custom_parallel_updates()
if self.platform.config_entry:
eid = self.platform.config_entry.entry_id
self._add_entities = self.hass.data[DOMAIN][eid].get('add_entities') or {}
Expand Down Expand Up @@ -2084,7 +2106,7 @@ def _update_sub_entities(self, properties, services=None, domain=None, option=No
fnm = f
elif p.full_name not in self._state_attrs and not p.writeable and not kwargs.get('whatever'):
continue
elif add_switches and domain == 'switch' and (p.format in ['bool'] or p.value_list) and p.writeable:
elif add_switches and domain == 'switch' and (p.format in ['bool', 'uint8']) and p.writeable:
self._subs[fnm] = MiotSwitchSubEntity(self, p, option=opt)
add_switches([self._subs[fnm]], update_before_add=True)
elif add_binary_sensors and domain == 'binary_sensor' and (p.is_bool or p.is_integer):
Expand Down
98 changes: 93 additions & 5 deletions custom_components/xiaomi_miot/core/device_customizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@
},
'cuco.acpartner.cp6': {
'switch_properties': 'air_conditioner.on',
'sensor_attributes': 'power_cost_today,power_cost_month',
'stat_power_cost_key': '7.1',
},
'cuco.acpartner.cp6:power_cost_today': {
'value_ratio': 1,
'state_class': 'total_increasing',
'device_class': 'energy',
'unit_of_measurement': 'kWh',
},
'cuco.acpartner.cp6:power_cost_month': {
'value_ratio': 1,
'state_class': 'total_increasing',
'device_class': 'energy',
'unit_of_measurement': 'kWh',
},
'cuco.light.sl4': {
'switch_properties': 'swich',
Expand Down Expand Up @@ -407,9 +421,27 @@
'state_class': 'total_increasing',
'device_class': 'energy',
'unit_of_measurement': 'kWh',
},
'cuco.plug.wp12': {
'main_miot_services': 'switch-2',
'sensor_attributes': 'power_cost_today,power_cost_month',
'stat_power_cost_key': '11.1'
},
'cuco.plug.wp12:power_cost_today': {
'value_ratio': 1,
'state_class': 'total_increasing',
'device_class': 'energy',
'unit_of_measurement': 'kWh',
},
'cuco.plug.wp12:power_cost_month': {
'value_ratio': 1,
'state_class': 'total_increasing',
'device_class': 'energy',
'unit_of_measurement': 'kWh',
},
'cuco.plug.*': {
'main_miot_services': 'switch-2',
'parallel_updates': 3,
},
'cuco.plug.*:electric_current': {
'state_class': 'measurement',
Expand Down Expand Up @@ -459,6 +491,11 @@
'state_class': '',
},

'dawn.toilet.02': {
'button_actions': 'stop_working,fangai,fanquan,paopaowei,chongshui,tunxi,fuxi,honggan,zijie',
'switch_properties': 'on,auto_flush,foot_sensing,moistening_wall,auto_clamshell',
'select_properties': 'target_temperature,washing_strength,nozzle_position,sensing_distance',
},
'deerma.humidifier.jsq4': {
'exclude_miot_services': None,
},
Expand Down Expand Up @@ -513,8 +550,9 @@
'percentage_property': 'prop.2.6',
},
'dmaker.fan.p28': {
'switch_properties': 'alarm,horizontal_swing,vertical_swing,swing_all,off_to_center',
'percentage_property': 'speed_level',
'button_properties': 'swing_updown_manual,swing_lr_manual,back_to_center',
'button_properties': 'swing_updown_manual,swing_lr_manual,back_to_center,start_left,start_right,start_up,start_down',
},
'dmaker.fan.p33': {
'percentage_property': 'prop.2.6',
Expand Down Expand Up @@ -641,6 +679,7 @@
'switch_properties': 'alarm_shielding,silent_mode,line_exchange',
},
'hyd.airer.lyjpro': {
'position_reverse': True,
'cover_position_mapping': {},
},
'hyd.airer.*': {
Expand All @@ -650,6 +689,7 @@
'number_properties': 'drying_time',
'exclude_miot_properties': 'motor_control',
'disable_target_position': True,
'position_reverse': False,
'cover_position_mapping': {
0: 50,
1: 100,
Expand Down Expand Up @@ -940,7 +980,21 @@
'lumi.switch.*': {
'cloud_delay_update': 10,
},
'lxzn.switch.cbcsmj': {
'sensor_properties': 'temperature,electric_power',
'select_properties': 'default_power_on_state',
'switch_properties': 'electric_alarm_set,heat_alert_set,overcurrent_set,overvoltage_set,undervoltage_set',
'number_properties': 'electric_alarm,heat_alert,overcurrent_alarm,overvoltage_alarm,undervoltage_alarm',
},

'madv.cateye.mi3iot': {
'binary_sensor_properties': 'madv_doorbell.motion_detection',
'sensor_properties': 'battery_level',
'switch_properties': 'eco,motion_detection,alarm,autoreply,fw_autoupgrade,vistpush,motionpush',
'select_properties': 'night_shot,ringtone,alarm_interval,detection_sensitivity,motionpush_pushtype,videolength,'
'eco_code,ringer_music',
'number_properties': 'videodelay,volume',
},
'mibx5.washer.*': {
'sensor_properties': 'fault,left_time,door_state,run_status,detergent_left_level',
'switch_properties': 'sleep_mode,steam_sterilization,detergent_self_delivery',
Expand All @@ -966,10 +1020,22 @@
'mmgg.feeder.fi1': {
'chunk_properties': 1,
'state_property': 'pet_food_left_level',
'button_actions': 'reset_desiccant_life,resetclean,pet_food_out',
'sensor_properties': 'desiccant_left_time,cleantime,fault,outletstatus,doorstatus',
'button_actions': 'pet_food_out,resetclean,reset_desiccant_life',
'binary_sensor_properties': 'outletstatus,doorstatus',
'sensor_properties': 'fault,outfood_num,cleantime,desiccant_left_time',
'number_properties': 'key_stat,indicator_light.on',
'exclude_miot_properties': 'outfood_num,outfood_id,contrycode,feddplan_string,factory_result',
'exclude_miot_properties': 'outfood_id,contrycode,feddplan_string,factory_result,phon_time_zone'
'feedplan_hour,feedplan_min,feedplan_unit,feedplan_stat,feedplan_id,getfeedplan_num',
},
'mmgg.feeder.inland': {
'chunk_properties': 1,
'state_property': 'pet_food_left_level',
'button_actions': 'pet_food_out,resetclean,reset_desiccant_life',
'binary_sensor_properties': 'outletstatus,doorstatus',
'sensor_properties': 'outfood_num,foodstatus,desiccant_left_time,cleantime',
'switch_properties': 'key_stat,indicator_light.on',
'exclude_miot_properties': 'fault,outfood_id,contrycode,feddplan_string,factory_result,phon_time_zone,'
'feedplan_hour,feedplan_min,feedplan_unit,feedplan_stat,feedplan_id,getfeedplan_num',
},
'mmgg.feeder.petfeeder': {
'state_property': 'pet_food_left_level',
Expand Down Expand Up @@ -1057,6 +1123,13 @@
'device_class': 'problem',
},

'opple.bhf_light.acmoto': {
'exclude_miot_services': 'pair,wifisinr,class_sku,fan_motor',
'exclude_miot_properties': 'fault',
'light_services': 'aura_light',
'number_properties': 'function_countdown.warm,function_countdown.blower,'
'function_countdown.breath,function_countdown,shutdown',
},
'opple.light.yrtd': {
'switch_properties': 'night_light,time_display,wake_up_at_night,voice',
'select_properties': 'study_time',
Expand Down Expand Up @@ -1454,7 +1527,7 @@
'switch_properties': 'status_seatheat,status_led,auto_led,switch_bubble,status_seat,status_cover,'
'auto_seat_close,auto_cover_close,status_selfclean',
'select_properties': 'seat_temp',
'button_actions': 'stop_working',
'button_actions': 'stop_working,flush_work,start_foam,clean_work',
},
'xwhzp.diffuser.xwxfj': {
'sensor_properties': 'fragrance_liquid_left_level',
Expand Down Expand Up @@ -1624,6 +1697,14 @@
'brightness_for_on': 0,
'brightness_for_off': 2,
},
'zhimi.fan.za3': {
'miot_type': 'urn:miot-spec-v2:device:fan:0000A005:zhimi-za3:3',
'number_select_properties': 'fan_level',
},
'zhimi.fan.za4': {
'miot_type': 'urn:miot-spec-v2:device:fan:0000A005:zhimi-za4:3',
'number_select_properties': 'fan_level',
},
'zhimi.fan.*': {
'switch_properties': 'anion,alarm,horizontal_swing,vertical_swing',
'number_properties': 'horizontal_angle,vertical_angle,off_delay',
Expand Down Expand Up @@ -1861,11 +1942,18 @@
'*.motion.*:trigger_at': {
'device_class': 'timestamp',
},
'*.sensor_occupy.*': {
'sensor_properties': 'illumination,has_someone_duration,no_one_duration',
},
'*.oven.*': {
'sensor_properties': 'temperature,left_time,cook_time,working_time',
'number_properties': 'target_temperature',
'switch_properties': 'oven.on',
},
'*.senpres.*': {
'binary_sensor_properties': 'pressure_present_state',
'sensor_properties': 'pressure_not_present_duration',
},
'*.s_lamp.*': {
'sensor_properties': 'left_time',
'switch_properties': 'uv,radar_on,lighting.on',
Expand Down
12 changes: 11 additions & 1 deletion custom_components/xiaomi_miot/core/miio2miot_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ def cbk(prop, params, props, **kwargs):
'["dry_cloth"] if value == 2 else '
'{"method": "set_auto","params": [props.auto]} }}',
},
'prop.2.3': {'prop': 'fan_st', 'setter': True},
'prop.2.3': {'prop': 'fan_st', 'setter': 'set_fan_level'},
'prop.2.101': {'prop': 'auto', 'setter': True},
'prop.2.102': {'prop': 'tank_full', 'format': 'onoff'},
'prop.3.1': {'prop': 'humidity'},
Expand Down Expand Up @@ -2754,6 +2754,16 @@ def cbk(prop, params, props, **kwargs):
'template': '{{ 1 if value|int(0) > 0 else 0 }}',
'set_template': '{{ [value|int(0) * 25] }}',
},
'prop.2.6': {
'prop': 'speed_level',
'setter': True,
'template': '{{ props.natural_level|default(value,true)|int(0) }}',
'set_template': '{% set nlv = props.natural_level|default(0)|int(0) %}'
'{{ {'
'"method": "set_natural_level" if nlv else "set_speed_level",'
'"params": [value|int(0)],'
'} }}',
},
'prop.4.1': {
'prop': 'buzzer',
'setter': True,
Expand Down
Loading

0 comments on commit 44efde7

Please sign in to comment.