mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-12-27 23:07:10 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fe689217a | ||
|
|
a680cd43b8 | ||
|
|
05ad0c3a15 | ||
|
|
aea43aad0c | ||
|
|
329fbce3dd | ||
|
|
f9a1f57d31 | ||
|
|
ee6c5b18af | ||
|
|
6166ebf4f7 | ||
|
|
39cc28b4dd | ||
|
|
e4b939780f | ||
|
|
c12e95f2a1 | ||
|
|
6129248fed | ||
|
|
3b2d817dd6 | ||
|
|
e9f8f95826 | ||
|
|
7a28c62ac5 | ||
|
|
f2735fd729 | ||
|
|
05e30ab414 | ||
|
|
af6f2d1789 | ||
|
|
665763bb22 |
10
README.md
10
README.md
@@ -3,7 +3,7 @@
|
||||
[](https://github.com/hacs/integration)
|
||||
[](https://github.com/sususweet/midea-meiju-codec/releases/latest)
|
||||
|
||||
English | [简体中文](README_zh_CN.md)
|
||||
English | [简体中文](README_hans.md)
|
||||
|
||||
Get devices from MSmartHome/Midea Meiju homes through the network and control them via Midea's cloud API.
|
||||
|
||||
@@ -19,9 +19,12 @@ Get devices from MSmartHome/Midea Meiju homes through the network and control th
|
||||
## Currently Supported Device Types
|
||||
|
||||
- T0x13 Electric Light
|
||||
- T0x15 Water Heater
|
||||
- T0x21 Central Air Conditioning Gateway
|
||||
- T0x26 Bath Heater
|
||||
- T0x3D Water Heater
|
||||
- T0x9B Steam oven
|
||||
- T0x9C Integrated Gas Stove
|
||||
- T0xA1 Dehumidifier
|
||||
- T0xAC Air Conditioner
|
||||
- T0xB2 Electric Steamer
|
||||
@@ -34,7 +37,8 @@ Get devices from MSmartHome/Midea Meiju homes through the network and control th
|
||||
- T0xCE Fresh Air System
|
||||
- T0xCF Central Air Conditioning Heating
|
||||
- T0xD9 Twin Tub Washing Machine
|
||||
- T0xDB Front Load Washing Machine
|
||||
- T0xDA Impeller Washing Machine
|
||||
- T0xDB Cylinder Washing Machine
|
||||
- T0xDC Clothes Dryer
|
||||
- T0xE1 Dishwasher
|
||||
- T0xE2 Electric Water Heater
|
||||
@@ -72,4 +76,4 @@ The example configuration `22012227` demonstrates how to map device attributes t
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
Thanks to the [midea-meiju-codec](https://github.com/MattedBroadSky/midea-meiju-codec) project for providing prior knowledge.
|
||||
Thanks to the [midea-meiju-codec](https://github.com/MattedBroadSky/midea-meiju-codec) project for providing prior knowledge.
|
||||
|
||||
@@ -19,9 +19,12 @@
|
||||
## 目前支持的设备类型
|
||||
|
||||
- T0x13 电灯
|
||||
- T0x15 养生壶
|
||||
- T0x21 中央空调网关
|
||||
- T0x26 浴霸
|
||||
- T0x3D 电热水瓶
|
||||
- T0x9B 蒸烤箱
|
||||
- T0x9C 集成灶
|
||||
- T0xA1 除湿机
|
||||
- T0xAC 空调
|
||||
- T0xB2 电蒸箱
|
||||
@@ -34,6 +37,7 @@
|
||||
- T0xCE 新风机
|
||||
- T0xCF 中央空调暖家
|
||||
- T0xD9 复式洗衣机
|
||||
- T0xDA 波轮洗衣机
|
||||
- T0xDB 滚筒洗衣机
|
||||
- T0xDC 干衣机
|
||||
- T0xE1 洗碗机
|
||||
@@ -57,7 +57,9 @@ PLATFORMS: list[Platform] = [
|
||||
Platform.WATER_HEATER,
|
||||
Platform.FAN,
|
||||
Platform.LIGHT,
|
||||
Platform.HUMIDIFIER
|
||||
Platform.HUMIDIFIER,
|
||||
Platform.NUMBER,
|
||||
Platform.BUTTON
|
||||
]
|
||||
|
||||
|
||||
@@ -138,20 +140,46 @@ async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType):
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
cjson = os.getcwd() + "/cjson.lua"
|
||||
bit = os.getcwd() + "/bit.lua"
|
||||
# if not os.path.exists(cjson):
|
||||
from .const import CJSON_LUA
|
||||
cjson_lua = base64.b64decode(CJSON_LUA.encode("utf-8")).decode("utf-8")
|
||||
with open(cjson, "wt") as fp:
|
||||
fp.write(cjson_lua)
|
||||
# if not os.path.exists(bit):
|
||||
from .const import BIT_LUA
|
||||
bit_lua = base64.b64decode(BIT_LUA.encode("utf-8")).decode("utf-8")
|
||||
with open(bit, "wt") as fp:
|
||||
fp.write(bit_lua)
|
||||
return True
|
||||
os.makedirs(hass.config.path(STORAGE_PATH), exist_ok=True)
|
||||
lua_path = hass.config.path(STORAGE_PATH)
|
||||
|
||||
cjson = os.path.join(lua_path, "cjson.lua")
|
||||
bit = os.path.join(lua_path, "bit.lua")
|
||||
|
||||
# 只有文件不存在时才创建
|
||||
if not os.path.exists(cjson):
|
||||
from .const import CJSON_LUA
|
||||
cjson_lua = base64.b64decode(CJSON_LUA.encode("utf-8")).decode("utf-8")
|
||||
try:
|
||||
with open(cjson, "wt") as fp:
|
||||
fp.write(cjson_lua)
|
||||
except PermissionError as e:
|
||||
MideaLogger.error(f"Failed to create cjson.lua at {cjson}: {e}")
|
||||
# 如果无法创建文件,尝试使用临时目录
|
||||
import tempfile
|
||||
temp_dir = tempfile.gettempdir()
|
||||
cjson = os.path.join(temp_dir, "cjson.lua")
|
||||
with open(cjson, "wt") as fp:
|
||||
fp.write(cjson_lua)
|
||||
MideaLogger.warning(f"Using temporary file for cjson.lua: {cjson}")
|
||||
|
||||
if not os.path.exists(bit):
|
||||
from .const import BIT_LUA
|
||||
bit_lua = base64.b64decode(BIT_LUA.encode("utf-8")).decode("utf-8")
|
||||
try:
|
||||
with open(bit, "wt") as fp:
|
||||
fp.write(bit_lua)
|
||||
except PermissionError as e:
|
||||
MideaLogger.error(f"Failed to create bit.lua at {bit}: {e}")
|
||||
# 如果无法创建文件,尝试使用临时目录
|
||||
import tempfile
|
||||
temp_dir = tempfile.gettempdir()
|
||||
bit = os.path.join(temp_dir, "bit.lua")
|
||||
with open(bit, "wt") as fp:
|
||||
fp.write(bit_lua)
|
||||
MideaLogger.warning(f"Using temporary file for bit.lua: {bit}")
|
||||
|
||||
return True
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||
device_type = config_entry.data.get(CONF_TYPE)
|
||||
|
||||
99
custom_components/midea_auto_cloud/button.py
Normal file
99
custom_components/midea_auto_cloud/button.py
Normal file
@@ -0,0 +1,99 @@
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
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:
|
||||
"""Set up button entities for Midea devices."""
|
||||
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.BUTTON, {})
|
||||
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(MideaButtonEntity(
|
||||
coordinator, device, manufacturer, rationale, entity_key, ecfg
|
||||
))
|
||||
async_add_entities(devs)
|
||||
|
||||
|
||||
class MideaButtonEntity(MideaEntity, ButtonEntity):
|
||||
"""Midea button entity."""
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Handle the button press."""
|
||||
# 从配置中获取要执行的命令或操作
|
||||
command = self._config.get("command")
|
||||
attribute = self._config.get("attribute", self._entity_key)
|
||||
value = self._config.get("value")
|
||||
|
||||
# 判断是否为中央空调设备(T0x21)
|
||||
is_central_ac = self._device.device_type == 0x21 if self._device else False
|
||||
|
||||
if command:
|
||||
# 如果配置中指定了命令,执行该命令
|
||||
if isinstance(command, dict):
|
||||
# 如果是字典,可能需要发送多个属性
|
||||
await self.async_set_attributes(command)
|
||||
elif isinstance(command, str):
|
||||
# 如果是字符串,可能是特殊命令类型
|
||||
await self._async_execute_command(command)
|
||||
elif value is not None:
|
||||
# 如果配置中指定了值,设置该属性值
|
||||
await self.async_set_attribute(attribute, value)
|
||||
else:
|
||||
# 默认行为:如果没有指定命令或值,记录警告
|
||||
MideaLogger.warning(
|
||||
f"Button {self._entity_key} has no command or value configured"
|
||||
)
|
||||
|
||||
async def _async_execute_command(self, command: str) -> None:
|
||||
"""Execute a special command."""
|
||||
# 这里可以处理特殊的命令类型
|
||||
# 例如:重启、重置、测试等
|
||||
if command == "reset" or command == "restart":
|
||||
# 可以在这里实现重置或重启逻辑
|
||||
MideaLogger.debug(f"Executing {command} command for button {self._entity_key}")
|
||||
else:
|
||||
# 对于其他命令,可以通过 coordinator 发送
|
||||
await self.coordinator.async_send_command(0, command)
|
||||
|
||||
@@ -361,11 +361,8 @@ class MeijuCloud(MideaCloud):
|
||||
command_data = {
|
||||
"nodeid": nodeid,
|
||||
"acattri_ctrl": {
|
||||
"aclist": [{
|
||||
"nodeid": nodeid,
|
||||
"modelid": modelid,
|
||||
"type": idtype
|
||||
}],
|
||||
"nodeid": nodeid,
|
||||
"modelid": modelid, "type": idtype, "aclist_data": nodeid[-2:],
|
||||
"event": control
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
import traceback
|
||||
|
||||
import lupa
|
||||
import threading
|
||||
import json
|
||||
@@ -9,6 +9,23 @@ from .logger import MideaLogger
|
||||
class LuaRuntime:
|
||||
def __init__(self, file):
|
||||
self._runtimes = lupa.lua51.LuaRuntime()
|
||||
|
||||
# 设置Lua路径,包含cjson.lua和bit.lua的目录
|
||||
lua_dir = os.path.dirname(os.path.abspath(file))
|
||||
self._runtimes.execute(f'package.path = package.path .. ";{lua_dir}/?.lua"')
|
||||
|
||||
# 加载必需的Lua库
|
||||
try:
|
||||
self._runtimes.execute('require "cjson"')
|
||||
except Exception as e:
|
||||
MideaLogger.warning(f"Failed to load cjson: {e}")
|
||||
|
||||
try:
|
||||
self._runtimes.execute('require "bit"')
|
||||
except Exception as e:
|
||||
MideaLogger.warning(f"Failed to load bit: {e}")
|
||||
|
||||
# 加载设备特定的Lua文件
|
||||
string = f'dofile("{file}")'
|
||||
self._runtimes.execute(string)
|
||||
self._lock = threading.Lock()
|
||||
@@ -70,6 +87,17 @@ class MideaCodec(LuaRuntime):
|
||||
query_dict["control"]["bucket"] = prefix
|
||||
else:
|
||||
query_dict["control"]["bucket"] = "db"
|
||||
# 针对T0x9C集成灶特殊处理
|
||||
elif self._device_type == "T0x9C":
|
||||
control_keys = list(append.keys())
|
||||
if len(control_keys) > 0:
|
||||
# 从第一个键名中提取前缀,例如从 'db_power' 中提取 'db'
|
||||
first_key = control_keys[0]
|
||||
prefix = first_key.split("_")[0]
|
||||
else:
|
||||
prefix = "total"
|
||||
|
||||
query_dict["control"]["type"] = prefix
|
||||
json_str = json.dumps(query_dict)
|
||||
MideaLogger.debug(f"LuaRuntime json_str {json_str}")
|
||||
try:
|
||||
|
||||
@@ -45,14 +45,7 @@ DEVICE_MAPPING = {
|
||||
Platform.FAN: {
|
||||
"fan": {
|
||||
"power": "fan_power",
|
||||
"speeds": [
|
||||
{"fan_speed": "1"},
|
||||
{"fan_speed": "2"},
|
||||
{"fan_speed": "3"},
|
||||
{"fan_speed": "4"},
|
||||
{"fan_speed": "5"},
|
||||
{"fan_speed": "6"},
|
||||
],
|
||||
"speeds": list({"fan_speed": value + 1} for value in range(0, 6)),
|
||||
"preset_modes": {
|
||||
"breathing_wind": {"fan_scene": "breathing_wind"},
|
||||
"const_temperature": {"fan_scene": "const_temperature"},
|
||||
|
||||
60
custom_components/midea_auto_cloud/device_mapping/T0x15.py
Normal file
60
custom_components/midea_auto_cloud/device_mapping/T0x15.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from homeassistant.const import Platform, UnitOfTemperature, UnitOfVolume, UnitOfTime, PERCENTAGE, PRECISION_HALVES, \
|
||||
UnitOfEnergy, UnitOfPower, PRECISION_WHOLE
|
||||
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": ["warm_target_temp", "boil_target_temp", "meate_select", "max_work_time", "warm_time_min"],
|
||||
"entities": {
|
||||
Platform.BINARY_SENSOR: {
|
||||
"islack_water": {
|
||||
"device_class": BinarySensorDeviceClass.PROBLEM,
|
||||
}
|
||||
},
|
||||
Platform.NUMBER: {
|
||||
"warm_time_min": {
|
||||
"min": 0,
|
||||
"max": 480,
|
||||
"step": 60
|
||||
},
|
||||
"max_work_time": {
|
||||
"min": 0,
|
||||
"max": 12,
|
||||
"step": 1
|
||||
},
|
||||
"warm_target_temp": {
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
"boil_target_temp": {
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
},
|
||||
Platform.SELECT: {
|
||||
"work_mode": {
|
||||
"options": {
|
||||
"取消": {"work_mode": "0", "work_switch": "cancel"},
|
||||
"烧水": {"work_mode": "1", "work_switch": "start"},
|
||||
"除氯": {"work_mode": "2", "work_switch": "start"},
|
||||
"花草茶": {"work_mode": "4", "work_switch": "start"},
|
||||
"养生汤": {"work_mode": "5", "work_switch": "start"},
|
||||
}
|
||||
}
|
||||
},
|
||||
Platform.SENSOR: {
|
||||
"current_temp": {
|
||||
"device_class": SensorDeviceClass.TEMPERATURE,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
custom_components/midea_auto_cloud/device_mapping/T0x9B.py
Normal file
20
custom_components/midea_auto_cloud/device_mapping/T0x9B.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from homeassistant.const import Platform, UnitOfTemperature, UnitOfVolume, UnitOfTime, PERCENTAGE, PRECISION_HALVES, \
|
||||
UnitOfEnergy, UnitOfPower, PRECISION_WHOLE, UnitOfPressure
|
||||
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.SENSOR: {
|
||||
"work_status": {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
86
custom_components/midea_auto_cloud/device_mapping/T0x9C.py
Normal file
86
custom_components/midea_auto_cloud/device_mapping/T0x9C.py
Normal file
@@ -0,0 +1,86 @@
|
||||
from homeassistant.const import Platform, UnitOfTemperature, UnitOfVolume, UnitOfTime, PERCENTAGE, PRECISION_HALVES, \
|
||||
UnitOfEnergy, UnitOfPower, PRECISION_WHOLE, UnitOfPressure
|
||||
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": ["b6_light"],
|
||||
"entities": {
|
||||
Platform.NUMBER: {
|
||||
"b6_lightness": {
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
}
|
||||
},
|
||||
Platform.SWITCH: {
|
||||
"b6_light": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
},
|
||||
Platform.SELECT: {
|
||||
"b6_gear": {
|
||||
"options": {
|
||||
"关": {"b6_gear": "0"},
|
||||
"低": {"b6_gear": "1"},
|
||||
"中": {"b6_gear": "2"},
|
||||
"高": {"b6_gear": "3"},
|
||||
"爆炒": {"b6_gear": "4"}
|
||||
}
|
||||
},
|
||||
"b6_power_on_light": {
|
||||
"options": {
|
||||
"关": {"b6_power_on_light": "off", "b6_setting": "power_on_light"},
|
||||
"开": {"b6_power_on_light": "on", "b6_setting": "power_on_light"}
|
||||
}
|
||||
},
|
||||
"b6_lock": {
|
||||
"options": {
|
||||
"关": {"b6_lock": "off", "b6_setting": "lock"},
|
||||
"开": {"b6_lock": "on", "b6_setting": "lock"}
|
||||
}
|
||||
},
|
||||
"b6_smoke_stove_linkage_gear": {
|
||||
"options": {
|
||||
"1档": {"b6_smoke_stove_linkage_gear": 1, "b6_setting": "smoke_stove_linkage"},
|
||||
"2档": {"b6_smoke_stove_linkage_gear": 2, "b6_setting": "smoke_stove_linkage"},
|
||||
"3档": {"b6_smoke_stove_linkage_gear": 3, "b6_setting": "smoke_stove_linkage"},
|
||||
}
|
||||
},
|
||||
"b6_delay_gear_linkage_gear": {
|
||||
"options": {
|
||||
"1档": {"b6_delay_gear_linkage_gear": 1, "b6_setting": "delay_gear_linkage"},
|
||||
"2档": {"b6_delay_gear_linkage_gear": 2, "b6_setting": "delay_gear_linkage"},
|
||||
"3档": {"b6_delay_gear_linkage_gear": 3, "b6_setting": "delay_gear_linkage"},
|
||||
}
|
||||
},
|
||||
"b6_delay_time_value": {
|
||||
"options": {
|
||||
"关": {"b6_delay_time": "off", "b6_setting": "delay_time"},
|
||||
"1分钟": {"b6_delay_time": "on", "b6_delay_time_value": 1, "b6_setting": "delay_time"},
|
||||
"2分钟": {"b6_delay_time": "on", "b6_delay_time_value": 2, "b6_setting": "delay_time"},
|
||||
"3分钟": {"b6_delay_time": "on", "b6_delay_time_value": 3, "b6_setting": "delay_time"},
|
||||
"4分钟": {"b6_delay_time": "on", "b6_delay_time_value": 4, "b6_setting": "delay_time"},
|
||||
"5分钟": {"b6_delay_time": "on", "b6_delay_time_value": 5, "b6_setting": "delay_time"},
|
||||
"6分钟": {"b6_delay_time": "on", "b6_delay_time_value": 6, "b6_setting": "delay_time"},
|
||||
"7分钟": {"b6_delay_time": "on", "b6_delay_time_value": 7, "b6_setting": "delay_time"},
|
||||
"8分钟": {"b6_delay_time": "on", "b6_delay_time_value": 8, "b6_setting": "delay_time"},
|
||||
"9分钟": {"b6_delay_time": "on", "b6_delay_time_value": 9, "b6_setting": "delay_time"},
|
||||
"10分钟": {"b6_delay_time": "on", "b6_delay_time_value": 10, "b6_setting": "delay_time"},
|
||||
}
|
||||
}
|
||||
},
|
||||
Platform.SENSOR: {
|
||||
"b6_wind_pressure": {
|
||||
"device_class": SensorDeviceClass.PRESSURE,
|
||||
"unit_of_measurement": UnitOfPressure.PA,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,7 @@ DEVICE_MAPPING = {
|
||||
Platform.FAN: {
|
||||
"fan": {
|
||||
"power": "new_wind_machine",
|
||||
"speeds": [
|
||||
{"fresh_air_fan_speed": 20},
|
||||
{"fresh_air_fan_speed": 40},
|
||||
{"fresh_air_fan_speed": 60},
|
||||
{"fresh_air_fan_speed": 80},
|
||||
{"fresh_air_fan_speed": 100},
|
||||
],
|
||||
"speeds": list({"fresh_air_fan_speed": value + 1} for value in range(0, 100)),
|
||||
"preset_modes": {
|
||||
"heat_exchange": {
|
||||
"fresh_air_mode": 1,
|
||||
@@ -166,13 +160,7 @@ DEVICE_MAPPING = {
|
||||
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},
|
||||
],
|
||||
"speeds": list({"fresh_air": 3, "fresh_air_fan_speed": value + 1} for value in range(0, 100)),
|
||||
"preset_modes": {
|
||||
"heat_exchange": {
|
||||
"fresh_air_mode": 1,
|
||||
|
||||
150
custom_components/midea_auto_cloud/device_mapping/T0xDA.py
Normal file
150
custom_components/midea_auto_cloud/device_mapping/T0xDA.py
Normal file
@@ -0,0 +1,150 @@
|
||||
from homeassistant.const import Platform, UnitOfElectricPotential, UnitOfTemperature, 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": [{}],
|
||||
"calculate": {
|
||||
"get": [
|
||||
{
|
||||
"lvalue": "[remain_time]",
|
||||
"rvalue": "[remain_time]"
|
||||
}
|
||||
],
|
||||
"set": {
|
||||
}
|
||||
},
|
||||
"entities": {
|
||||
Platform.NUMBER: {
|
||||
"temperature": {
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
"detergent": {
|
||||
"min": 0,
|
||||
"max": 5,
|
||||
"step": 1
|
||||
},
|
||||
"softener": {
|
||||
"min": 0,
|
||||
"max": 5,
|
||||
"step": 1
|
||||
},
|
||||
"dehydration_speed": {
|
||||
"min": 0,
|
||||
"max": 1600,
|
||||
"step": 100
|
||||
},
|
||||
"soak_time": {
|
||||
"min": 0,
|
||||
"max": 40,
|
||||
"step": 10
|
||||
},
|
||||
"wash_time": {
|
||||
"min": 0,
|
||||
"max": 20,
|
||||
"step": 1
|
||||
},
|
||||
"rinse_count": {
|
||||
"min": 0,
|
||||
"max": 3,
|
||||
"step": 1
|
||||
},
|
||||
"dehydration_time": {
|
||||
"min": 0,
|
||||
"max": 9,
|
||||
"step": 1
|
||||
},
|
||||
"wash_level": {
|
||||
"min": 0,
|
||||
"max": 8,
|
||||
"step": 1
|
||||
},
|
||||
"rinse_level": {
|
||||
"min": 0,
|
||||
"max": 8,
|
||||
"step": 1
|
||||
},
|
||||
"wash_strength": {
|
||||
"min": 1,
|
||||
"max": 4,
|
||||
"step": 1
|
||||
},
|
||||
},
|
||||
Platform.BINARY_SENSOR: {
|
||||
"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: {
|
||||
"power": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
"control_status": {
|
||||
"rationale": ["pause", "start"],
|
||||
},
|
||||
"lock": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
},
|
||||
Platform.SELECT: {
|
||||
"mode": {
|
||||
"options": {
|
||||
"normal": {"mode": "normal"},
|
||||
"dry": {"mode": "dry"},
|
||||
"continus": {"mode": "continus"},
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"options": {
|
||||
"标准": {"program": "standard"},
|
||||
"速洗": {"program": "fast"},
|
||||
"家纺": {"program": "blanket"},
|
||||
"羊毛": {"program": "wool"},
|
||||
"浸洗": {"program": "embathe"},
|
||||
"记忆": {"program": "memory"},
|
||||
"童装": {"program": "child"},
|
||||
"强洗": {"program": "strong_wash"},
|
||||
"桶自洁": {"program": "bucket_self_clean"},
|
||||
}
|
||||
},
|
||||
},
|
||||
Platform.SENSOR: {
|
||||
"running_status": {
|
||||
"device_class": SensorDeviceClass.ENUM
|
||||
},
|
||||
"appointment_time": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"remain_time": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"progress": {
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
"unit_of_measurement": "%",
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"error_code": {
|
||||
"device_class": SensorDeviceClass.ENUM
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,48 @@ DEVICE_MAPPING = {
|
||||
}
|
||||
},
|
||||
"entities": {
|
||||
Platform.NUMBER: {
|
||||
"temperature": {
|
||||
"min": 0,
|
||||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
"detergent": {
|
||||
"min": 0,
|
||||
"max": 5,
|
||||
"step": 1
|
||||
},
|
||||
"softener": {
|
||||
"min": 0,
|
||||
"max": 5,
|
||||
"step": 1
|
||||
},
|
||||
"dehydration_time": {
|
||||
"min": 0,
|
||||
"max": 9,
|
||||
"step": 1
|
||||
},
|
||||
"dehydration_speed": {
|
||||
"min": 0,
|
||||
"max": 1600,
|
||||
"step": 100
|
||||
},
|
||||
"dirty_degree": {
|
||||
"min": 0,
|
||||
"max": 4,
|
||||
"step": 1
|
||||
},
|
||||
"soak_count": {
|
||||
"min": 0,
|
||||
"max": 5,
|
||||
"step": 1
|
||||
},
|
||||
"wash_time": {
|
||||
"min": 0,
|
||||
"max": 20,
|
||||
"step": 1
|
||||
},
|
||||
},
|
||||
Platform.BINARY_SENSOR: {
|
||||
"softener_lack": {
|
||||
"device_class": BinarySensorDeviceClass.PROBLEM,
|
||||
@@ -66,19 +108,6 @@ DEVICE_MAPPING = {
|
||||
},
|
||||
},
|
||||
Platform.SELECT: {
|
||||
"dehydration_speed": {
|
||||
"options": {
|
||||
"0": {"dehydration_speed": "0"},
|
||||
"400": {"dehydration_speed": "400"},
|
||||
"600": {"dehydration_speed": "600"},
|
||||
"800": {"dehydration_speed": "800"},
|
||||
"1000": {"dehydration_speed": "1000"},
|
||||
"1200": {"dehydration_speed": "1200"},
|
||||
"1400": {"dehydration_speed": "1400"},
|
||||
"1600": {"dehydration_speed": "1600"},
|
||||
"1300": {"dehydration_speed": "1300"}
|
||||
}
|
||||
},
|
||||
"mode": {
|
||||
"options": {
|
||||
"normal": {"mode": "normal"},
|
||||
@@ -190,68 +219,11 @@ DEVICE_MAPPING = {
|
||||
"hanfu_wash": {"program": "hanfu_wash"}
|
||||
}
|
||||
},
|
||||
"temperature": {
|
||||
"options": {
|
||||
"0": {"temperature": "0"},
|
||||
"20": {"temperature": "20"},
|
||||
"30": {"temperature": "30"},
|
||||
"40": {"temperature": "40"},
|
||||
"50": {"temperature": "50"},
|
||||
"60": {"temperature": "60"},
|
||||
"70": {"temperature": "70"},
|
||||
"90": {"temperature": "90"},
|
||||
"95": {"temperature": "95"}
|
||||
}
|
||||
},
|
||||
"detergent": {
|
||||
"options": {
|
||||
"0": {"detergent": "0"},
|
||||
"1": {"detergent": "1"},
|
||||
"2": {"detergent": "2"},
|
||||
"3": {"detergent": "3"},
|
||||
"4": {"detergent": "4"},
|
||||
"5": {"detergent": "5"}
|
||||
}
|
||||
},
|
||||
"softener": {
|
||||
"options": {
|
||||
"0": {"softener": "0"},
|
||||
"1": {"softener": "1"},
|
||||
"2": {"softener": "2"},
|
||||
"3": {"softener": "3"},
|
||||
"4": {"softener": "4"},
|
||||
"5": {"softener": "5"}
|
||||
}
|
||||
},
|
||||
"dirty_degree": {
|
||||
"options": {
|
||||
"0": {"dirty_degree": "0"},
|
||||
"1": {"dirty_degree": "1"},
|
||||
"2": {"dirty_degree": "2"},
|
||||
"3": {"dirty_degree": "3"},
|
||||
"4": {"dirty_degree": "4"}
|
||||
}
|
||||
},
|
||||
"soak_count": {
|
||||
"options": {
|
||||
"0": {"soak_count": "0"},
|
||||
"1": {"soak_count": "1"},
|
||||
"2": {"soak_count": "2"},
|
||||
"3": {"soak_count": "3"},
|
||||
"4": {"soak_count": "4"},
|
||||
"5": {"soak_count": "5"}
|
||||
}
|
||||
}
|
||||
},
|
||||
Platform.SENSOR: {
|
||||
"running_status": {
|
||||
"device_class": SensorDeviceClass.ENUM
|
||||
},
|
||||
"wash_time": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"appointment_time": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
@@ -273,11 +245,6 @@ DEVICE_MAPPING = {
|
||||
"unit_of_measurement": "%",
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"dehydration_time_value": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"customize_machine_cycle": {
|
||||
"device_class": SensorDeviceClass.ENUM
|
||||
},
|
||||
@@ -315,11 +282,6 @@ DEVICE_MAPPING = {
|
||||
"active_oxygen": {
|
||||
"device_class": SensorDeviceClass.ENUM
|
||||
},
|
||||
"dehydration_time": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"cloud_cycle_jiepai_time2": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
|
||||
@@ -10,10 +10,10 @@ DEVICE_MAPPING = {
|
||||
"queries": [{}],
|
||||
"centralized": [],
|
||||
"entities": {
|
||||
Platform.WATER_HEATER: {
|
||||
Platform.CLIMATE: {
|
||||
"water_heater": {
|
||||
"power": "power",
|
||||
"operation_list": {
|
||||
"hvac_modes": {
|
||||
"off": {"power": "off"},
|
||||
"on": {"power": "on"},
|
||||
},
|
||||
@@ -26,6 +26,9 @@ DEVICE_MAPPING = {
|
||||
}
|
||||
},
|
||||
Platform.SWITCH: {
|
||||
"power": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
"ti_protect": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
|
||||
@@ -10,6 +10,9 @@ DEVICE_MAPPING = {
|
||||
"centralized": [],
|
||||
"entities": {
|
||||
Platform.SWITCH: {
|
||||
"power": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
"bubble": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
"rationale": [0, 1]
|
||||
|
||||
@@ -66,30 +66,30 @@ DEVICE_MAPPING = {
|
||||
Platform.SELECT: {
|
||||
"mode": {
|
||||
"options": {
|
||||
"Rice": {"mode": "essence_rice", "work_status": "cooking"},
|
||||
"Porridge": {"mode": "gruel", "work_status": "cooking"},
|
||||
"精华饭": {"mode": "essence_rice", "work_status": "cooking"},
|
||||
"稀饭": {"mode": "gruel", "work_status": "cooking"},
|
||||
"热饭": {"mode": "heat_rice", "work_status": "cooking"},
|
||||
"Congee": {"mode": "boil_congee", "work_status": "cooking"},
|
||||
"Soup": {"mode": "cook_soup", "work_status": "cooking"},
|
||||
"Steam": {"mode": "stewing", "work_status": "cooking"},
|
||||
"煮粥": {"mode": "boil_congee", "work_status": "cooking"},
|
||||
"煲汤": {"mode": "cook_soup", "work_status": "cooking"},
|
||||
"蒸煮": {"mode": "stewing", "work_status": "cooking"},
|
||||
}
|
||||
},
|
||||
"rice_type": {
|
||||
"options": {
|
||||
"None": {"rice_type": "none"},
|
||||
"Northeast rice": {"rice_type": "northeast"},
|
||||
"Long-grain rice": {"rice_type": "longrain"},
|
||||
"Fragrant rice": {"rice_type": "fragrant"},
|
||||
"Wuchang rice": {"rice_type": "five"},
|
||||
"无": {"rice_type": "none"},
|
||||
"东北大米": {"rice_type": "northeast"},
|
||||
"长粒米": {"rice_type": "longrain"},
|
||||
"香米": {"rice_type": "fragrant"},
|
||||
"五常大米": {"rice_type": "five"},
|
||||
}
|
||||
},
|
||||
"work_status": {
|
||||
"options": {
|
||||
"Stop": {"work_status": "cancel"},
|
||||
"Cooking": {"work_status": "cooking"},
|
||||
"Warming": {"work_status": "keep_warm"},
|
||||
"Soaking": {"work_status": "awakening_rice"},
|
||||
"Delay": {"work_status": "schedule"}
|
||||
"停止": {"work_status": "cancel"},
|
||||
"烹饪": {"work_status": "cooking"},
|
||||
"保温": {"work_status": "keep_warm"},
|
||||
"醒米": {"work_status": "awakening_rice"},
|
||||
"预约": {"work_status": "schedule"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from homeassistant.const import Platform, UnitOfTemperature, UnitOfTime, PERCENTAGE
|
||||
from homeassistant.const import Platform, UnitOfTemperature, UnitOfTime, PERCENTAGE, DEGREE
|
||||
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
|
||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from homeassistant.components.switch import SwitchDeviceClass
|
||||
@@ -23,17 +23,7 @@ DEVICE_MAPPING = {
|
||||
Platform.FAN: {
|
||||
"fan": {
|
||||
"power": "power",
|
||||
"speeds": [
|
||||
{"gear": "1"},
|
||||
{"gear": "2"},
|
||||
{"gear": "3"},
|
||||
{"gear": "4"},
|
||||
{"gear": "5"},
|
||||
{"gear": "6"},
|
||||
{"gear": "7"},
|
||||
{"gear": "8"},
|
||||
{"gear": "9"},
|
||||
],
|
||||
"speeds": list({"gear": value + 1} for value in range(0, 9)),
|
||||
"oscillate": "swing",
|
||||
"preset_modes": {
|
||||
"normal": {"mode": "normal"},
|
||||
@@ -102,26 +92,6 @@ DEVICE_MAPPING = {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"timer_off_hour": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.HOURS,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"timer_off_minute": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"timer_on_hour": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.HOURS,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"timer_on_minute": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"pm25": {
|
||||
"device_class": SensorDeviceClass.PM25,
|
||||
"unit_of_measurement": "µg/m³",
|
||||
@@ -153,5 +123,86 @@ DEVICE_MAPPING = {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"xxxxxx": {
|
||||
"rationale": ["off", "on"],
|
||||
"queries": [{}],
|
||||
"centralized": [
|
||||
"power", "gear"
|
||||
],
|
||||
"entities": {
|
||||
Platform.SWITCH: {
|
||||
"display_on_off": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
"rationale": ["on", "off"]
|
||||
},
|
||||
"anion": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
"temp_wind_switch": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
},
|
||||
Platform.FAN: {
|
||||
"fan": {
|
||||
"power": "power",
|
||||
"speeds": list({"gear": value + 1} for value in range(0, 100)),
|
||||
"preset_modes": {
|
||||
"self_selection": {"mode": "self_selection"},
|
||||
"sleeping_wind": {"mode": "sleeping_wind"},
|
||||
"purified_wind": {"mode": "purified_wind"}
|
||||
}
|
||||
}
|
||||
},
|
||||
Platform.SELECT: {
|
||||
"voice": {
|
||||
"options": {
|
||||
"open_buzzer": {"voice": "open_buzzer"},
|
||||
"close_buzzer": {"voice": "close_buzzer"},
|
||||
"mute": {"voice": "mute"}
|
||||
}
|
||||
},
|
||||
"lr_shake_switch": {
|
||||
"options": {
|
||||
"off": {"lr_shake_switch": "off"},
|
||||
"default": {"lr_shake_switch": "default"},
|
||||
"normal": {"lr_shake_switch": "normal"},
|
||||
}
|
||||
},
|
||||
"ud_shake_switch": {
|
||||
"options": {
|
||||
"off": {"ud_shake_switch": "off"},
|
||||
"default": {"ud_shake_switch": "default"},
|
||||
"normal": {"ud_shake_switch": "normal"},
|
||||
}
|
||||
},
|
||||
},
|
||||
Platform.SENSOR: {
|
||||
"real_gear": {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"dust_life_time": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.HOURS,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"filter_life_time": {
|
||||
"device_class": SensorDeviceClass.DURATION,
|
||||
"unit_of_measurement": UnitOfTime.HOURS,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"current_angle": {
|
||||
"device_class": SensorDeviceClass.WIND_DIRECTION,
|
||||
"unit_of_measurement": DEGREE,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"target_angle": {
|
||||
"device_class": SensorDeviceClass.WIND_DIRECTION,
|
||||
"unit_of_measurement": DEGREE,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,18 @@ class MideaFanEntity(MideaEntity, FanEntity):
|
||||
)
|
||||
self._key_power = self._config.get("power")
|
||||
self._key_preset_modes = self._config.get("preset_modes")
|
||||
self._key_speeds = self._config.get("speeds")
|
||||
speeds_config = self._config.get("speeds")
|
||||
# 处理范围形式的 speeds 配置: {"key": "gear", "value": [1, 9]}
|
||||
if isinstance(speeds_config, dict) and "key" in speeds_config and "value" in speeds_config:
|
||||
key_name = speeds_config["key"]
|
||||
value_range = speeds_config["value"]
|
||||
if isinstance(value_range, list) and len(value_range) == 2:
|
||||
start, end = value_range[0], value_range[1]
|
||||
self._key_speeds = [{key_name: str(i)} for i in range(start, end + 1)]
|
||||
else:
|
||||
self._key_speeds = speeds_config
|
||||
else:
|
||||
self._key_speeds = speeds_config
|
||||
self._key_oscillate = self._config.get("oscillate")
|
||||
self._key_directions = self._config.get("directions")
|
||||
self._attr_speed_count = len(self._key_speeds) if self._key_speeds else 0
|
||||
|
||||
@@ -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.14"
|
||||
"version": "v0.1.20"
|
||||
}
|
||||
117
custom_components/midea_auto_cloud/number.py
Normal file
117
custom_components/midea_auto_cloud/number.py
Normal file
@@ -0,0 +1,117 @@
|
||||
from homeassistant.components.number import NumberEntity
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
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:
|
||||
"""Set up number entities for Midea devices."""
|
||||
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.NUMBER, {})
|
||||
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(MideaNumberEntity(
|
||||
coordinator, device, manufacturer, rationale, entity_key, ecfg
|
||||
))
|
||||
async_add_entities(devs)
|
||||
|
||||
|
||||
class MideaNumberEntity(MideaEntity, NumberEntity):
|
||||
"""Midea number entity."""
|
||||
|
||||
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._min_value = self._config.get("min", 0.0)
|
||||
self._max_value = self._config.get("max", 100.0)
|
||||
self._step = self._config.get("step", 1.0)
|
||||
self._mode = self._config.get("mode", "auto") # auto, box, slider
|
||||
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the current value."""
|
||||
# Use attribute from config if available, otherwise fall back to entity_key
|
||||
attribute = self._config.get("attribute", self._entity_key)
|
||||
value = self._get_nested_value(attribute)
|
||||
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
# 确保返回的是数值类型
|
||||
try:
|
||||
return float(value)
|
||||
except (ValueError, TypeError):
|
||||
MideaLogger.warning(
|
||||
f"Failed to convert value '{value}' to float for number entity {self._entity_key}"
|
||||
)
|
||||
return None
|
||||
|
||||
@property
|
||||
def native_min_value(self) -> float:
|
||||
"""Return the minimum value."""
|
||||
return float(self._min_value)
|
||||
|
||||
@property
|
||||
def native_max_value(self) -> float:
|
||||
"""Return the maximum value."""
|
||||
return float(self._max_value)
|
||||
|
||||
@property
|
||||
def native_step(self) -> float:
|
||||
"""Return the step value."""
|
||||
return float(self._step)
|
||||
|
||||
@property
|
||||
def mode(self) -> str:
|
||||
"""Return the mode of the number entity."""
|
||||
return self._mode
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Set the value of the number entity."""
|
||||
# 确保值在有效范围内
|
||||
value = max(self._min_value, min(self._max_value, value))
|
||||
|
||||
# Use attribute from config if available, otherwise fall back to entity_key
|
||||
attribute = self._config.get("attribute", self._entity_key)
|
||||
|
||||
# 如果配置中指定了转换函数或映射,可以在这里处理
|
||||
# 否则直接设置属性值
|
||||
await self.async_set_attribute(attribute, str(int(value)))
|
||||
|
||||
@@ -349,6 +349,27 @@
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"b6_power": {
|
||||
"name": "Smoke Machine Power"
|
||||
},
|
||||
"b6_power_on_light": {
|
||||
"name": "Smoke Machine Power On Light"
|
||||
},
|
||||
"b6_lock": {
|
||||
"name": "Smoke Machine Lock"
|
||||
},
|
||||
"b6_gear": {
|
||||
"name": "Smoke Machine Gear"
|
||||
},
|
||||
"b6_smoke_stove_linkage_gear": {
|
||||
"name": "Smoke Stove Linkage Gear"
|
||||
},
|
||||
"b6_delay_gear_linkage_gear": {
|
||||
"name": "Smoke Machine Delay Gear Linkage Gear"
|
||||
},
|
||||
"b6_delay_time_value": {
|
||||
"name": "Smoke Machine Delay Time (Minute)"
|
||||
},
|
||||
"warm_target_temp": {
|
||||
"name": "Warm Target Temperature"
|
||||
},
|
||||
@@ -367,12 +388,6 @@
|
||||
"control_type": {
|
||||
"name": "Control Type"
|
||||
},
|
||||
"dehydration_speed": {
|
||||
"name": "Dehydration Speed"
|
||||
},
|
||||
"db_dehydration_speed": {
|
||||
"name": "DB Dehydration Speed"
|
||||
},
|
||||
"db_detergent": {
|
||||
"name": "DB Detergent"
|
||||
},
|
||||
@@ -403,9 +418,6 @@
|
||||
"detergent_density": {
|
||||
"name": "Detergent Density"
|
||||
},
|
||||
"dirty_degree": {
|
||||
"name": "Dirty Degree"
|
||||
},
|
||||
"disinfectant": {
|
||||
"name": "Disinfectant"
|
||||
},
|
||||
@@ -490,9 +502,6 @@
|
||||
"season": {
|
||||
"name": "Season"
|
||||
},
|
||||
"soak_count": {
|
||||
"name": "Soak Count"
|
||||
},
|
||||
"softener_density": {
|
||||
"name": "Softener Density"
|
||||
},
|
||||
@@ -571,15 +580,6 @@
|
||||
"gear": {
|
||||
"name": "Gear"
|
||||
},
|
||||
"detergent": {
|
||||
"name": "Detergent"
|
||||
},
|
||||
"softener": {
|
||||
"name": "Softener"
|
||||
},
|
||||
"temperature": {
|
||||
"name": "Temperature"
|
||||
},
|
||||
"ptc": {
|
||||
"name": "PTC"
|
||||
},
|
||||
@@ -1509,12 +1509,62 @@
|
||||
"name": "Light"
|
||||
}
|
||||
},
|
||||
"number": {
|
||||
"b6_lightness": {
|
||||
"name": "Smoke Machine Lightness"
|
||||
},
|
||||
"dehydration_speed": {
|
||||
"name": "Dehydration Speed"
|
||||
},
|
||||
"db_dehydration_speed": {
|
||||
"name": "DB Dehydration Speed"
|
||||
},
|
||||
"detergent": {
|
||||
"name": "Detergent"
|
||||
},
|
||||
"softener": {
|
||||
"name": "Softener"
|
||||
},
|
||||
"temperature": {
|
||||
"name": "Temperature"
|
||||
},
|
||||
"soak_count": {
|
||||
"name": "Soak Count"
|
||||
},
|
||||
"dirty_degree": {
|
||||
"name": "Dirty Degree"
|
||||
},
|
||||
"soak_time": {
|
||||
"name": "Soak Time"
|
||||
},
|
||||
"wash_time": {
|
||||
"name": "Wash Time"
|
||||
},
|
||||
"rinse_count": {
|
||||
"name": "Rinse Count"
|
||||
},
|
||||
"dehydration_time": {
|
||||
"name": "Dehydration Time"
|
||||
},
|
||||
"wash_level": {
|
||||
"name": "Wash Level"
|
||||
},
|
||||
"rinse_level": {
|
||||
"name": "Rinse Level"
|
||||
},
|
||||
"wash_strength": {
|
||||
"name": "Water Strength"
|
||||
}
|
||||
},
|
||||
"fan": {
|
||||
"fan": {
|
||||
"name": "Fan"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"b6_light": {
|
||||
"name": "Smoke Machine Light"
|
||||
},
|
||||
"temp_wind_switch": {
|
||||
"name": "Wind Change with Temperature"
|
||||
},
|
||||
|
||||
@@ -353,6 +353,27 @@
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"b6_power": {
|
||||
"name": "烟机开关"
|
||||
},
|
||||
"b6_power_on_light": {
|
||||
"name": "烟机开机开灯"
|
||||
},
|
||||
"b6_lock": {
|
||||
"name": "烟机锁屏"
|
||||
},
|
||||
"b6_gear": {
|
||||
"name": "烟机档位"
|
||||
},
|
||||
"b6_smoke_stove_linkage_gear": {
|
||||
"name": "烟灶联动档位"
|
||||
},
|
||||
"b6_delay_gear_linkage_gear": {
|
||||
"name": "烟机延时关机风速档位"
|
||||
},
|
||||
"b6_delay_time_value": {
|
||||
"name": "烟机延时关机时间(分钟)"
|
||||
},
|
||||
"warm_target_temp": {
|
||||
"name": "保温目标温度"
|
||||
},
|
||||
@@ -371,12 +392,6 @@
|
||||
"control_type": {
|
||||
"name": "控制类型"
|
||||
},
|
||||
"dehydration_speed": {
|
||||
"name": "脱水转速"
|
||||
},
|
||||
"db_dehydration_speed": {
|
||||
"name": "脱水转速"
|
||||
},
|
||||
"db_detergent": {
|
||||
"name": "洗涤剂"
|
||||
},
|
||||
@@ -407,9 +422,6 @@
|
||||
"detergent_density": {
|
||||
"name": "洗涤剂浓度"
|
||||
},
|
||||
"dirty_degree": {
|
||||
"name": "脏污程度"
|
||||
},
|
||||
"disinfectant": {
|
||||
"name": "消毒剂"
|
||||
},
|
||||
@@ -494,9 +506,6 @@
|
||||
"season": {
|
||||
"name": "季节"
|
||||
},
|
||||
"soak_count": {
|
||||
"name": "浸泡次数"
|
||||
},
|
||||
"softener_density": {
|
||||
"name": "柔顺剂浓度"
|
||||
},
|
||||
@@ -575,15 +584,6 @@
|
||||
"gear": {
|
||||
"name": "档位"
|
||||
},
|
||||
"detergent": {
|
||||
"name": "洗涤剂"
|
||||
},
|
||||
"softener": {
|
||||
"name": "柔顺剂"
|
||||
},
|
||||
"temperature": {
|
||||
"name": "温度"
|
||||
},
|
||||
"ptc": {
|
||||
"name": "电辅热"
|
||||
},
|
||||
@@ -1513,12 +1513,62 @@
|
||||
"name": "电灯"
|
||||
}
|
||||
},
|
||||
"number": {
|
||||
"b6_lightness": {
|
||||
"name": "烟机照明"
|
||||
},
|
||||
"dehydration_speed": {
|
||||
"name": "脱水转速"
|
||||
},
|
||||
"db_dehydration_speed": {
|
||||
"name": "脱水转速"
|
||||
},
|
||||
"detergent": {
|
||||
"name": "洗涤剂"
|
||||
},
|
||||
"softener": {
|
||||
"name": "柔顺剂"
|
||||
},
|
||||
"temperature": {
|
||||
"name": "温度"
|
||||
},
|
||||
"soak_count": {
|
||||
"name": "浸泡次数"
|
||||
},
|
||||
"dirty_degree": {
|
||||
"name": "脏污程度"
|
||||
},
|
||||
"soak_time": {
|
||||
"name": "浸泡时间"
|
||||
},
|
||||
"wash_time": {
|
||||
"name": "洗涤时间"
|
||||
},
|
||||
"rinse_count": {
|
||||
"name": "漂洗次数"
|
||||
},
|
||||
"dehydration_time": {
|
||||
"name": "脱水时间"
|
||||
},
|
||||
"wash_level": {
|
||||
"name": "洗涤水位"
|
||||
},
|
||||
"rinse_level": {
|
||||
"name": "漂洗水位"
|
||||
},
|
||||
"wash_strength": {
|
||||
"name": "水流强度"
|
||||
}
|
||||
},
|
||||
"fan": {
|
||||
"fan": {
|
||||
"name": "风扇"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"b6_light": {
|
||||
"name": "烟机灯"
|
||||
},
|
||||
"temp_wind_switch": {
|
||||
"name": "风随温变"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user