50 Commits

Author SHA1 Message Date
sususweet
224d6b0bbc feat: fix device support for T0x13. 2025-10-14 20:37:39 +08:00
sususweet
341796a8d4 feat: fix device support for T0x13. 2025-10-14 20:36:27 +08:00
sususweet
57b5cf811c Merge remote-tracking branch 'origin/master' 2025-10-14 20:30:07 +08:00
sususweet
187c46168c feat: add device support for T0x13. 2025-10-14 20:29:35 +08:00
sususweet
6491570e70 Merge pull request #30 from zy900906/master
传感器增加running_status
2025-10-13 23:10:07 +08:00
zy900906
a5d40b7d65 Update en.json
sensor,running_status
2025-10-13 12:47:47 +08:00
zy900906
d8c298f608 Update zh-Hans.json
sensor,running_status
2025-10-13 12:46:49 +08:00
zy900906
85c51c2090 Update T0xDC.py
running_status
2025-10-13 12:44:20 +08:00
sususweet
b1e42526f6 feat: add device for central air conditioner gateway(T0x21). 2025-10-12 12:53:13 +08:00
sususweet
b87729d016 fix: resolve error when lua file is none 2025-10-11 23:52:54 +08:00
sususweet
1172f66a17 feat: version 0.1.10 2025-10-11 20:53:03 +08:00
sususweet
1ddfa9f020 feat: update device mapping for T0xB6. Fix #26. 2025-10-11 20:44:33 +08:00
sususweet
160957abb8 feat: update translation 2025-10-11 14:59:16 +08:00
sususweet
69098292f0 feat: update contribution doc. 2025-10-11 14:21:11 +08:00
sususweet
b3e9a11394 fix: humidifier entity control mapping. 2025-10-11 11:48:42 +08:00
sususweet
d49eab91c9 feat: update device mapping for T0xFD by @jesustoachild. 2025-10-10 21:22:14 +08:00
sususweet
ab23b4088e feat: update translations. 2025-10-10 20:59:00 +08:00
sususweet
c90b8a3d0d feat: update device mapping for T0xE3. 2025-10-10 20:55:16 +08:00
sususweet
5ffa57bed8 feat: update device mapping for T0xCA. 2025-10-10 20:45:24 +08:00
sususweet
1029b6c4aa feat: update available_modes for HumidifierEntity 2025-10-10 19:55:30 +08:00
sususweet
6bc49c1b09 feat: update mapping for T0xAC 26093139 device. 2025-10-10 17:01:44 +08:00
sususweet
16460d66ca feat: version 0.1.8 2025-10-10 10:47:00 +08:00
sususweet
94f0ce84fb feat: update device mapping for T0xFD. Try to fix #24 2025-10-10 10:45:46 +08:00
sususweet
a2c379a334 feat: add device support for T0xA1 2025-10-10 10:28:59 +08:00
sususweet
2d2d0de10a fix: update translation and entity for T0xE1 2025-10-10 09:42:51 +08:00
sususweet
2bceda19ac fix: translation. 2025-10-09 21:11:11 +08:00
sususweet
7ee178b6f2 fix: translation. 2025-10-09 21:09:14 +08:00
sususweet
b45bb48352 Merge remote-tracking branch 'origin/master' 2025-10-09 21:07:40 +08:00
sususweet
cab195f9e0 fix: translation for input_temperature_Sensing 2025-10-09 21:07:26 +08:00
sususweet
c92785eea2 Update and rename main.yml to validate.yml 2025-10-09 20:45:37 +08:00
sususweet
dfc6e9c5d3 Merge remote-tracking branch 'origin/master' 2025-10-09 20:39:41 +08:00
sususweet
0072503a00 feat: add mop dry feature for T0xB8. 2025-10-09 20:39:22 +08:00
sususweet
ab146eb54b Create main.yml 2025-10-09 19:08:29 +08:00
sususweet
51133b94bd fix: device mapping and translation for T0xCA and T0xED. Fix #23. 2025-10-09 10:02:08 +08:00
sususweet
7a75376725 Merge pull request #22 from bjzhou/master
update device mapping
2025-10-09 09:47:21 +08:00
Hinnka
2c821ceb54 feat: zero cold water switch 2025-10-08 12:43:28 +08:00
Hinnka
2e2ec7a989 feat: update 0xED mapping 2025-10-07 09:03:32 +08:00
hinnka
e1924bdc4b translations 2025-10-07 08:32:36 +08:00
sususweet
066ed7b0a2 feat: version 0.1.6 2025-10-05 13:43:11 +08:00
sususweet
87fa17c7df feat: support climate turn on & off feature. Fix #18. 2025-10-05 13:42:57 +08:00
sususweet
1cd31305e5 feat: update T0xED mapping. 2025-10-05 13:00:50 +08:00
sususweet
59308d1f4f feat: version 0.1.5 2025-10-05 11:07:00 +08:00
sususweet
0d36e1da6f feat: update device control command for mop robot(T0xD8). Fix #1. 2025-10-05 11:06:42 +08:00
sususweet
684c143d4f feat: update device support for mop robot(T0xD8). 2025-10-05 10:57:09 +08:00
sususweet
0328714227 feat: update device support for central air conditioner and washer. 2025-10-05 10:27:57 +08:00
sususweet
bd4666e1bd feat: update device support for T0x26 2025-10-05 00:09:52 +08:00
sususweet
324ed37de4 feat: update device support for T0x26 2025-10-05 00:09:15 +08:00
sususweet
1f555800f3 feat: update device T0xE1 control strategy. 2025-10-04 23:34:27 +08:00
sususweet
0ec6b763cd feat: update device rational 2025-10-04 22:47:56 +08:00
sususweet
4427a1fba9 feat: add cooker T0xB7 2025-10-01 22:42:52 +08:00
37 changed files with 6557 additions and 4801 deletions

23
.github/workflows/validate.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: Validate
on:
push:
pull_request:
schedule:
- cron: 0 0 * * *
jobs:
hassfest:
name: hassfest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: home-assistant/actions/hassfest@master
hacs:
name: HACS
runs-on: ubuntu-latest
steps:
- name: HACS Action
uses: hacs/action@main
with:
category: integration

1
.gitignore vendored
View File

@@ -153,6 +153,7 @@ cython_debug/
.idea
decrypt_lua.py
test.py
*.lua

123
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,123 @@
# 贡献指南
感谢您考虑为我们的项目做出贡献!您的努力将使我们的项目变得更好。
在您开始贡献之前,请花一点时间阅读以下准则:
## 我可以如何贡献?
### 报告问题
如果您在项目中遇到错误,请在 GitHub 上[报告问题](https://github.com/sususweet/midea_auto_cloud/issues/new/),并提供关于错误的详细信息,包括复现步骤、 debug 级日志以及错误出现的时间。
集成开启 debug 级日志的[方法](https://www.home-assistant.io/integrations/logger/#log-filters)
```
# configuration.yaml 设置打印日志等级
logger:
default: critical
logs:
custom_components.xiaomi_home: debug
```
### 建议增强功能
如果您有增强或新功能的想法,欢迎您在 GitHub 讨论区[创建想法](https://github.com/sususweet/midea_auto_cloud/discussions/new?category=ideas) 。我们期待您的建议!
### 贡献代码
1. Fork 该仓库并从 `master` 创建您的分支。
2. 确保您的代码符合项目的编码规范。
3. 确保您的提交消息描述清晰。
4. 提交请求应附有明确的问题描述和解决方案。
5. 如果必要,请更新文档。
6. 请运行测试并确保测试通过。
## 适配设备
要适配本项目中暂未包含的设备,可以按照以下步骤进行:
1. 在Homeassistant中安装本插件安装完成后登录自己的账号可以看到自己名下的设备。
2. 在集成中找到需要适配的设备,点击设备的相关字段进入详情页面,如下图:
![img_2.png](./img/img_2.png)
3. 点击传感器中的`连通性`,可以看到该设备可以被读取和访问的状态,如下图:
![img_3.png](./img/img_3.png)
着重关注Device type、Subtype这两个字段这是后续获得设备控制对应lua文件的基础。
4. 进入Homeassistant的安装目录`.storage/midea_auto_cloud/lua/`目录下找到T_0000_`Device type`_`Subtype`_***.lua文件例如上面干衣机设备的lua文件是 T_0000_DC_12852_2021121701.lua。
5. 可用人工分析或者AI分析的方法解析lua文件结合美的官方APP的控制界面提取出需要控制的设备属性把修改合并到`device_mapping`中对应设备`Device type`的py文件中。
6. `device_mapping`中设备映射文件的编写方法可参考之前编写过的,`default`是默认的映射可以作为参考默认改这个就可以。如果自己设备的映射跟通用的差别太大目前发现有空调、新风系统设备类型都是T0xAC但可控制的变量差别比较大可以根据设备的sn8来新建字段。
7. 完成上述步骤,编写好`device_mapping`中对应设备的py文件即可在自己的机器上测试测试好后就可以提pr。
## 拉取请求准则
在提交拉取请求之前,请确保满足以下要求:
- 您的拉取请求解决了单个问题或功能。
- 您已在本地测试过您的更改。
- 您的代码遵循项目的代码规范。
- 所有现有测试都通过,并且如果适用,您已添加了新的测试。
- 任何依赖更改都有文档说明。
## 代码规范
本项目的代码格式遵循 [Google Style](https://google.github.io/styleguide/pyguide.html) 。请确保您的贡献符合该指南。
## Commit Message 格式
```
<type>: <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```
type :有以下几种变更类型
- feat新增功能。
- fix修复问题。
- docs仅仅修改了文档。
- style仅仅是对格式进行修改如逗号、缩进、空格等不改变代码逻辑。
- refactor代码重构没有新增功能或修复问题。
- perf优化性能。
- test增加或修改测试用例。
- chore修改编译流程或变更依赖库和工具等。
- revert版本回滚。
subject :简洁的标题,描述本次提交的概要。使用祈使句、现在时态,首字母小写,结尾不加句号。
body :描述本次提交的详细内容,解释为什么需要这些变更。除 docs 之外的变更类型必须包含 body。
footer :(可选)关联的 issue 或 pull request 编号。
## 命名规范
### 第三方平台命名规范
- 描述“Home Assistant”时必须使用“Home Assistant”变量可以使用“hass”或“hass_xxx”。
### 其它命名规范
- 文档中的中文语句包含英文时,如果英文没有被中文引号括起来,那么中文与英文之间必须有一个空格。(最好代码注释也这么写)
## 许可
在为本项目做出贡献时,您同意您的贡献遵循本项目的[许可证](../LICENSE.md) 。
当您第一次提交拉取请求时GitHub Action 会提示您签署贡献者许可协议Contributor License AgreementCLA。只有签署了 CLA ,本项目才会合入您的拉取请求。
## 获取帮助
如果您需要帮助或有疑问,可在 GitHub 的[讨论区](https://github.com/sususweet/midea_auto_cloud/discussions/)询问。
您还可以联系 sususweetcandy@qq.com

View File

@@ -15,11 +15,18 @@
## 目前支持的设备类型
- T0x13 电灯
- T0x21 中央空调网关
- T0x26 浴霸
- T0xA1 除湿机
- T0xAC 空调
- T0xB2 电蒸箱
- T0xB3 消毒碗柜
- T0xB6 抽油烟机
- T0xB7 燃气灶
- T0xB8 智能扫地机器人
- T0xCA 对开门冰箱
- T0xCC 中央空调(风管机)Wi-Fi线控器
- T0xCE 新风机
- T0xCF 中央空调暖家
- T0xD9 复式洗衣机
@@ -37,11 +44,13 @@
合作开发方法:添加本插件后,找到未能正确识别的设备,点击对应设备`传感器`分类下的`连通性`
![img.png](img.png)
![img.png](./img/img.png)
展开下面的`属性`卡片,把里面这些字段复制给我或随issue提交,等待适配就可以了
展开下面的`属性`卡片把里面这些字段随issue提交。 着重关注Device type、Subtype这两个字段这是后续获得设备控制对应lua文件的基础
![img_1.png](img_1.png)
再进入Homeassistant的安装目录`.storage/midea_auto_cloud/lua/`目录下找到设备对应的T_0000_`Device type`_`Subtype`_***.lua文件等待适配就可以了。
![img_1.png](./img/img_1.png)
## 实体映射

View File

@@ -55,6 +55,7 @@ PLATFORMS: list[Platform] = [
Platform.SELECT,
Platform.WATER_HEATER,
Platform.FAN,
Platform.LIGHT,
Platform.HUMIDIFIER
]

View File

@@ -51,6 +51,9 @@ async def async_setup_entry(
class MideaClimateEntity(MideaEntity, ClimateEntity):
def __init__(self, coordinator, device, manufacturer, rationale, entity_key, config):
# 自动判断是否为中央空调设备T0x21
self._is_central_ac = device.device_type == 0x21
super().__init__(
coordinator,
device.device_id,
@@ -66,6 +69,7 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
config=config,
)
self._key_power = self._config.get("power")
self._key_pre_mode = self._config.get("pre_mode")
self._key_hvac_modes = self._config.get("hvac_modes")
self._key_preset_modes = self._config.get("preset_modes")
self._key_aux_heat = self._config.get("aux_heat")
@@ -107,23 +111,31 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
@property
def target_temperature(self):
if isinstance(self._key_target_temperature, list):
temp_int = self._get_nested_value(self._key_target_temperature[0])
tem_dec = self._get_nested_value(self._key_target_temperature[1])
if temp_int is not None and tem_dec is not None:
try:
return float(temp_int) + float(tem_dec)
except (ValueError, TypeError):
return None
if self._is_central_ac:
run_mode = self._get_nested_value(self._key_power) or "0"
if run_mode == "2": # 制冷模式
return self._get_nested_value("cool_temp_set")
elif run_mode == "3": # 制热模式
return self._get_nested_value("cool_temp_set")
return None
else:
temp = self._get_nested_value(self._key_target_temperature)
if temp is not None:
try:
return float(temp)
except (ValueError, TypeError):
return None
return None
if isinstance(self._key_target_temperature, list):
temp_int = self._get_nested_value(self._key_target_temperature[0])
tem_dec = self._get_nested_value(self._key_target_temperature[1])
if temp_int is not None and tem_dec is not None:
try:
return float(temp_int) + float(tem_dec)
except (ValueError, TypeError):
return None
return None
else:
temp = self._get_nested_value(self._key_target_temperature)
if temp is not None:
try:
return float(temp)
except (ValueError, TypeError):
return None
return None
@property
def min_temp(self):
@@ -165,11 +177,21 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
@property
def swing_modes(self):
return list(self._key_swing_modes.keys())
if self._is_central_ac:
return ["off", "on"]
else:
return list(self._key_swing_modes.keys())
@property
def swing_mode(self):
return self._dict_get_selected(self._key_swing_modes)
if self._is_central_ac:
extflag = self._get_nested_value("extflag") or "0"
# extflag: 4=摇摆, 6=电辅热+摇摆
if extflag in ["4", "6"]:
return "on"
return "off"
else:
return self._dict_get_selected(self._key_swing_modes)
@property
def is_on(self) -> bool:
@@ -193,39 +215,90 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
async def async_turn_off(self):
await self._async_set_status_on_off(self._key_power, False)
async def async_toggle(self):
if self.is_on:
await self.async_turn_off()
else:
await self.async_turn_on()
async def async_set_temperature(self, **kwargs):
if ATTR_TEMPERATURE not in kwargs:
return
temperature = kwargs.get(ATTR_TEMPERATURE)
temp_int, temp_dec = divmod(temperature, 1)
temp_int = int(temp_int)
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
if hvac_mode is not None:
new_status = self._key_hvac_modes.get(hvac_mode)
if self._is_central_ac:
run_mode = self._get_nested_value(self._key_power) or "0"
control = {}
if run_mode == "2": # 制冷模式
control["cooling_temp"] = str(temperature)
elif run_mode == "3": # 制热模式
control["cooling_temp"] = str(temperature)
control["heating_temp"] = str(temperature)
if control:
await self.coordinator.async_send_central_ac_control(control)
else:
new_status = {}
if isinstance(self._key_target_temperature, list):
new_status[self._key_target_temperature[0]] = temp_int
new_status[self._key_target_temperature[1]] = temp_dec
else:
new_status[self._key_target_temperature] = temperature
await self.async_set_attributes(new_status)
temp_int, temp_dec = divmod(temperature, 1)
temp_int = int(temp_int)
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
if hvac_mode is not None:
new_status = self._key_hvac_modes.get(hvac_mode)
else:
new_status = {}
if isinstance(self._key_target_temperature, list):
new_status[self._key_target_temperature[0]] = temp_int
new_status[self._key_target_temperature[1]] = temp_dec
else:
new_status[self._key_target_temperature] = temperature
await self.async_set_attributes(new_status)
async def async_set_fan_mode(self, fan_mode: str):
new_status = self._key_fan_modes.get(fan_mode)
await self.async_set_attributes(new_status)
if self._is_central_ac:
fan_speed = self._key_fan_modes.get(fan_mode)
await self.coordinator.async_send_central_ac_control(fan_speed)
else:
new_status = self._key_fan_modes.get(fan_mode)
await self.async_set_attributes(new_status)
async def async_set_preset_mode(self, preset_mode: str):
new_status = self._key_preset_modes.get(preset_mode)
await self.async_set_attributes(new_status)
if self._is_central_ac:
new_status = self._key_preset_modes.get(preset_mode)
await self.coordinator.async_send_central_ac_control(new_status)
else:
new_status = self._key_preset_modes.get(preset_mode)
await self.async_set_attributes(new_status)
async def async_set_hvac_mode(self, hvac_mode: str):
new_status = self._key_hvac_modes.get(hvac_mode)
await self.async_set_attributes(new_status)
if self._is_central_ac:
run_mode = self._key_hvac_modes.get(hvac_mode)
await self.coordinator.async_send_central_ac_control(run_mode)
else:
new_status = self._key_hvac_modes.get(hvac_mode)
await self.async_set_attributes(new_status)
async def async_set_swing_mode(self, swing_mode: str):
new_status = self._key_swing_modes.get(swing_mode)
await self.async_set_attributes(new_status)
if self._is_central_ac:
current_extflag = self._get_nested_value("extflag") or "0"
if swing_mode == "on":
# 开启摆风:如果当前有电辅热(2)则设为6(电辅热+摆风)否则设为4(摆风)
if current_extflag == "2":
new_extflag = "6" # 电辅热+摆风
else:
new_extflag = "4" # 仅摆风
else:
# 关闭摆风如果当前是6(电辅热+摆风)则设为2(仅电辅热)否则设为0(关闭)
if current_extflag == "6":
new_extflag = "2" # 仅电辅热
else:
new_extflag = "0" # 关闭
control = {"extflag": new_extflag}
await self.coordinator.async_send_central_ac_control(control)
else:
new_status = self._key_swing_modes.get(swing_mode)
await self.async_set_attributes(new_status)
async def async_turn_aux_heat_on(self) -> None:
await self._async_set_status_on_off(self._key_aux_heat, True)
@@ -242,8 +315,12 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
return value
return value == 1 or value == "on" or value == "true"
async def _async_set_status_on_off(self, key, value):
async def _async_set_status_on_off(self, attribute_key: str | None, turn_on: bool):
"""Set on/off status for device attribute."""
if key is None:
if attribute_key is None:
return
await self.async_set_attribute(key, value)
new_status = {}
new_status[attribute_key] = self._rationale[int(turn_on)]
if turn_on:
new_status[self._key_pre_mode] = self._get_nested_value(self._key_pre_mode)
await self.async_set_attributes(new_status)

View File

@@ -44,9 +44,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
)
try:
if await cloud.login():
await self.async_set_unique_id(user_input[CONF_ACCOUNT])
self._abort_if_unique_id_configured()
# 保存云实例和用户输入,用于后续步骤
self._cloud = cloud
self._user_input = user_input

View File

@@ -198,6 +198,14 @@ class MideaCloud:
async def send_device_control(self, appliance_code: int, control: dict, status: dict | None = None) -> bool:
"""Send control to a device via cloud. Subclasses should implement if supported."""
raise NotImplementedError()
async def send_central_ac_control(self, appliance_code: int, nodeid: str, modelid: str, idtype: int, control: dict) -> bool:
"""Send control to central AC subdevice. Subclasses should implement if supported."""
raise NotImplementedError()
async def get_central_ac_status(self, appliance_codes: list) -> dict | None:
"""Get status of central AC devices. Subclasses should implement if supported."""
raise NotImplementedError()
class MeijuCloud(MideaCloud):
@@ -223,6 +231,7 @@ class MeijuCloud(MideaCloud):
password=password,
api_url=clouds[cloud_name]["api_url"]
)
self._homegroup_id = None
async def login(self) -> bool:
if login_id := await self._get_login_id():
@@ -275,6 +284,8 @@ class MeijuCloud(MideaCloud):
return None
async def list_appliances(self, home_id) -> dict | None:
# 存储当前使用的 homegroupId 用于后续的中央空调控制
self._homegroup_id = str(home_id)
data = {
"homegroupId": home_id
}
@@ -304,11 +315,11 @@ class MeijuCloud(MideaCloud):
return appliances
return None
async def get_device_status(self, appliance_code: int) -> dict | None:
async def get_device_status(self, appliance_code: int, query: dict) -> dict | None:
data = {
"applianceCode": str(appliance_code),
"command": {
"query": {}
"query": query
}
}
if response := await self._api_request(
@@ -333,6 +344,66 @@ class MeijuCloud(MideaCloud):
data=data
)
return response is not None
async def send_central_ac_control(self, appliance_code: int, nodeid: str, modelid: str, idtype: int, control: dict) -> bool:
"""Send control to central AC subdevice using the special T0x21 API."""
import uuid
import json
# 构建中央空调控制命令
command_data = {
"nodeid": nodeid,
"acattri_ctrl": {
"aclist": [{
"nodeid": nodeid,
"modelid": modelid,
"type": idtype
}],
"event": control
}
}
# 构建完整的请求数据
request_data = {
"applianceCode": str(appliance_code),
"modelId": modelid,
"topic": "/subdevice/multicontrol",
"command": command_data,
"msgId": str(uuid.uuid4()).replace("-", "")
}
request_data_str = json.dumps(request_data).encode("utf-8")
MideaLogger.debug(f"Sending control to central AC device {appliance_code}: {request_data_str}")
# 发送到特殊的中央空调API
if response := await self._api_request(
endpoint="/v1/gateway/transport/send",
data={
'applianceCode': str(appliance_code),
'order': self._security.aes_encrypt(request_data_str).hex(),
'homegroupId': self._homegroup_id,
}
):
if response and response.get('reply'):
reply_data = self._security.aes_decrypt(bytes.fromhex(response['reply']))
MideaLogger.debug(f"[{appliance_code}] Gateway command response: {reply_data}")
return reply_data
else:
MideaLogger.warning(f"[{appliance_code}] Gateway command failed: {response}")
async def get_central_ac_status(self, appliance_codes: list) -> dict | None:
"""Get status of central AC devices using the aggregator API."""
# 构建请求数据
request_data = {
"entities": ["endlist", "tips"],
"appliances": [{"id": str(code), "type": "0x21"} for code in appliance_codes],
}
response = await self._api_request(
endpoint="/api/v1/aggregator/appliances",
data=request_data
)
return response
async def download_lua(
self, path: str,

View File

@@ -166,14 +166,15 @@ class MiedaDevice(threading.Thread):
# Convert dot-notation attributes to nested structure for transmission
nested_status = self._convert_to_nested_structure(new_status)
try:
if set_cmd := self._lua_runtime.build_control(nested_status, status=self._attributes):
await self._build_send(set_cmd)
return
except Exception as e:
MideaLogger.debug(f"LuaRuntimeError in set_attribute {nested_status}: {repr(e)}")
traceback.print_exc()
if self._lua_runtime is not None:
try:
if set_cmd := self._lua_runtime.build_control(nested_status, status=self._attributes):
await self._build_send(set_cmd)
return
except Exception as e:
MideaLogger.debug(f"LuaRuntimeError in set_attribute {nested_status}: {repr(e)}")
traceback.print_exc()
cloud = self._cloud
if cloud and hasattr(cloud, "send_device_control"):
@@ -193,13 +194,14 @@ class MiedaDevice(threading.Thread):
nested_status = self._convert_to_nested_structure(new_status)
if has_new:
try:
if set_cmd := self._lua_runtime.build_control(nested_status, status=self._attributes):
await self._build_send(set_cmd)
return
except Exception as e:
MideaLogger.debug(f"LuaRuntimeError in set_attributes {nested_status}: {repr(e)}")
traceback.print_exc()
if self._lua_runtime is not None:
try:
if set_cmd := self._lua_runtime.build_control(nested_status, status=self._attributes):
await self._build_send(set_cmd)
return
except Exception as e:
MideaLogger.debug(f"LuaRuntimeError in set_attributes {nested_status}: {repr(e)}")
traceback.print_exc()
cloud = self._cloud
if cloud and hasattr(cloud, "send_device_control"):
@@ -267,8 +269,9 @@ class MiedaDevice(threading.Thread):
async def refresh_status(self):
for query in self._queries:
if query_cmd := self._lua_runtime.build_query(query):
await self._build_send(query_cmd)
if self._lua_runtime is not None:
if query_cmd := self._lua_runtime.build_query(query):
await self._build_send(query_cmd)
def _parse_cloud_message(self, decrypted):
# MideaLogger.debug(f"Received: {decrypted}")

View File

@@ -90,17 +90,11 @@ class MideaDataUpdateCoordinator(DataUpdateCoordinator[MideaDeviceData]):
return self.data
try:
await self.device.refresh_status()
# # 使用传入的 cloud 实例(若可用)
# cloud = self._cloud
# if cloud and hasattr(cloud, "get_device_status"):
# try:
# status = await cloud.get_device_status(self._device_id)
# if isinstance(status, dict) and len(status) > 0:
# for k, v in status.items():
# self.device.attributes[k] = v
# except Exception as e:
# MideaLogger.debug(f"Cloud status fetch failed: {e}")
# 检查是否为中央空调设备T0x21
if self.device.device_type == 0x21:
await self._poll_central_ac_state()
else:
await self.device.refresh_status()
# 返回并推送当前状态
updated = MideaDeviceData(
@@ -117,6 +111,51 @@ class MideaDataUpdateCoordinator(DataUpdateCoordinator[MideaDeviceData]):
available=False,
connected=False,
)
async def _poll_central_ac_state(self) -> None:
"""轮询中央空调状态"""
try:
cloud = self._cloud
if cloud and hasattr(cloud, "get_central_ac_status"):
status_data = await cloud.get_central_ac_status([self._device_id])
if status_data and "appliances" in status_data:
# 找到对应的设备数据并更新到设备属性中
for appliance in status_data["appliances"]:
if appliance.get("type") == "0x21" and "extraData" in appliance:
extra_data = appliance["extraData"]
if "attr" in extra_data and "state" in extra_data["attr"]:
state = extra_data["attr"]["state"]
if "nodeid" in extra_data["attr"]:
self.device._attributes["nodeid"] = extra_data["attr"]["nodeid"]
if "masterId" in extra_data["attr"]:
self.device._attributes["masterId"] = extra_data["attr"]["masterId"]
if "modelid" in extra_data["attr"]:
self.device._attributes["modelid"] = extra_data["attr"]["modelid"]
if "idType" in extra_data["attr"]:
self.device._attributes["idType"] = extra_data["attr"]["idType"]
if "condition_attribute" in state:
condition = state["condition_attribute"]
# 将状态数据更新到设备属性中
for key, value in condition.items():
# 尝试将数字字符串转换为数字
if key.find("temp") > -1:
try:
# 尝试转换为整数
if '.' not in value:
self.device._attributes[key] = int(value)
else:
# 尝试转换为浮点数
self.device._attributes[key] = float(value)
except (ValueError, TypeError):
# 如果转换失败,保持原值
self.device._attributes[key] = value
else:
self.device._attributes[key] = value
break
except Exception as e:
MideaLogger.debug(f"Error polling central AC state: {e}")
async def async_set_attribute(self, attribute: str, value) -> None:
"""Set a device attribute."""
@@ -140,4 +179,75 @@ class MideaDataUpdateCoordinator(DataUpdateCoordinator[MideaDeviceData]):
self.device.send_command(cmd_type, cmd_body_bytes)
except ValueError as e:
_LOGGER.error(f"Invalid command body: {e}")
raise
raise
async def async_send_central_ac_control(self, control: dict) -> bool:
"""发送中央空调控制命令"""
try:
cloud = self._cloud
if cloud and hasattr(cloud, "send_central_ac_control"):
# 从设备属性中获取nodeid
masterid = self.device.attributes.get("masterId")
nodeid = self.device.attributes.get("nodeid")
modelid = self.device.attributes.get("modelid")
idtype = int(self.device.attributes.get("idType"))
if not nodeid:
MideaLogger.warning(f"No nodeid found for central AC device {self._device_id}")
return False
# 构建完整的控制命令包含centralized中的所有字段
full_control = self._build_full_central_ac_control(control)
MideaLogger.debug(f"Sending control to {self.device.device_name}: {full_control}")
success = await cloud.send_central_ac_control(
masterid,
nodeid,
modelid,
idtype,
full_control
)
if success:
# 更新本地状态
self.device.attributes.update(control)
self.mute_state_update_for_a_while()
self.async_update_listeners()
return True
else:
MideaLogger.debug(f"Failed to send control to {self.device.device_name}")
return False
else:
MideaLogger.debug("Cloud service not available for central AC control")
return False
except Exception as e:
MideaLogger.debug(f"Error sending control to {self.device.device_name}: {e}")
return False
def _build_full_central_ac_control(self, new_control: dict) -> dict:
"""构建完整控制命令"""
full_control = {}
full_control["run_mode"] = self.device.attributes.get("run_mode")
full_control["cooling_temp"] = str(self.device.attributes.get("cool_temp_set") or 26.0)
full_control["heating_temp"] = str(self.device.attributes.get("heat_temp_set") or 20.0)
full_control["fan_speed"] = self.device.attributes.get("fan_speed")
swing_mode = self.device.attributes.get("is_swing")
is_elec_heat = self.device.attributes.get("is_elec_heat")
if swing_mode == "1":
# 开启摆风:如果当前有电辅热(2)则设为6(电辅热+摆风)否则设为4(摆风)
if is_elec_heat == "1":
new_extflag = "6" # 电辅热+摆风
else:
new_extflag = "4" # 仅摆风
else:
# 关闭摆风如果当前是6(电辅热+摆风)则设为2(仅电辅热)否则设为0(关闭)
if is_elec_heat == "1":
new_extflag = "2" # 仅电辅热
else:
new_extflag = "0" # 关闭
full_control["extflag"] = new_extflag
# 然后用新的控制值覆盖
full_control.update(new_control)
return full_control

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,68 @@
from homeassistant.const import Platform
DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [],
"entities": {
Platform.LIGHT: {
"light": {
"power": "power",
"brightness": {"brightness": [1, 100]},
"color_temp": {"color_temperature": [3000, 5700]}, # 添加色温配置
"preset_modes": {
"night": {"scene_light": "night"},
"read": {"scene_light": "read"},
"mild": {"scene_light": "mild"},
"life": {"scene_light": "life"},
"film": {"scene_light": "film"},
"manual": {"scene_light": "manual"},
}
}
}
}
},
"M0200015": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [],
"entities": {
Platform.LIGHT: {
"light": {
"power": "led_power",
"brightness": {"brightness": [1, 100]},
"color_temp": {"color_temperature": [2700, 6500]},
"preset_modes": {
"work": {"led_scene_light": "work"},
"eating": {"led_scene_light": "eating"},
"film": {"led_scene_light": "film"},
"night": {"led_scene_light": "night"},
"ledmanual": {"led_scene_light": "ledmanual"},
}
}
},
Platform.FAN: {
"fan": {
"power": "fan_power",
"fan_speed": [
{"fan_speed": "1"},
{"fan_speed": "2"},
{"fan_speed": "3"},
{"fan_speed": "4"},
{"fan_speed": "5"},
{"fan_speed": "6"},
],
"preset_modes": {
"breathing_wind": {"fan_scene": "breathing_wind"},
"const_temperature": {"fan_scene": "const_temperature"},
"fanmanual": {"fan_scene": "fanmanual"},
"baby_wind": {"fan_scene": "baby_wind"},
"sleep_wind": {"fan_scene": "sleep_wind"},
"forest_wind": {"fan_scene": "forest_wind"}
}
}
}
}
}
}

View File

@@ -0,0 +1,89 @@
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": ["run_mode", "fan_speed", "cooling_temp", "heating_temp", "extflag"],
"entities": {
Platform.CLIMATE: {
"thermostat": {
"power": "run_mode",
"hvac_modes": {
"off": {"run_mode": "0"},
"fan_only": {"run_mode": "1"},
"cool": {"run_mode": "2"},
"heat": {"run_mode": "3"},
"auto": {"run_mode": "4"},
"dry": {"run_mode": "5"}
},
"fan_modes": {
"off": {"fan_speed": "0"},
"1": {"fan_speed": "1"},
"2": {"fan_speed": "2"},
"3": {"fan_speed": "3"},
"4": {"fan_speed": "4"},
"5": {"fan_speed": "5"},
"6": {"fan_speed": "6"},
"7": {"fan_speed": "7"},
"auto": {"fan_speed": "8"}
},
"preset_modes": {
"none": {"extflag": "0"},
"electric_heat": {"extflag": "2"},
"swing": {"extflag": "4"},
"electric_heat_swing": {"extflag": "6"}
},
"target_temperature": ["temperature", "small_temperature"],
"current_temperature": "room_temp",
"pre_mode": "mode",
"aux_heat": "ptc",
"min_temp": 17,
"max_temp": 30,
"temperature_unit": UnitOfTemperature.CELSIUS,
"precision": PRECISION_HALVES,
}
},
Platform.SWITCH: {
"is_lock_heat": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ['0', '1']
},
"is_lock_cool": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ['0', '1']
},
"fan_speed_lock": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ['0', '1']
},
"is_lock_rc": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ['0', '1']
},
},
Platform.SENSOR: {
"room_temp": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT,
"precision": PRECISION_HALVES
},
"cool_temp_set": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT,
"precision": PRECISION_HALVES
},
"heat_temp_set": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT,
"precision": PRECISION_HALVES
},
}
}
}
}

View File

@@ -0,0 +1,145 @@
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES, UnitOfTime
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [
"blowing_direction", "function_led_enable", "smelly_trigger", "subpacket_type",
"heating_direction", "light_mode", "drying_time", "wifi_led_enable", "mode",
"night_light_brightness", "bath_heating_time", "bath_direction", "delay_enable",
"main_light_brightness", "current_temperature", "digit_led_enable", "version",
"dehumidity_trigger", "delay_time", "bath_temperature", "blowing_speed"
],
"entities": {
Platform.SWITCH: {
"function_led_enable": {
"device_class": SwitchDeviceClass.SWITCH,
},
"smelly_trigger": {
"device_class": SwitchDeviceClass.SWITCH,
},
"wifi_led_enable": {
"device_class": SwitchDeviceClass.SWITCH,
},
"delay_enable": {
"device_class": SwitchDeviceClass.SWITCH,
},
"digit_led_enable": {
"device_class": SwitchDeviceClass.SWITCH,
},
"dehumidity_trigger": {
"device_class": SwitchDeviceClass.SWITCH,
}
},
Platform.SELECT: {
"blowing_direction": {
"options": {
"0": {"blowing_direction": 0},
"45": {"blowing_direction": 45},
"90": {"blowing_direction": 90},
"135": {"blowing_direction": 135},
"180": {"blowing_direction": 180},
"225": {"blowing_direction": 225},
"253": {"blowing_direction": 253}
}
},
"heating_direction": {
"options": {
"0": {"heating_direction": 0},
"45": {"heating_direction": 45},
"90": {"heating_direction": 90},
"135": {"heating_direction": 135},
"180": {"heating_direction": 180},
"225": {"heating_direction": 225},
"253": {"heating_direction": 253}
}
},
"light_mode": {
"options": {
"close_all": {"light_mode": "close_all"},
"night_light": {"light_mode": "night_light"},
"main_light": {"light_mode": "main_light"}
}
},
"mode": {
"options": {
"close_all": {"mode": "close_all"},
"strong_heating": {"mode": "strong_heating"},
"weak_heating": {"mode": "weak_heating"},
"heating": {"mode": "heating"},
"bath": {"mode": "bath"},
"soft_wind": {"mode": "soft_wind"},
"ventilation": {"mode": "ventilation"},
"morning_ventilation": {"mode": "morning_ventilation"},
"drying": {"mode": "drying"},
"blowing": {"mode": "blowing"},
"drying_safe_power": {"mode": "drying_safe_power"},
"drying_fast": {"mode": "drying_fast"}
}
},
"bath_direction": {
"options": {
"0": {"bath_direction": 0},
"45": {"bath_direction": 45},
"90": {"bath_direction": 90},
"135": {"bath_direction": 135},
"180": {"bath_direction": 180},
"225": {"bath_direction": 225},
"253": {"bath_direction": 253}
}
},
"drying_direction": {
"options": {
"0": {"drying_direction": 0},
"45": {"drying_direction": 45},
"90": {"drying_direction": 90},
"135": {"drying_direction": 135},
"180": {"drying_direction": 180},
"225": {"drying_direction": 225},
"253": {"drying_direction": 253}
}
}
},
Platform.SENSOR: {
"drying_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"night_light_brightness": {
"device_class": SensorDeviceClass.ENUM,
},
"bath_heating_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"main_light_brightness": {
"device_class": SensorDeviceClass.ENUM,
},
"current_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"delay_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"bath_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"blowing_speed": {
"device_class": SensorDeviceClass.ENUM,
}
}
}
}
}

View File

@@ -0,0 +1,92 @@
from homeassistant.components.humidifier import HumidifierDeviceClass
from homeassistant.const import Platform, UnitOfTime
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [],
"entities": {
Platform.SWITCH: {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"anion": {
"device_class": SwitchDeviceClass.SWITCH,
},
"child_lock": {
"device_class": SwitchDeviceClass.SWITCH,
},
"wind_swing_ud": {
"device_class": SwitchDeviceClass.SWITCH,
},
"filter_tip": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
},
Platform.HUMIDIFIER: {
"dehumidifier": {
"device_class": HumidifierDeviceClass.HUMIDIFIER,
"power": "power",
"target_humidity": "humidity",
"current_humidity": "cur_humidity",
"min_humidity": 35,
"max_humidity": 85,
"mode": "mode",
"modes": {
"continuity": {"mode": "continuity"},
"auto": {"mode": "auto"},
"fan": {"mode": "fan"},
"dry_shoes": {"mode": "dry_shoes"},
"dry_clothes": {"mode": "dry_clothes"}
}
}
},
Platform.BINARY_SENSOR: {
"tank_status": {
"device_class": BinarySensorDeviceClass.PROBLEM
}
},
Platform.SELECT: {
"wind_speed": {
"options": {
"low": {"wind_speed": "30"},
"high": {"wind_speed": "80"},
}
},
"power_on_time": {
"options": {
"off": {"power_on_timer": "off"},
"15": {"power_on_timer": "on", "power_on_time_value": "15"},
"30": {"power_on_timer": "on", "power_on_time_value": "30"},
"45": {"power_on_timer": "on", "power_on_time_value": "45"},
"60": {"power_on_timer": "on", "power_on_time_value": "60"},
}
},
"power_off_time": {
"options": {
"off": {"power_off_timer": "off"},
"15": {"power_off_timer": "on", "power_off_time_value": "15"},
"30": {"power_off_timer": "on", "power_off_time_value": "30"},
"45": {"power_off_timer": "on", "power_off_time_value": "45"},
"60": {"power_off_timer": "on", "power_off_time_value": "60"},
}
},
},
Platform.SENSOR: {
"water_full_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"water_full_level": {
"device_class": SensorDeviceClass.ENUM
},
}
}
}
}

View File

@@ -91,6 +91,7 @@ DEVICE_MAPPING = {
},
"target_temperature": ["temperature", "small_temperature"],
"current_temperature": "indoor_temperature",
"pre_mode": "mode",
"aux_heat": "ptc",
"min_temp": 17,
"max_temp": 30,
@@ -108,13 +109,16 @@ DEVICE_MAPPING = {
},
"prevent_straight_wind": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [1, 2]
"rationale": [0, 1]
},
"aux_heat": {
"device_class": SwitchDeviceClass.SWITCH,
}
},
Platform.SENSOR: {
"mode": {
"device_class": SensorDeviceClass.ENUM,
},
"indoor_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
@@ -128,6 +132,55 @@ DEVICE_MAPPING = {
}
}
},
"26093139": {
"rationale": [0, 3],
"queries": [{}, {"query_type": "run_status"}],
"centralized": ["fresh_air", "fresh_air_mode", "fresh_air_fan_speed", "fresh_air_temp"],
"entities": {
Platform.FAN: {
"fan": {
"power": "fresh_air",
"speeds": [
{"fresh_air": 3, "fresh_air_fan_speed": 20},
{"fresh_air": 3, "fresh_air_fan_speed": 40},
{"fresh_air": 3, "fresh_air_fan_speed": 60},
{"fresh_air": 3, "fresh_air_fan_speed": 80},
{"fresh_air": 3, "fresh_air_fan_speed": 100},
],
"preset_modes": {
"heat_exchange": {
"fresh_air_mode": 1,
"wind_strength": 0
},
"smooth_in": {
"fresh_air_mode": 2,
"wind_strength": 0
},
"rough_in": {
"fresh_air_mode": 2,
"wind_strength": 1
},
"smooth_out": {
"fresh_air_mode": 3,
"wind_strength": 0
},
"rough_out": {
"fresh_air_mode": 3,
"wind_strength": 1
},
"auto": {
"fresh_air_mode": 4,
"wind_strength": 0
},
"innercycle": {
"fresh_air_mode": 5,
"wind_strength": 0
},
}
}
},
}
},
"22012227": {
"rationale": ["off", "on"],
"queries": [{}],
@@ -175,6 +228,7 @@ DEVICE_MAPPING = {
},
"target_temperature": ["temperature", "small_temperature"],
"current_temperature": "indoor_temperature",
"pre_mode": "mode",
"aux_heat": "ptc",
"min_temp": 17,
"max_temp": 30,
@@ -198,6 +252,9 @@ DEVICE_MAPPING = {
}
},
Platform.SENSOR: {
"mode": {
"device_class": SensorDeviceClass.ENUM,
},
"indoor_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,

View File

@@ -0,0 +1,34 @@
from homeassistant.const import Platform
from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [],
"entities": {
Platform.SWITCH: {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"light": {
"device_class": SwitchDeviceClass.SWITCH,
},
"wisdom_wind": {
"device_class": SwitchDeviceClass.SWITCH,
}
},
Platform.SELECT: {
"wind_pressure": {
"options": {
"off": {"wind_pressure": "0"},
"low": {"wind_pressure": "1"},
"medium": {"wind_pressure": "2"},
"high": {"wind_pressure": "3"},
"extreme": {"wind_pressure": "4"},
}
},
},
}
}
}

View File

@@ -0,0 +1,117 @@
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES, UnitOfTime
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [
"left_power", "left_recipe_current_step_action", "left_recipe_id",
"left_dry_fire_protection", "left_recipe_rest_time", "left_gear",
"left_current_temperature", "lock", "left_status", "eq_recipe_action",
"left_lock", "gas_leakage_code", "left_work_time", "left_recipe_current_step",
"left_recipe_target_steps", "version", "left_recipe_target_time",
"is_error", "left_cookmode", "light_lampblack_mode", "error_type"
],
"entities": {
Platform.SWITCH: {
"left_power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"left_dry_fire_protection": {
"device_class": SwitchDeviceClass.SWITCH,
},
"left_lock": {
"device_class": SwitchDeviceClass.SWITCH,
},
"lock": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ['0', '1'],
},
"light_lampblack_mode": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1],
}
},
Platform.SELECT: {
"left_cookmode": {
"options": {
"default": {"left_cookmode": "default"},
"order": {"left_cookmode": "order"},
"keep_temperature": {"left_cookmode": "keep_temperature"},
"local_recipe": {"left_cookmode": "local_recipe"},
"cloud_recipe": {"left_cookmode": "cloud_recipe"},
"order_keep_temperature": {"left_cookmode": "order_keep_temperature"},
}
},
"left_gear": {
"options": {
"0": {"left_gear": 0},
"1": {"left_gear": 1},
"2": {"left_gear": 2},
"3": {"left_gear": 3},
"4": {"left_gear": 4},
"5": {"left_gear": 5},
"6": {"left_gear": 6},
"7": {"left_gear": 7},
"8": {"left_gear": 8},
"9": {"left_gear": 9}
}
},
},
Platform.SENSOR: {
"left_recipe_current_step_action": {
"device_class": SensorDeviceClass.ENUM,
},
"left_recipe_id": {
"device_class": SensorDeviceClass.ENUM,
},
"left_recipe_rest_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.SECONDS,
"state_class": SensorStateClass.MEASUREMENT
},
"left_current_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"left_status": {
"device_class": SensorDeviceClass.ENUM,
},
"eq_recipe_action": {
"device_class": SensorDeviceClass.ENUM,
},
"gas_leakage_code": {
"device_class": SensorDeviceClass.ENUM,
},
"left_work_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.SECONDS,
"state_class": SensorStateClass.MEASUREMENT
},
"left_recipe_current_step": {
"device_class": SensorDeviceClass.ENUM,
},
"left_recipe_target_steps": {
"device_class": SensorDeviceClass.ENUM
},
"left_recipe_target_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.SECONDS,
"state_class": SensorStateClass.MEASUREMENT
},
"error_type": {
"device_class": SensorDeviceClass.ENUM,
}
},
Platform.BINARY_SENSOR: {
"is_error": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
}
}
}
}

View File

@@ -1,7 +1,6 @@
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES, UnitOfTime, UnitOfArea, UnitOfVolume
from homeassistant.const import Platform, UnitOfTime, UnitOfArea
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
"default": {
@@ -10,90 +9,47 @@ DEVICE_MAPPING = {
"centralized": [],
"entities": {
Platform.SELECT: {
"fan_level": {
"fan_setting": {
"options": {
"low": {"fan_level": "low"},
"medium": {"fan_level": "medium"},
"high": {"fan_level": "high"},
"auto": {"fan_level": "auto"}
"soft": {"level": "soft"},
"normal": {"level": "normal"},
"high": {"level": "high"},
"super": {"level": "super"}
}
},
"work_mode": {
"options": {
"none": {"work_mode": "none"},
"auto": {"work_mode": "auto"},
"spot": {"work_mode": "spot"},
"edge": {"work_mode": "edge"},
"single_room": {"work_mode": "single_room"},
"custom": {"work_mode": "custom"}
"sweep_and_mop": {"work_mode": "sweep_and_mop"},
"sweep": {"work_mode": "sweep"},
"mop": {"work_mode": "mop"},
"sweep_then_mop": {"work_mode": "sweep_then_mop"}
}
},
"work_status": {
"options": {
"idle": {"work_status": "idle"},
"cleaning": {"work_status": "cleaning"},
"returning": {"work_status": "returning"},
"docked": {"work_status": "docked"},
"on_base": {"work_status": "on_base"},
"charging": {"work_status": "charging"},
"error": {"work_status": "error"}
"charge": {"work_status": "charge"},
"charge_pause": {"work_status": "charge_pause"},
"charge_continue": {"work_status": "charge_continue"},
"auto_clean": {"work_status": "auto_clean"},
"auto_clean_pause": {"work_status": "auto_clean_pause"},
"auto_clean_continue": {"work_status": "auto_clean_continue"},
"pause": {"work_status": "pause"},
"stop": {"work_status": "stop"},
"work": {"work_status": "work"},
"video_cruise_start": {"work_status": "video_cruise_start"},
"video_cruise_pause": {"work_status": "video_cruise_pause"},
"mop_clean": {"mop_clean_setting": {"mode_type": "common", "clean_level": "normal"}},
"dry_mop_on": {"work_status": "dry_mop", "switch": "on"},
"dry_mop_off": {"work_status": "dry_mop", "switch": "off"},
}
},
"move_direction": {
"water_tank_setting": {
"options": {
"none": {"move_direction": "none"},
"forward": {"move_direction": "forward"},
"backward": {"move_direction": "backward"},
"left": {"move_direction": "left"},
"right": {"move_direction": "right"}
"low": {"level": "low"},
"normal": {"level": "normal"},
"high": {"level": "high"}
}
},
"query_type": {
"options": {
"work": {"query_type": "work"},
"status": {"query_type": "status"},
"battery": {"query_type": "battery"},
"error": {"query_type": "error"}
}
},
"sub_work_status": {
"options": {
"idle": {"sub_work_status": "idle"},
"cleaning": {"sub_work_status": "cleaning"},
"charging": {"sub_work_status": "charging"},
"charge_finish": {"sub_work_status": "charge_finish"},
"error": {"sub_work_status": "error"}
}
},
"water_level": {
"options": {
"low": {"water_level": "low"},
"normal": {"water_level": "normal"},
"high": {"water_level": "high"}
}
},
"mop_status": {
"options": {
"normal": {"mop_status": "normal"},
"lack_water": {"mop_status": "lack_water"},
"full_water": {"mop_status": "full_water"}
}
},
"error_type": {
"options": {
"no_error": {"error_type": "no_error"},
"can_fix": {"error_type": "can_fix"},
"need_help": {"error_type": "need_help"}
}
},
"control_type": {
"options": {
"none": {"control_type": "none"},
"app": {"control_type": "app"},
"remote": {"control_type": "remote"},
"auto": {"control_type": "auto"}
}
}
},
Platform.BINARY_SENSOR: {
"carpet_switch": {
@@ -104,6 +60,18 @@ DEVICE_MAPPING = {
}
},
Platform.SENSOR: {
"fan_level": {
"device_class": SensorDeviceClass.ENUM
},
"mop": {
"device_class": SensorDeviceClass.ENUM
},
"sub_work_status": {
"device_class": SensorDeviceClass.ENUM
},
"move_direction": {
"device_class": SensorDeviceClass.ENUM
},
"dust_count": {
"device_class": SensorDeviceClass.ENUM
},

View File

@@ -11,7 +11,7 @@ DEVICE_MAPPING = {
"freezing_mode", "intelligent_mode", "energy_saving_mode", "holiday_mode",
"moisturize_mode", "preservation_mode", "acme_freezing_mode", "variable_mode",
"storage_power", "left_flexzone_power", "right_flexzone_power", "freezing_power",
"function_zone_power", "storage_temperature", "freezing_temperature",
"storage_temperature", "freezing_temperature",
"left_flexzone_temperature", "right_flexzone_temperature"
],
"entities": {
@@ -49,9 +49,6 @@ DEVICE_MAPPING = {
"freezing_power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"function_zone_power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"cross_peak_electricity": {
"device_class": SwitchDeviceClass.SWITCH,
},
@@ -138,10 +135,11 @@ DEVICE_MAPPING = {
"power": "storage_power",
"hvac_modes": {
"off": {"storage_power": "off"},
"heat": {"storage_power": "on"}
"cool": {"storage_power": "on"}
},
"target_temperature": "storage_temperature",
"current_temperature": "refrigeration_real_temperature",
"pre_mode": "mode",
"min_temp": -10,
"max_temp": 10,
"temperature_unit": UnitOfTemperature.CELSIUS,
@@ -151,7 +149,7 @@ DEVICE_MAPPING = {
"power": "freezing_power",
"hvac_modes": {
"off": {"freezing_power": "off"},
"heat": {"freezing_power": "on"}
"cool": {"freezing_power": "on"}
},
"target_temperature": "freezing_temperature",
"current_temperature": "freezing_real_temperature",
@@ -164,7 +162,7 @@ DEVICE_MAPPING = {
"power": "left_flexzone_power",
"hvac_modes": {
"off": {"left_flexzone_power": "off"},
"heat": {"left_flexzone_power": "on"}
"cool": {"left_flexzone_power": "on"}
},
"target_temperature": "left_flexzone_temperature",
"current_temperature": "left_variable_real_temperature",
@@ -177,7 +175,7 @@ DEVICE_MAPPING = {
"power": "right_flexzone_power",
"hvac_modes": {
"off": {"right_flexzone_power": "off"},
"heat": {"right_flexzone_power": "on"}
"cool": {"right_flexzone_power": "on"}
},
"target_temperature": "right_flexzone_temperature",
"current_temperature": "right_variable_real_temperature",
@@ -191,26 +189,27 @@ DEVICE_MAPPING = {
"variable_mode": {
"options": {
"none_mode": {"variable_mode": "none_mode"},
"freezing": {"variable_mode": "freezing"},
"refrigeration": {"variable_mode": "refrigeration"},
"wine": {"variable_mode": "wine"},
"vegetable": {"variable_mode": "vegetable"}
"soft_freezing_mode": {"variable_mode": "soft_freezing_mode"},
"zero_fresh_mode": {"variable_mode": "zero_fresh_mode"},
"cold_drink_mode": {"variable_mode": "cold_drink_mode"},
"fresh_product_mode": {"variable_mode": "fresh_product_mode"},
"partial_freezing_mode": {"variable_mode": "partial_freezing_mode"},
"dry_zone_mode": {"variable_mode": "dry_zone_mode"},
"freeze_warm_mode": {"variable_mode": "freeze_warm_mode"},
"freeze_mode": {"variable_mode": "freeze_mode"},
}
},
"icea_bar_function_switch": {
"options": {
"default": {"icea_bar_function_switch": "default"},
"ice": {"icea_bar_function_switch": "ice"},
"water": {"icea_bar_function_switch": "water"},
"off": {"icea_bar_function_switch": "off"}
"refrigeration": {"icea_bar_function_switch": "refrigeration"},
"freezing": {"icea_bar_function_switch": "freezing"},
}
},
"food_site": {
"options": {
"left_freezing_room": {"food_site": "left_freezing_room"},
"right_freezing_room": {"food_site": "right_freezing_room"},
"storage_room": {"food_site": "storage_room"},
"function_zone": {"food_site": "function_zone"}
}
},
"temperature_unit": {

View File

@@ -48,6 +48,7 @@ DEVICE_MAPPING = {
},
"target_temperature": "temperature.current",
"current_temperature": "temperature.room",
"pre_mode": "mode",
"min_temp": 17,
"max_temp": 30,
"temperature_unit": UnitOfTemperature.CELSIUS,
@@ -89,6 +90,9 @@ DEVICE_MAPPING = {
}
},
Platform.SENSOR: {
"mode": {
"device_class": SensorDeviceClass.ENUM,
},
"room_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,

View File

@@ -22,6 +22,7 @@ DEVICE_MAPPING = {
},
"target_temperature": "temp_set",
"current_temperature": "cur_temp",
"pre_mode": "mode",
"min_temp": 5,
"max_temp": 70,
"temperature_unit": UnitOfTemperature.CELSIUS,
@@ -103,6 +104,9 @@ DEVICE_MAPPING = {
}
},
Platform.SENSOR: {
"mode": {
"device_class": SensorDeviceClass.ENUM,
},
"cur_temp": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,

View File

@@ -19,59 +19,25 @@ DEVICE_MAPPING = {
},
"entities": {
Platform.BINARY_SENSOR: {
"power": {
"device_class": BinarySensorDeviceClass.RUNNING,
"softener_lack": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"detergent_lack": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"door_opened": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"bucket_water_overheating": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
},
Platform.SWITCH: {
"softener_lack": {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"detergent_lack": {
"device_class": SwitchDeviceClass.SWITCH,
},
"door_opened": {
"device_class": SwitchDeviceClass.SWITCH,
},
"bucket_water_overheating": {
"device_class": SwitchDeviceClass.SWITCH,
},
"memory": {
"device_class": SwitchDeviceClass.SWITCH,
},
"appointment": {
"device_class": SwitchDeviceClass.SWITCH,
},
"spray_wash": {
"device_class": SwitchDeviceClass.SWITCH,
},
"old_speedy": {
"device_class": SwitchDeviceClass.SWITCH,
},
"nightly": {
"device_class": SwitchDeviceClass.SWITCH,
},
"down_light": {
"device_class": SwitchDeviceClass.SWITCH,
},
"easy_ironing": {
"device_class": SwitchDeviceClass.SWITCH,
},
"super_clean_wash": {
"device_class": SwitchDeviceClass.SWITCH,
},
"intelligent_wash": {
"device_class": SwitchDeviceClass.SWITCH,
},
"strong_wash": {
"device_class": SwitchDeviceClass.SWITCH,
},
"silent": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ["0", "1"],
},
"speedy": {
"device_class": SwitchDeviceClass.SWITCH,
"control_status": {
"rationale": ["pause", "start"],
},
"lock": {
"device_class": SwitchDeviceClass.SWITCH,
@@ -79,36 +45,6 @@ DEVICE_MAPPING = {
"flocks_switcher": {
"device_class": SwitchDeviceClass.SWITCH,
},
"fresh_anion_switch": {
"device_class": SwitchDeviceClass.SWITCH,
},
"dry_weighing_already": {
"device_class": SwitchDeviceClass.SWITCH,
},
"keep_fresh_status": {
"device_class": SwitchDeviceClass.SWITCH,
},
"drying_tunnel_overheating": {
"device_class": SwitchDeviceClass.SWITCH,
},
"fast_clean_wash": {
"device_class": SwitchDeviceClass.SWITCH,
},
"steam_wash": {
"device_class": SwitchDeviceClass.SWITCH,
},
"beforehand_wash": {
"device_class": SwitchDeviceClass.SWITCH,
},
"ai_flag": {
"device_class": SwitchDeviceClass.SWITCH,
},
"water_plus": {
"device_class": SwitchDeviceClass.SWITCH,
},
"soak": {
"device_class": SwitchDeviceClass.SWITCH,
},
"ultraviolet_lamp": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ["0", "1"],
@@ -128,27 +64,8 @@ DEVICE_MAPPING = {
"cycle_memory": {
"device_class": SwitchDeviceClass.SWITCH,
},
"disinfectant": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ["0", "1"],
},
"add_rinse": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ["0", "1"],
},
},
Platform.SELECT: {
"running_status": {
"options": {
"off": {"power": "off", "running_status": "off"},
"standby": {"power": "on", "running_status": "standby"},
"start": {"power": "on", "running_status": "start"},
"pause": {"power": "on", "running_status": "pause"},
"end": {"power": "on", "running_status": "end"},
"fault": {"power": "on", "running_status": "fault"},
"delay": {"power": "on", "running_status": "delay"}
}
},
"dehydration_speed": {
"options": {
"0": {"dehydration_speed": "0"},
@@ -327,6 +244,9 @@ DEVICE_MAPPING = {
}
},
Platform.SENSOR: {
"running_status": {
"device_class": SensorDeviceClass.ENUM
},
"wash_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
@@ -353,44 +273,11 @@ DEVICE_MAPPING = {
"unit_of_measurement": "%",
"state_class": SensorStateClass.MEASUREMENT
},
"cloud_cycle_low": {
"device_class": SensorDeviceClass.ENUM
},
"cloud_cycle_high": {
"device_class": SensorDeviceClass.ENUM
},
"cloud_cycle_jiepai1": {
"device_class": SensorDeviceClass.ENUM
},
"cloud_cycle_jiepai2": {
"device_class": SensorDeviceClass.ENUM
},
"cloud_cycle_jiepai3": {
"device_class": SensorDeviceClass.ENUM
},
"cloud_cycle_jiepai4": {
"device_class": SensorDeviceClass.ENUM
},
"cloud_cycle_jiepai_time1": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"dehydration_time_value": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"cloud_cycle_jiepai_time3": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"cloud_cycle_jiepai_time4": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"customize_machine_cycle": {
"device_class": SensorDeviceClass.ENUM
},
@@ -416,9 +303,6 @@ DEVICE_MAPPING = {
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"device_software_version": {
"device_class": SensorDeviceClass.ENUM
},
"expert_step": {
"device_class": SensorDeviceClass.ENUM
},

View File

@@ -7,53 +7,59 @@ DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [
"power", "ai_switch", "light", "appointment", "prevent_wrinkle_switch",
"steam_switch", "damp_dry_signal", "eco_dry_switch", "bucket_clean_switch",
"water_box", "baby_lock", "remind_sound", "steam", "prevent_wrinkle",
"material", "sterilize", "dryness_level", "dry_temp", "intensity", "program"
],
"centralized": [],
"entities": {
Platform.SWITCH: {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"control_status": {
"rationale": ["pause", "start"],
},
"ai_switch": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"light": {
"device_class": SwitchDeviceClass.SWITCH,
},
"appointment": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"prevent_wrinkle_switch": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"steam_switch": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"damp_dry_signal": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"eco_dry_switch": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"bucket_clean_switch": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"water_box": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"baby_lock": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"remind_sound": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"steam": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"power": {
"device_class": SwitchDeviceClass.SWITCH,
}
},
Platform.BINARY_SENSOR: {
"door_warn": {
@@ -61,65 +67,75 @@ DEVICE_MAPPING = {
}
},
Platform.SELECT: {
"prevent_wrinkle": {
"options": {
"off": {"prevent_wrinkle": "0"},
"low": {"prevent_wrinkle": "1"},
"medium": {"prevent_wrinkle": "2"},
"high": {"prevent_wrinkle": "3"}
}
},
"material": {
"options": {
"cotton": {"material": "0"},
"synthetic": {"material": "1"},
"wool": {"material": "2"},
"delicate": {"material": "3"},
"mixed": {"material": "4"}
}
},
"sterilize": {
"options": {
"off": {"sterilize": "0"},
"on": {"sterilize": "1"}
}
},
"dryness_level": {
"options": {
"extra_dry": {"dryness_level": "0"},
"dry": {"dryness_level": "1"},
"normal": {"dryness_level": "2"},
"damp": {"dryness_level": "3"}
}
},
"dry_temp": {
"options": {
"low": {"dry_temp": "0"},
"medium": {"dry_temp": "1"},
"high": {"dry_temp": "2"},
"extra_high": {"dry_temp": "3"}
}
},
"intensity": {
"options": {
"low": {"intensity": "0"},
"medium": {"intensity": "1"},
"high": {"intensity": "2"}
}
},
"program": {
"options": {
"mixed_wash": {"program": "mixed_wash"},
"cotton": {"program": "cotton"},
"synthetic": {"program": "synthetic"},
"fiber": {"program": "fiber"},
"mixed_wash": {"program": "mixed_wash"},
"jean": {"program": "jean"},
"bedsheet": {"program": "bedsheet"},
"outdoor": {"program": "outdoor"},
"down_jacket": {"program": "down_jacket"},
"plush": {"program": "plush"},
"wool": {"program": "wool"},
"delicate": {"program": "delicate"},
"quick": {"program": "quick"},
"eco": {"program": "eco"}
"dehumidify": {"program": "dehumidify"},
"cold_air_fresh_air": {"program": "cold_air_fresh_air"},
"hot_air_dry": {"program": "hot_air_dry"},
"sport_clothes": {"program": "sport_clothes"},
"underwear": {"program": "underwear"},
"baby_clothes": {"program": "baby_clothes"},
"shirt": {"program": "shirt"},
"standard": {"program": "standard"},
"quick_dry": {"program": "quick_dry"},
"fresh_air": {"program": "fresh_air"},
"low_temp_dry": {"program": "low_temp_dry"},
"eco_dry": {"program": "eco_dry"},
"quick_dry_30": {"program": "quick_dry_30"},
"towel": {"program": "towel"},
"intelligent_dry": {"program": "intelligent_dry"},
"steam_care": {"program": "steam_care"},
"big": {"program": "big"},
"fixed_time_dry": {"program": "fixed_time_dry"},
"night_dry": {"program": "night_dry"},
"bracket_dry": {"program": "bracket_dry"},
"western_trouser": {"program": "western_trouser"},
"dehumidification": {"program": "dehumidification"},
"smart_dry": {"program": "smart_dry"},
"four_piece_suit": {"program": "four_piece_suit"},
"warm_clothes": {"program": "warm_clothes"},
"quick_dry_20": {"program": "quick_dry_20"},
"steam_sterilize": {"program": "steam_sterilize"},
"enzyme": {"program": "enzyme"},
"big_60": {"program": "big_60"},
"steam_no_iron": {"program": "steam_no_iron"},
"air_wash": {"program": "air_wash"},
"bed_clothes": {"program": "bed_clothes"},
"little_fast_dry": {"program": "little_fast_dry"},
"small_piece_dry": {"program": "small_piece_dry"},
"big_dry": {"program": "big_dry"},
"wool_nurse": {"program": "wool_nurse"},
"sun_quilt": {"program": "sun_quilt"},
"fresh_remove_smell": {"program": "fresh_remove_smell"},
"bucket_self_clean": {"program": "bucket_self_clean"},
"silk": {"program": "silk"},
"sterilize": {"program": "sterilize"},
"heavy_duty": {"program": "heavy_duty"},
"towel_warmer": {"program": "towel_warmer"},
"air_fluff": {"program": "air_fluff"},
"delicates": {"program": "delicates"},
"time_drying_30": {"program": "time_drying_30"},
"time_drying_60": {"program": "time_drying_60"},
"time_drying_90": {"program": "time_drying_90"},
"dry_softnurse": {"program": "dry_softnurse"},
"uniforms": {"program": "uniforms"},
"remove_electricity": {"program": "remove_electricity"}
}
}
},
Platform.SENSOR: {
"running_status": {
"device_class": SensorDeviceClass.ENUM
},
"appointment_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,

View File

@@ -5,7 +5,7 @@ from homeassistant.components.switch import SwitchDeviceClass
DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"rationale": [0, 1],
"queries": [{}],
"centralized": [],
"entities": {
@@ -19,9 +19,6 @@ DEVICE_MAPPING = {
"uvswitch": {
"device_class": SwitchDeviceClass.SWITCH,
},
"doorswitch": {
"device_class": SwitchDeviceClass.SWITCH,
},
"dryswitch": {
"device_class": SwitchDeviceClass.SWITCH,
},
@@ -30,20 +27,23 @@ DEVICE_MAPPING = {
}
},
Platform.BINARY_SENSOR: {
"doorswitch": {
"device_class": BinarySensorDeviceClass.RUNNING,
},
"air_status": {
"device_class": BinarySensorDeviceClass.RUNNING,
},
"water_lack": {
"device_class": BinarySensorDeviceClass.RUNNING,
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"softwater_lack": {
"device_class": BinarySensorDeviceClass.RUNNING,
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"wash_stage":{
"device_class": BinarySensorDeviceClass.RUNNING,
},
"bright_lack": {
"device_class": BinarySensorDeviceClass.RUNNING,
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"diy_flag": {
"device_class": BinarySensorDeviceClass.RUNNING,
@@ -59,43 +59,54 @@ DEVICE_MAPPING = {
},
},
Platform.SELECT: {
"air_set_hour": {
"options": {
"12": {"air_set_hour": "12" },
"24": {"air_set_hour": "24" },
"36": {"air_set_hour": "36" },
"48": {"air_set_hour": "48" },
"60": {"air_set_hour": "60" },
"72": {"air_set_hour": "72" },
}
},
"work_status": {
"options": {
"power_off": {"work_status": "power_off" },
"power_on": {"work_status": "power_on" },
"cancel": {"work_status": "cancel" },
"pause": {"operator":"pause"},
"resume": {"operator":"start"},
}
},
"wash_mode": {
"options": {
"neutral_gear": {"mode": "neutral_gear"},
"auto_wash": {"mode": "auto_wash"},
"strong_wash": {"mode": "strong_wash"},
"standard_wash": {"mode": "standard_wash"},
"eco_wash": {"mode": "eco_wash"},
"glass_wash": {"mode": "glass_wash"},
"hour_wash": {"mode": "hour_wash"},
"fast_wash": {"mode": "fast_wash"},
"soak_wash": {"mode": "soak_wash"},
"90min_wash": {"mode": "90min_wash"},
"self_clean": {"mode": "self_clean"},
"fruit_wash": {"mode": "fruit_wash"},
"self_define": {"mode": "self_define"},
"germ": {"mode": "germ"},
"bowl_wash": {"mode": "bowl_wash"},
"kill_germ": {"mode": "kill_germ"},
"seafood_wash": {"mode": "seafood_wash"},
"hotpot_wash": {"mode": "hotpot_wash"},
"quietnight_wash": {"mode": "quietnight_wash"},
"less_wash": {"mode": "less_wash"},
"oilnet_wash": {"mode": "oilnet_wash"}
"neutral_gear": {"work_status": "work", "mode": "neutral_gear"},
"auto_wash": {"work_status": "work", "mode": "auto_wash"},
"strong_wash": {"work_status": "work", "mode": "strong_wash"},
"standard_wash": {"work_status": "work", "mode": "standard_wash"},
"eco_wash": {"work_status":"work","mode":"eco_wash","additional":0,"wash_region":3},
"glass_wash": {"work_status": "work", "mode": "glass_wash"},
"hour_wash": {"work_status": "work", "mode": "hour_wash"},
"fast_wash": {"work_status": "work", "mode": "fast_wash"},
"soak_wash": {"work_status": "work", "mode": "soak_wash"},
"90min_wash": {"work_status": "work", "mode": "90min_wash"},
"self_clean": {"work_status": "work", "mode": "self_clean"},
"fruit_wash": {"work_status": "work", "mode": "fruit_wash"},
"self_define": {"work_status": "work", "mode": "self_define"},
"germ": {"work_status": "work", "mode": "germ"},
"bowl_wash": {"work_status": "work", "mode": "bowl_wash"},
"kill_germ": {"work_status": "work", "mode": "kill_germ"},
"seafood_wash": {"work_status": "work", "mode": "seafood_wash"},
"hotpot_wash": {"work_status": "work", "mode": "hotpot_wash"},
"quietnight_wash": {"work_status": "work", "mode": "quietnight_wash"},
"less_wash": {"work_status": "work", "mode": "less_wash"},
"oilnet_wash": {"work_status": "work", "mode": "oilnet_wash"}
}
},
}
},
Platform.SENSOR: {
"bright": {
"device_class": SensorDeviceClass.ILLUMINANCE,
"unit_of_measurement": "lx",
"state_class": SensorStateClass.MEASUREMENT
"device_class": SensorDeviceClass.ENUM
},
"temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
@@ -103,18 +114,11 @@ DEVICE_MAPPING = {
"state_class": SensorStateClass.MEASUREMENT
},
"softwater": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
"device_class": SensorDeviceClass.ENUM
},
"left_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.HOURS,
"state_class": SensorStateClass.MEASUREMENT
},
"air_set_hour": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.HOURS,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"air_left_hour": {

View File

@@ -7,18 +7,14 @@ DEVICE_MAPPING = {
"default": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [
"power", "bubble", "cold_water", "bathtub", "safe", "cold_water_dot",
"change_litre_switch", "cold_water_ai", "cold_water_pressure",
"person_mode_one", "person_mode_two", "person_mode_three", "gesture_function",
"mode", "power_level", "type_machine", "capacity", "temperature"
],
"centralized": [],
"entities": {
Platform.SWITCH: {
"bubble": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1]
},
"cold_water": {
"cold_water_master": {
"device_class": SwitchDeviceClass.SWITCH,
},
"bathtub": {
@@ -48,9 +44,9 @@ DEVICE_MAPPING = {
"person_mode_three": {
"device_class": SwitchDeviceClass.SWITCH,
},
"gesture_function": {
"device_class": SwitchDeviceClass.SWITCH,
}
# "gesture_function": {
# "device_class": SwitchDeviceClass.SWITCH,
# }
},
Platform.CLIMATE: {
"water_heater": {
@@ -73,39 +69,48 @@ DEVICE_MAPPING = {
"shower": {"mode": "shower"},
"bath": {"mode": "bath"},
"mixed": {"mode": "mixed"},
"eco": {"mode": "eco"}
"eco": {"mode": "eco"},
"kitchen": {"mode": "kitchen"},
"thalposis": {"mode": "thalposis"},
"intelligence": {"mode": "intelligence"},
"unfreeze": {"mode": "unfreeze"},
"wash_bowl": {"mode": "wash_bowl"},
"high_temperature": {"mode": "high_temperature"},
"baby": {"mode": "baby"},
"adult": {"mode": "adult"},
"old": {"mode": "old"}
}
},
"power_level": {
"options": {
"low": {"power_level": "0"},
"medium": {"power_level": "1"},
"high": {"power_level": "2"},
"max": {"power_level": "3"}
"low": {"power_level": 0},
"medium": {"power_level": 1},
"high": {"power_level": 2},
"max": {"power_level": 3}
}
},
"type_machine": {
"options": {
"standard": {"type_machine": "20"},
"premium": {"type_machine": "21"},
"deluxe": {"type_machine": "22"}
"standard": {"type_machine": 20},
"premium": {"type_machine": 21},
"deluxe": {"type_machine": 22}
}
},
"capacity": {
"options": {
"small": {"capacity": "1"},
"medium": {"capacity": "2"},
"large": {"capacity": "3"}
"small": {"capacity": 1},
"medium": {"capacity": 2},
"large": {"capacity": 3}
}
},
"gesture_function_type": {
"options": {
"none": {"gesture_function_type": "0"},
"wave": {"gesture_function_type": "1"},
"touch": {"gesture_function_type": "2"},
"proximity": {"gesture_function_type": "3"}
}
}
# "gesture_function_type": {
# "options": {
# "none": {"gesture_function_type": "0"},
# "wave": {"gesture_function_type": "1"},
# "touch": {"gesture_function_type": "2"},
# "proximity": {"gesture_function_type": "3"}
# }
# }
},
Platform.SENSOR: {
"out_water_tem": {

View File

@@ -1,4 +1,4 @@
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES, UnitOfTime, UnitOfElectricPotential, \
from homeassistant.const import Platform, UnitOfTemperature, UnitOfTime, UnitOfElectricPotential, \
UnitOfVolume, UnitOfMass
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
@@ -14,9 +14,11 @@ DEVICE_MAPPING = {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"heat_start": {
"heat": {
"device_class": SwitchDeviceClass.SWITCH,
},
"antifreeze": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": [0, 1],
},
"lock": {
"device_class": SwitchDeviceClass.SWITCH,
@@ -42,6 +44,30 @@ DEVICE_MAPPING = {
"wash_enable": {
"device_class": SwitchDeviceClass.SWITCH,
},
"water_way": {
"device_class": SwitchDeviceClass.SWITCH,
},
"soften": {
"device_class": SwitchDeviceClass.SWITCH,
},
"regeneration": {
"device_class": SwitchDeviceClass.SWITCH,
},
"maintenance_reminder_switch": {
"device_class": SwitchDeviceClass.SWITCH,
},
"leak_water_protection": {
"device_class": SwitchDeviceClass.SWITCH,
},
"micro_leak_protection": {
"device_class": SwitchDeviceClass.SWITCH,
},
"cl_sterilization": {
"device_class": SwitchDeviceClass.SWITCH,
},
"holiday_mode": {
"device_class": SwitchDeviceClass.SWITCH,
},
},
Platform.BINARY_SENSOR: {
"heat_status": {
@@ -55,6 +81,30 @@ DEVICE_MAPPING = {
},
"rtc_error": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"low_salt": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"no_salt": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"low_battery": {
"device_class": BinarySensorDeviceClass.BATTERY,
},
"flowmeter_error": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"salt_level_sensor_error": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"leak_water": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"micro_leak": {
"device_class": BinarySensorDeviceClass.PROBLEM,
},
"maintenance_remind": {
"device_class": BinarySensorDeviceClass.PROBLEM,
}
},
Platform.SENSOR: {
@@ -63,6 +113,17 @@ DEVICE_MAPPING = {
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"input_temperature_Sensing": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT,
"translation_key": "input_temperature_sensing"
},
"hot_pot_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"cool_target_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
@@ -83,6 +144,126 @@ DEVICE_MAPPING = {
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"salt_alarm_threshold": {
"device_class": SensorDeviceClass.WEIGHT,
"unit_of_measurement": UnitOfMass.KILOGRAMS,
"state_class": SensorStateClass.MEASUREMENT
},
"left_salt": {
"device_class": SensorDeviceClass.BATTERY,
"unit_of_measurement": "%",
"state_class": SensorStateClass.MEASUREMENT
},
"salt_setting": {
"device_class": SensorDeviceClass.WEIGHT,
"unit_of_measurement": UnitOfMass.KILOGRAMS,
"state_class": SensorStateClass.MEASUREMENT
},
"supply_voltage": {
"device_class": SensorDeviceClass.VOLTAGE,
"unit_of_measurement": UnitOfElectricPotential.VOLT,
"state_class": SensorStateClass.MEASUREMENT
},
"battery_voltage": {
"device_class": SensorDeviceClass.VOLTAGE,
"unit_of_measurement": UnitOfElectricPotential.VOLT,
"state_class": SensorStateClass.MEASUREMENT
},
"water_hardness": {
"device_class": SensorDeviceClass.WATER,
"unit_of_measurement": "mg/L",
"state_class": SensorStateClass.MEASUREMENT
},
"water_consumption_big": {
"device_class": SensorDeviceClass.VOLUME,
"unit_of_measurement": UnitOfVolume.LITERS,
"state_class": SensorStateClass.TOTAL_INCREASING
},
"water_consumption_today": {
"device_class": SensorDeviceClass.VOLUME,
"unit_of_measurement": UnitOfVolume.LITERS,
"state_class": SensorStateClass.TOTAL_INCREASING
},
"water_consumption_average": {
"device_class": SensorDeviceClass.VOLUME,
"unit_of_measurement": UnitOfVolume.LITERS,
"state_class": SensorStateClass.TOTAL_INCREASING
},
"soft_available_big": {
"device_class": SensorDeviceClass.VOLUME,
"unit_of_measurement": UnitOfVolume.LITERS,
"state_class": SensorStateClass.MEASUREMENT
},
"regeneration_left_seconds": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.SECONDS,
"state_class": SensorStateClass.MEASUREMENT
},
"heat_start": {
"device_class": SensorDeviceClass.ENUM,
},
"regeneration_stages": {
"device_class": SensorDeviceClass.ENUM,
},
"regeneration_current_stages": {
"device_class": SensorDeviceClass.ENUM,
},
"regeneration_count": {
"device_class": SensorDeviceClass.ENUM,
},
"days_since_last_regeneration": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"days_since_last_two_regeneration": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"use_days": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.TOTAL_INCREASING
},
"flushing_days": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"pre_regeneration_days": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"remind_maintenance_days": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"maintenance_reminder_setting": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.DAYS,
"state_class": SensorStateClass.MEASUREMENT
},
"micro_leak_protection_value": {
"device_class": SensorDeviceClass.ENUM,
},
"leak_water_protection_value": {
"device_class": SensorDeviceClass.ENUM,
},
"mixed_water_gear": {
"device_class": SensorDeviceClass.ENUM,
},
"velocity": {
"device_class": SensorDeviceClass.ENUM,
},
"error": {
"device_class": SensorDeviceClass.ENUM,
},
"category": {
"device_class": SensorDeviceClass.ENUM,
},
}
}
}

View File

@@ -9,19 +9,16 @@ DEVICE_MAPPING = {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [
"power", "disinfect_on_off", "netions_on_off", "airdry_on_off",
"power", "disinfect_on_off", "netIons_on_off", "airDry_on_off",
"wind_gear", "wind_speed", "light_color", "bright_led",
"humidity_mode", "tank_status", "humidity", "cur_humidity"
],
"entities": {
Platform.SWITCH: {
"disinfect_on_off": {
"netIons_on_off": {
"device_class": SwitchDeviceClass.SWITCH,
},
"netions_on_off": {
"device_class": SwitchDeviceClass.SWITCH,
},
"airdry_on_off": {
"airDry_on_off": {
"device_class": SwitchDeviceClass.SWITCH,
},
"power": {
@@ -35,9 +32,6 @@ DEVICE_MAPPING = {
},
"power_off_timer": {
"device_class": SwitchDeviceClass.SWITCH,
},
"display_on_off": {
"device_class": SwitchDeviceClass.SWITCH,
}
},
Platform.BINARY_SENSOR: {
@@ -56,13 +50,19 @@ DEVICE_MAPPING = {
"mode": "humidity_mode",
"modes": {
"manual": {"humidity_mode": "manual"},
"auto": {"humidity_mode": "auto"},
"sleep": {"humidity_mode": "sleep"},
"baby": {"humidity_mode": "baby"}
"moist_skin": {"humidity_mode": "moist_skin"},
"sleep": {"humidity_mode": "sleep"}
}
}
},
Platform.SELECT: {
"humidity_mode": {
"options": {
"manual": {"humidity_mode": "manual"},
"moist_skin": {"humidity_mode": "moist_skin"},
"sleep": {"humidity_mode": "sleep"}
}
},
"wind_gear": {
"options": {
"low": {"wind_gear": "low"},
@@ -77,33 +77,26 @@ DEVICE_MAPPING = {
"low": {"wind_speed": "low"},
"medium": {"wind_speed": "medium"},
"high": {"wind_speed": "high"},
"auto": {"wind_speed": "auto"}
"auto": {"wind_speed": "auto"},
"invalid": {"wind_speed": "invalid"}
}
},
"light_color": {
"options": {
"warm": {"light_color": "warm"},
"cool": {"light_color": "cool"},
"white": {"light_color": "white"},
"blue": {"light_color": "blue"},
"green": {"light_color": "green"},
"red": {"light_color": "red"},
#"cool": {"light_color": "cool"},
#"white": {"light_color": "white"},
#"blue": {"light_color": "blue"},
#"green": {"light_color": "green"},
#"red": {"light_color": "red"},
"off": {"light_color": "off"}
}
},
"bright_led": {
"options": {
"light": {"bright_led": "light"},
"dim": {"bright_led": "dim"},
"off": {"bright_led": "off"}
}
},
"tank_status": {
"options": {
"normal": {"tank_status": "0"},
"low": {"tank_status": "1"},
"empty": {"tank_status": "2"},
"error": {"tank_status": "3"}
"dark": {"bright_led": "dark"},
"exit": {"bright_led": "exit"}
}
}
},
@@ -150,8 +143,13 @@ DEVICE_MAPPING = {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"tank_status": {
"device_class": SensorDeviceClass.BATTERY,
"unit_of_measurement": PERCENTAGE,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
}
}
}

View File

@@ -1,6 +1,6 @@
from homeassistant.components.humidifier import (
HumidifierEntity,
HumidifierDeviceClass
HumidifierDeviceClass, HumidifierEntityFeature
)
from homeassistant.const import Platform
from homeassistant.config_entries import ConfigEntry
@@ -61,6 +61,8 @@ class MideaHumidifierEntity(MideaEntity, HumidifierEntity):
rationale=rationale,
config=config,
)
self._attr_supported_features = HumidifierEntityFeature.MODES
self._attr_available_modes = list(self._config.get("modes").keys())
@property
def device_class(self):
@@ -122,13 +124,14 @@ class MideaHumidifierEntity(MideaEntity, HumidifierEntity):
"""Turn the humidifier on."""
power_key = self._config.get("power")
if power_key:
await self._device.set_attribute(power_key, True)
await self._device.set_attribute(power_key, self._rationale[int(True)])
async def async_turn_off(self, **kwargs):
"""Turn the humidifier off."""
power_key = self._config.get("power")
if power_key:
await self._device.set_attribute(power_key, False)
await self._device.set_attribute(power_key, self._rationale[int(False)])
await self._device.set_attribute(power_key, self._rationale[int(False)])
async def async_set_humidity(self, humidity: int):
"""Set the target humidity."""

View File

@@ -0,0 +1,283 @@
from homeassistant.components.light import LightEntity, LightEntityFeature, ColorMode
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .core.logger import MideaLogger
from .midea_entity import MideaEntity
from . import load_device_config
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
account_bucket = hass.data.get(DOMAIN, {}).get("accounts", {}).get(config_entry.entry_id)
if not account_bucket:
async_add_entities([])
return
device_list = account_bucket.get("device_list", {})
coordinator_map = account_bucket.get("coordinator_map", {})
devs = []
for device_id, info in device_list.items():
device_type = info.get("type")
sn8 = info.get("sn8")
config = await load_device_config(hass, device_type, sn8) or {}
entities_cfg = (config.get("entities") or {}).get(Platform.LIGHT, {})
manufacturer = config.get("manufacturer")
rationale = config.get("rationale")
coordinator = coordinator_map.get(device_id)
device = coordinator.device if coordinator else None
for entity_key, ecfg in entities_cfg.items():
devs.append(MideaLightEntity(coordinator, device, manufacturer, rationale, entity_key, ecfg))
async_add_entities(devs)
class MideaLightEntity(MideaEntity, LightEntity):
def __init__(self, coordinator, device, manufacturer, rationale, entity_key, config):
super().__init__(
coordinator,
device.device_id,
device.device_name,
f"T0x{device.device_type:02X}",
device.sn,
device.sn8,
device.model,
entity_key,
device=device,
manufacturer=manufacturer,
rationale=rationale,
config=config,
)
self._key_power = self._config.get("power")
self._key_preset_modes = self._config.get("preset_modes")
self._key_brightness = self._config.get("brightness")
self._key_color_temp = self._config.get("color_temp")
self._key_oscillate = self._config.get("oscillate")
self._key_directions = self._config.get("directions")
# 检测亮度配置类型:范围 [min, max] 或嵌套格式 {"brightness": [min, max]}
self._brightness_is_range = False
self._brightness_min = 0
self._brightness_max = 255
self._brightness_key = "brightness" # 默认键名
if self._key_brightness:
if isinstance(self._key_brightness, list) and len(self._key_brightness) == 2:
# 直接范围格式:[min, max]
if isinstance(self._key_brightness[0], (int, float)) and isinstance(self._key_brightness[1], (int, float)):
self._brightness_is_range = True
self._brightness_min = self._key_brightness[0]
self._brightness_max = self._key_brightness[1]
elif isinstance(self._key_brightness, dict):
# 嵌套格式:{"brightness": [min, max]} 或其他键名
for key, value in self._key_brightness.items():
if isinstance(value, list) and len(value) == 2:
if isinstance(value[0], (int, float)) and isinstance(value[1], (int, float)):
self._brightness_is_range = True
self._brightness_min = value[0]
self._brightness_max = value[1]
self._brightness_key = key
break
# 检测色温配置类型:范围 [min_kelvin, max_kelvin] 或嵌套格式 {"color_temp": [min_kelvin, max_kelvin]}
self._color_temp_is_range = False
self._color_temp_min = 2700 # 默认最小色温(暖白)
self._color_temp_max = 6500 # 默认最大色温(冷白)
self._color_temp_key = "color_temp" # 默认键名
if self._key_color_temp:
if isinstance(self._key_color_temp, list) and len(self._key_color_temp) == 2:
# 直接范围格式:[min_kelvin, max_kelvin]
if isinstance(self._key_color_temp[0], (int, float)) and isinstance(self._key_color_temp[1], (int, float)):
self._color_temp_is_range = True
self._color_temp_min = self._key_color_temp[0]
self._color_temp_max = self._key_color_temp[1]
elif isinstance(self._key_color_temp, dict):
# 嵌套格式:{"color_temp": [min_kelvin, max_kelvin]} 或其他键名
for key, value in self._key_color_temp.items():
if isinstance(value, list) and len(value) == 2:
if isinstance(value[0], (int, float)) and isinstance(value[1], (int, float)):
self._color_temp_is_range = True
self._color_temp_min = value[0]
self._color_temp_max = value[1]
self._color_temp_key = key
break
@property
def supported_features(self):
features = LightEntityFeature(0)
if self._key_preset_modes is not None and len(self._key_preset_modes) > 0:
features |= LightEntityFeature.EFFECT
return features
@property
def supported_color_modes(self):
"""返回支持的色彩模式"""
modes = set()
if self._brightness_is_range and self._color_temp_is_range:
# 如果同时支持亮度和色温,优先支持色温模式(更高级的功能)
modes.add(ColorMode.COLOR_TEMP)
elif self._brightness_is_range:
modes.add(ColorMode.BRIGHTNESS)
elif self._color_temp_is_range:
modes.add(ColorMode.COLOR_TEMP)
else:
modes.add(ColorMode.ONOFF)
return modes
@property
def color_mode(self):
"""返回当前色彩模式"""
if self._brightness_is_range and self._color_temp_is_range:
# 如果同时支持亮度和色温优先返回色温模式与supported_color_modes保持一致
return ColorMode.COLOR_TEMP
elif self._brightness_is_range:
return ColorMode.BRIGHTNESS
elif self._color_temp_is_range:
return ColorMode.COLOR_TEMP
return ColorMode.ONOFF
@property
def is_on(self) -> bool:
return self._get_status_on_off(self._key_power)
@property
def effect_list(self):
return list(self._key_preset_modes.keys())
@property
def effect(self):
return self._dict_get_selected(self._key_preset_modes)
@property
def brightness(self):
"""返回0-255范围内的亮度值Home Assistant标准"""
if not self._brightness_is_range:
return None
# 范围模式:从设备属性读取亮度值,使用配置的键名
brightness_value = self._get_nested_value(self._brightness_key)
if brightness_value is not None:
brightness_value = int(brightness_value)
if brightness_value is not None:
# 如果配置是[0, 255]但实际设备范围是1-100需要特殊处理
if self._brightness_min == 0 and self._brightness_max == 255:
# 特殊处理设备1-100范围映射到HA的0-255范围
ha_brightness = round(brightness_value * 2.55) # 1-100 -> 0-255
return max(1, min(255, ha_brightness))
else:
# 正常范围映射
device_range = self._brightness_max - self._brightness_min
if device_range > 0:
ha_brightness = round((brightness_value - self._brightness_min) * 255 / device_range)
return max(1, min(255, ha_brightness))
return None
@property
def color_temp_kelvin(self):
"""返回当前色温值(开尔文)"""
if not self._color_temp_is_range:
return None
# 从设备属性读取色温值1-100范围
color_temp_value = self._get_nested_value(self._color_temp_key)
if color_temp_value is not None:
try:
device_color_temp = int(color_temp_value)
# 将设备的1-100值转换为开尔文值
kelvin_range = self._color_temp_max - self._color_temp_min
if kelvin_range > 0:
# 将1-100范围映射回开尔文范围
ha_color_temp = self._color_temp_min + device_color_temp * kelvin_range / 100
return round(ha_color_temp)
else:
return self._color_temp_min
except (ValueError, TypeError):
return None
return None
@property
def min_color_temp_kelvin(self):
"""返回支持的最小色温值(开尔文)"""
if self._color_temp_is_range:
return self._color_temp_min
return None
@property
def max_color_temp_kelvin(self):
"""返回支持的最大色温值(开尔文)"""
if self._color_temp_is_range:
return self._color_temp_max
return None
async def async_turn_on(
self,
brightness: int | None = None,
brightness_pct: int | None = None,
percentage: int | None = None,
color_temp_kelvin: int | None = None,
effect: str | None = None,
preset_mode: str | None = None,
**kwargs,
):
new_status = {}
if effect is not None and self._key_preset_modes is not None:
effect_config = self._key_preset_modes.get(effect, {})
new_status.update(effect_config)
# 处理亮度设置 - 支持多种参数格式
target_brightness = None
if brightness is not None:
# Home Assistant标准0-255范围
target_brightness = brightness
elif brightness_pct is not None:
# 百分比格式0-100范围转换为0-255
target_brightness = round(brightness_pct * 255 / 100)
elif percentage is not None:
# 兼容旧格式0-100范围转换为0-255
target_brightness = round(percentage * 255 / 100)
if target_brightness is not None and self._key_brightness and self._brightness_is_range:
# 范围模式将Home Assistant的0-255映射到设备范围
# 如果配置是[0, 255]但实际设备范围是1-100需要特殊处理
if self._brightness_min == 0 and self._brightness_max == 255:
# 特殊处理:配置[0,255]但实际设备范围是1-100
device_brightness = round(target_brightness / 2.55) # 0-255 -> 0-100
device_brightness = max(1, min(100, device_brightness)) # 确保在1-100范围内
else:
# 正常范围映射
device_range = self._brightness_max - self._brightness_min
if device_range > 0:
device_brightness = round(self._brightness_min + (target_brightness / 255.0) * device_range)
device_brightness = max(self._brightness_min, min(self._brightness_max, device_brightness))
else:
return
new_status[self._brightness_key] = device_brightness
# 处理色温设置
if color_temp_kelvin is not None and self._color_temp_is_range:
# 确保色温值在配置的范围内
ha_color_temp = max(self._color_temp_min, min(self._color_temp_max, color_temp_kelvin))
# 将开尔文值转换为设备范围1-100
kelvin_range = self._color_temp_max - self._color_temp_min
if kelvin_range > 0:
# 将开尔文值映射到1-100范围
device_color_temp = round((ha_color_temp - self._color_temp_min) * 100 / kelvin_range)
device_color_temp = max(0, min(100, device_color_temp))
else:
device_color_temp = 50 # 默认中间值
new_status[self._color_temp_key] = str(device_color_temp)
await self._async_set_status_on_off(self._key_power, True)
if new_status:
await self.async_set_attributes(new_status)
async def async_turn_off(self):
await self._async_set_status_on_off(self._key_power, False)

View File

@@ -7,5 +7,5 @@
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/sususweet/midea-meiju-codec/issues",
"requirements": ["lupa>=2.0"],
"version": "v0.1.3"
"version": "v0.1.10"
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

BIN
img/img_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
img/img_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB