mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-12-27 23:07:10 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa553cd3a8 | ||
|
|
7ee22880ab | ||
|
|
e941dfc547 | ||
|
|
059cf3aebf | ||
|
|
48fac5ec42 | ||
|
|
c503b14d33 | ||
|
|
171d76ee3e |
@@ -21,6 +21,7 @@ Get devices from MSmartHome/Midea Meiju homes through the network and control th
|
||||
- T0x13 Electric Light
|
||||
- T0x21 Central Air Conditioning Gateway
|
||||
- T0x26 Bath Heater
|
||||
- T0x3D Water Heater
|
||||
- T0xA1 Dehumidifier
|
||||
- T0xAC Air Conditioner
|
||||
- T0xB2 Electric Steamer
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
|
||||
- T0x13 电灯
|
||||
- T0x21 中央空调网关
|
||||
- T0x26 浴霸
|
||||
- T0x26 浴霸
|
||||
- T0x3D 电热水瓶
|
||||
- T0xA1 除湿机
|
||||
- T0xAC 空调
|
||||
- T0xB2 电蒸箱
|
||||
|
||||
@@ -63,7 +63,7 @@ class MideaCloud:
|
||||
def _make_general_data(self):
|
||||
return {}
|
||||
|
||||
async def _api_request(self, endpoint: str, data: dict, header=None) -> dict | None:
|
||||
async def _api_request(self, endpoint: str, data: dict, header=None, method="POST") -> dict | None:
|
||||
header = header or {}
|
||||
if not data.get("reqId"):
|
||||
data.update({
|
||||
@@ -91,15 +91,18 @@ class MideaCloud:
|
||||
_LOGGER.debug(f"Midea cloud API header: {header}")
|
||||
_LOGGER.debug(f"Midea cloud API dump_data: {dump_data}")
|
||||
try:
|
||||
r = await self._session.request("POST", url, headers=header, data=dump_data, timeout=5)
|
||||
r = await self._session.request(method, url, headers=header, data=dump_data, timeout=5)
|
||||
raw = await r.read()
|
||||
_LOGGER.debug(f"Midea cloud API url: {url}, data: {data}, response: {raw}")
|
||||
response = json.loads(raw)
|
||||
except Exception as e:
|
||||
_LOGGER.debug(f"API request attempt failed: {e}")
|
||||
|
||||
if int(response["code"]) == 0 and "data" in response:
|
||||
return response["data"]
|
||||
if int(response["code"]) == 0:
|
||||
if "data" in response:
|
||||
return response["data"]
|
||||
else:
|
||||
return {"message": "ok"}
|
||||
|
||||
return None
|
||||
|
||||
@@ -207,6 +210,10 @@ class MideaCloud:
|
||||
"""Get status of central AC devices. Subclasses should implement if supported."""
|
||||
raise NotImplementedError()
|
||||
|
||||
async def send_switch_control(self, device_id: str, nodeid: str, switch_control: dict) -> bool:
|
||||
"""Send control to switch device. Subclasses should implement if supported."""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class MeijuCloud(MideaCloud):
|
||||
APP_ID = "900"
|
||||
@@ -405,6 +412,39 @@ class MeijuCloud(MideaCloud):
|
||||
)
|
||||
return response
|
||||
|
||||
async def send_switch_control(self, device_id: str, nodeid: str, switch_control: dict) -> bool:
|
||||
"""Send control to switch device using the controlPanelFour API with PUT method."""
|
||||
import uuid
|
||||
|
||||
# switch_control 格式: {"endPoint": 1, "attribute": 0}
|
||||
end_point = switch_control.get("endPoint", 1)
|
||||
attribute = switch_control.get("attribute", 0)
|
||||
|
||||
# 构建请求数据
|
||||
request_data = {
|
||||
"msgId": str(uuid.uuid4()).replace("-", ""),
|
||||
"deviceControlList": [{
|
||||
"endPoint": end_point,
|
||||
"attribute": attribute
|
||||
}],
|
||||
"deviceId": device_id,
|
||||
"nodeId": nodeid
|
||||
}
|
||||
|
||||
MideaLogger.debug(f"Sending switch control to device {device_id}: {request_data}")
|
||||
|
||||
# 使用PUT方法发送到开关控制API
|
||||
if response := await self._api_request(
|
||||
endpoint="/v1/appliance/operation/controlPanelFour/" + device_id,
|
||||
data=request_data,
|
||||
method="PUT"
|
||||
):
|
||||
MideaLogger.debug(f"[{device_id}] Switch control response: {response}")
|
||||
return True
|
||||
else:
|
||||
MideaLogger.warning(f"[{device_id}] Switch control failed: {response}")
|
||||
return False
|
||||
|
||||
async def download_lua(
|
||||
self, path: str,
|
||||
device_type: int,
|
||||
|
||||
@@ -123,9 +123,7 @@ class MideaDataUpdateCoordinator(DataUpdateCoordinator[MideaDeviceData]):
|
||||
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 "attr" in extra_data:
|
||||
if "nodeid" in extra_data["attr"]:
|
||||
self.device._attributes["nodeid"] = extra_data["attr"]["nodeid"]
|
||||
if "masterId" in extra_data["attr"]:
|
||||
@@ -135,7 +133,8 @@ class MideaDataUpdateCoordinator(DataUpdateCoordinator[MideaDeviceData]):
|
||||
if "idType" in extra_data["attr"]:
|
||||
self.device._attributes["idType"] = extra_data["attr"]["idType"]
|
||||
|
||||
if "condition_attribute" in state:
|
||||
if "state" in extra_data["attr"] and "condition_attribute" in extra_data["attr"]["state"]:
|
||||
state = extra_data["attr"]["state"]
|
||||
condition = state["condition_attribute"]
|
||||
# 将状态数据更新到设备属性中
|
||||
for key, value in condition.items():
|
||||
@@ -153,6 +152,32 @@ class MideaDataUpdateCoordinator(DataUpdateCoordinator[MideaDeviceData]):
|
||||
self.device._attributes[key] = value
|
||||
else:
|
||||
self.device._attributes[key] = value
|
||||
|
||||
if "endlist" in extra_data["attr"]:
|
||||
endlist = extra_data["attr"]["endlist"]
|
||||
# endlist是一个数组,包含多个endpoint对象
|
||||
if isinstance(endlist, list):
|
||||
for endpoint in endlist:
|
||||
if "event" in endpoint:
|
||||
event = endpoint["event"]
|
||||
endpoint_id = endpoint.get("endpoint", 1)
|
||||
endpoint_name = endpoint.get("name", f"按键{endpoint_id}")
|
||||
|
||||
# 为每个endpoint创建独立的状态属性
|
||||
for key, value in event.items():
|
||||
# 创建带endpoint标识的属性名
|
||||
attr_key = f"endpoint_{endpoint_id}_{key}"
|
||||
attr_name_key = f"endpoint_{endpoint_id}_name"
|
||||
|
||||
# 保存endpoint名称
|
||||
self.device._attributes[attr_name_key] = endpoint_name
|
||||
self.device._attributes[attr_key] = value
|
||||
|
||||
# 同时保持原有的属性名(用于兼容性)
|
||||
for key, value in event.items():
|
||||
# 尝试将数字字符串转换为数字
|
||||
self.device._attributes[key] = value
|
||||
|
||||
break
|
||||
except Exception as e:
|
||||
MideaLogger.debug(f"Error polling central AC state: {e}")
|
||||
@@ -223,6 +248,78 @@ class MideaDataUpdateCoordinator(DataUpdateCoordinator[MideaDeviceData]):
|
||||
MideaLogger.debug(f"Error sending control to {self.device.device_name}: {e}")
|
||||
return False
|
||||
|
||||
async def async_send_switch_control(self, control: dict) -> bool:
|
||||
"""发送开关控制命令(subtype为00000000的设备)"""
|
||||
try:
|
||||
cloud = self._cloud
|
||||
if cloud and hasattr(cloud, "send_switch_control"):
|
||||
# 获取设备ID和nodeId
|
||||
masterid = str(self.device.attributes.get("masterId"))
|
||||
nodeid = str(self.device.attributes.get("nodeid"))
|
||||
|
||||
if not nodeid:
|
||||
MideaLogger.warning(f"No nodeid found for switch device {self._device_id}")
|
||||
return False
|
||||
|
||||
# 根据控制命令确定endPoint和attribute值
|
||||
end_point = control.get("endpoint", 1) # 从control中获取endpoint,默认1
|
||||
attribute = 0 # 默认attribute
|
||||
|
||||
# 根据control内容设置attribute值
|
||||
if "run_mode" in control:
|
||||
if control["run_mode"] == "1":
|
||||
attribute = 1 # 开启
|
||||
else:
|
||||
attribute = 0 # 关闭
|
||||
|
||||
# 构建控制数据
|
||||
switch_control = {
|
||||
"endPoint": end_point,
|
||||
"attribute": attribute
|
||||
}
|
||||
|
||||
MideaLogger.debug(f"Sending switch control to {self.device.device_name}: {switch_control}")
|
||||
success = await cloud.send_switch_control(masterid, nodeid, switch_control)
|
||||
|
||||
if success:
|
||||
# 更新本地状态 - 使用类似poll_central的解析方法
|
||||
await self._update_switch_status_from_control(control)
|
||||
self.mute_state_update_for_a_while()
|
||||
self.async_update_listeners()
|
||||
return True
|
||||
else:
|
||||
MideaLogger.debug(f"Failed to send switch control to {self.device.device_name}")
|
||||
return False
|
||||
else:
|
||||
MideaLogger.debug("Cloud service not available for switch control")
|
||||
return False
|
||||
except Exception as e:
|
||||
MideaLogger.debug(f"Error sending switch control to {self.device.device_name}: {e}")
|
||||
return False
|
||||
|
||||
async def _update_switch_status_from_control(self, control: dict) -> None:
|
||||
"""根据控制命令更新开关状态,参照poll_central的解析方法"""
|
||||
try:
|
||||
# 获取endpoint ID
|
||||
endpoint_id = control.get("endpoint", 1)
|
||||
run_mode = control.get("run_mode", "0")
|
||||
|
||||
# 模拟endlist数据结构来更新状态
|
||||
# 根据run_mode设置OnOff状态
|
||||
onoff_value = "1" if run_mode == "1" else "0"
|
||||
|
||||
# 更新endpoint特定的状态属性
|
||||
attr_key = f"endpoint_{endpoint_id}_OnOff"
|
||||
self.device._attributes[attr_key] = onoff_value
|
||||
|
||||
# 同时更新兼容性属性
|
||||
self.device._attributes["OnOff"] = onoff_value
|
||||
|
||||
MideaLogger.debug(f"Updated switch status for endpoint {endpoint_id}: OnOff={onoff_value}")
|
||||
|
||||
except Exception as e:
|
||||
MideaLogger.debug(f"Error updating switch status from control: {e}")
|
||||
|
||||
def _build_full_central_ac_control(self, new_control: dict) -> dict:
|
||||
"""构建完整控制命令"""
|
||||
full_control = {}
|
||||
|
||||
@@ -45,7 +45,7 @@ DEVICE_MAPPING = {
|
||||
Platform.FAN: {
|
||||
"fan": {
|
||||
"power": "fan_power",
|
||||
"fan_speed": [
|
||||
"speeds": [
|
||||
{"fan_speed": "1"},
|
||||
{"fan_speed": "2"},
|
||||
{"fan_speed": "3"},
|
||||
|
||||
@@ -3,6 +3,23 @@ from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
|
||||
from homeassistant.components.switch import SwitchDeviceClass
|
||||
|
||||
DEVICE_MAPPING = {
|
||||
"00000000": {
|
||||
"rationale": ["0", "1"],
|
||||
"queries": [{}],
|
||||
"centralized": [],
|
||||
"entities": {
|
||||
Platform.SWITCH: {
|
||||
"endpoint_1_OnOff": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
"rationale": ['0', '1']
|
||||
},
|
||||
"endpoint_2_OnOff": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
"rationale": ['0', '1']
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"rationale": ["off", "on"],
|
||||
"queries": [{}],
|
||||
|
||||
48
custom_components/midea_auto_cloud/device_mapping/T0x3D.py
Normal file
48
custom_components/midea_auto_cloud/device_mapping/T0x3D.py
Normal file
@@ -0,0 +1,48 @@
|
||||
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": [],
|
||||
"entities": {
|
||||
Platform.SWITCH: {
|
||||
"work_switch": {
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
"rationale": ['cancel', 'work']
|
||||
}
|
||||
},
|
||||
Platform.SELECT: {
|
||||
"warm_target_temp": {
|
||||
"options": {
|
||||
"45℃": {"warm_target_temp": "45"},
|
||||
"55℃": {"warm_target_temp": "55"},
|
||||
"65℃": {"warm_target_temp": "65"},
|
||||
"75℃": {"warm_target_temp": "75"},
|
||||
"85℃": {"warm_target_temp": "85"}
|
||||
}
|
||||
},
|
||||
"boil_target_temp": {
|
||||
"options": {
|
||||
"45℃": {"boil_target_temp": "45"},
|
||||
"55℃": {"boil_target_temp": "55"},
|
||||
"65℃": {"boil_target_temp": "65"},
|
||||
"75℃": {"boil_target_temp": "75"},
|
||||
"85℃": {"boil_target_temp": "85"}
|
||||
}
|
||||
}
|
||||
},
|
||||
Platform.SENSOR: {
|
||||
"cur_temp": {
|
||||
"device_class": SensorDeviceClass.TEMPERATURE,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES
|
||||
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_HALVES, PRECISION_WHOLE
|
||||
from homeassistant.components.sensor import SensorStateClass, SensorDeviceClass
|
||||
# from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from homeassistant.components.switch import SwitchDeviceClass
|
||||
@@ -132,6 +132,32 @@ DEVICE_MAPPING = {
|
||||
}
|
||||
}
|
||||
},
|
||||
"106J6363": {
|
||||
"rationale": ["off", "on"],
|
||||
"queries": [{}],
|
||||
"centralized": [],
|
||||
"entities": {
|
||||
Platform.CLIMATE: {
|
||||
"thermostat": {
|
||||
"power": "water_model_power",
|
||||
"hvac_modes": {
|
||||
"off": {"water_model_power": "off"},
|
||||
"heat": {"water_model_power": "on", "water_model_temperature_auto": "off"},
|
||||
"auto": {"water_model_power": "on", "water_model_temperature_auto": "on"},
|
||||
},
|
||||
"preset_modes": {
|
||||
"none": {"water_model_go_out": "off"},
|
||||
"go out": {"water_model_go_out": "on"},
|
||||
},
|
||||
"target_temperature": "water_model_temperature_set",
|
||||
"min_temp": 25,
|
||||
"max_temp": 60,
|
||||
"temperature_unit": UnitOfTemperature.CELSIUS,
|
||||
"precision": PRECISION_WHOLE,
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
"26093139": {
|
||||
"rationale": [0, 3],
|
||||
"queries": [{}, {"query_type": "run_status"}],
|
||||
|
||||
@@ -8,34 +8,38 @@ DEVICE_MAPPING = {
|
||||
"rationale": ["off", "on"],
|
||||
"queries": [{}],
|
||||
"centralized": [
|
||||
"power", "humidify", "swing", "anion", "display_on_off",
|
||||
"dust_reset", "temp_wind_switch", "filter_reset"
|
||||
"power", "swing", "display_on_off", "temp_wind_switch",
|
||||
],
|
||||
"entities": {
|
||||
Platform.BINARY_SENSOR: {
|
||||
"power": {
|
||||
"device_class": BinarySensorDeviceClass.POWER,
|
||||
},
|
||||
"humidify": {
|
||||
"device_class": BinarySensorDeviceClass.RUNNING,
|
||||
},
|
||||
"swing": {
|
||||
"device_class": BinarySensorDeviceClass.RUNNING,
|
||||
},
|
||||
"anion": {
|
||||
"device_class": BinarySensorDeviceClass.RUNNING,
|
||||
},
|
||||
Platform.SWITCH: {
|
||||
"display_on_off": {
|
||||
"device_class": BinarySensorDeviceClass.RUNNING,
|
||||
},
|
||||
"dust_reset": {
|
||||
"device_class": BinarySensorDeviceClass.RUNNING,
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
"rationale": ["on", "off"]
|
||||
},
|
||||
"temp_wind_switch": {
|
||||
"device_class": BinarySensorDeviceClass.RUNNING,
|
||||
"device_class": SwitchDeviceClass.SWITCH,
|
||||
},
|
||||
"filter_reset": {
|
||||
"device_class": BinarySensorDeviceClass.RUNNING,
|
||||
},
|
||||
Platform.FAN: {
|
||||
"fan": {
|
||||
"power": "power",
|
||||
"speeds": [
|
||||
{"gear": "1"},
|
||||
{"gear": "2"},
|
||||
{"gear": "3"},
|
||||
{"gear": "4"},
|
||||
{"gear": "5"},
|
||||
{"gear": "6"},
|
||||
{"gear": "7"},
|
||||
{"gear": "8"},
|
||||
{"gear": "9"},
|
||||
],
|
||||
"oscillate": "swing",
|
||||
"preset_modes": {
|
||||
"normal": {"mode": "normal"},
|
||||
"sleep": {"mode": "sleep"},
|
||||
"baby": {"mode": "baby"}
|
||||
}
|
||||
}
|
||||
},
|
||||
Platform.SELECT: {
|
||||
@@ -65,16 +69,6 @@ DEVICE_MAPPING = {
|
||||
"both": {"swing_direction": "both"}
|
||||
}
|
||||
},
|
||||
"scene": {
|
||||
"options": {
|
||||
"none": {"scene": "none"},
|
||||
"auto": {"scene": "auto"},
|
||||
"sleep": {"scene": "sleep"},
|
||||
"work": {"scene": "work"},
|
||||
"study": {"scene": "study"},
|
||||
"party": {"scene": "party"}
|
||||
}
|
||||
},
|
||||
"sleep_sensor": {
|
||||
"options": {
|
||||
"none": {"sleep_sensor": "none"},
|
||||
@@ -83,27 +77,6 @@ DEVICE_MAPPING = {
|
||||
"both": {"sleep_sensor": "both"}
|
||||
}
|
||||
},
|
||||
"mode": {
|
||||
"options": {
|
||||
"normal": {"mode": "normal"},
|
||||
"auto": {"mode": "auto"},
|
||||
"manual": {"mode": "manual"},
|
||||
"sleep": {"mode": "sleep"},
|
||||
"turbo": {"mode": "turbo"},
|
||||
"quiet": {"mode": "quiet"}
|
||||
}
|
||||
},
|
||||
"gear": {
|
||||
"options": {
|
||||
"1": {"gear": "1"},
|
||||
"2": {"gear": "2"},
|
||||
"3": {"gear": "3"},
|
||||
"4": {"gear": "4"},
|
||||
"5": {"gear": "5"},
|
||||
"6": {"gear": "6"},
|
||||
"auto": {"gear": "auto"}
|
||||
}
|
||||
}
|
||||
},
|
||||
Platform.SENSOR: {
|
||||
"real_gear": {
|
||||
@@ -120,19 +93,6 @@ DEVICE_MAPPING = {
|
||||
"unit_of_measurement": UnitOfTime.HOURS,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"battery_status": {
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"battery_level": {
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
"unit_of_measurement": PERCENTAGE,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"error_code": {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"temperature_feedback": {
|
||||
"device_class": SensorDeviceClass.TEMPERATURE,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
@@ -162,10 +122,6 @@ DEVICE_MAPPING = {
|
||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"version": {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"pm25": {
|
||||
"device_class": SensorDeviceClass.PM25,
|
||||
"unit_of_measurement": "µg/m³",
|
||||
@@ -176,22 +132,22 @@ DEVICE_MAPPING = {
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"lr_diy_down_percent": {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
"unit_of_measurement": PERCENTAGE,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"lr_diy_up_percent": {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
"unit_of_measurement": PERCENTAGE,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"ud_diy_down_percent": {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
"unit_of_measurement": PERCENTAGE,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
},
|
||||
"ud_diy_up_percent": {
|
||||
"device_class": SensorDeviceClass.ENUM,
|
||||
"device_class": SensorDeviceClass.BATTERY,
|
||||
"unit_of_measurement": PERCENTAGE,
|
||||
"state_class": SensorStateClass.MEASUREMENT
|
||||
}
|
||||
|
||||
@@ -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.10"
|
||||
"version": "v0.1.14"
|
||||
}
|
||||
@@ -5,6 +5,7 @@ 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
|
||||
|
||||
@@ -43,6 +44,9 @@ class MideaSwitchEntity(MideaEntity, SwitchEntity):
|
||||
"""Midea switch entity."""
|
||||
|
||||
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,
|
||||
@@ -67,12 +71,37 @@ class MideaSwitchEntity(MideaEntity, SwitchEntity):
|
||||
|
||||
async def async_turn_on(self):
|
||||
"""Turn the switch on."""
|
||||
# Use attribute from config if available, otherwise fall back to entity_key
|
||||
attribute = self._config.get("attribute", self._entity_key)
|
||||
await self._async_set_status_on_off(attribute, True)
|
||||
if self._is_central_ac:
|
||||
await self._async_set_central_ac_switch_status(True)
|
||||
else:
|
||||
await self._async_set_status_on_off(attribute, True)
|
||||
|
||||
async def async_turn_off(self):
|
||||
"""Turn the switch off."""
|
||||
# Use attribute from config if available, otherwise fall back to entity_key
|
||||
attribute = self._config.get("attribute", self._entity_key)
|
||||
await self._async_set_status_on_off(attribute, False)
|
||||
if self._is_central_ac:
|
||||
await self._async_set_central_ac_switch_status(False)
|
||||
else:
|
||||
await self._async_set_status_on_off(attribute, False)
|
||||
|
||||
async def _async_set_central_ac_switch_status(self, is_on: bool):
|
||||
"""设置中央空调开关设备的状态"""
|
||||
# 从entity_key中提取endpoint ID
|
||||
# entity_key格式: endpoint_1_OnOff -> 提取出 1
|
||||
endpoint_id = 1 # 默认值
|
||||
if self._entity_key.startswith("endpoint_"):
|
||||
try:
|
||||
# 提取endpoint_后面的数字
|
||||
parts = self._entity_key.split("_")
|
||||
if len(parts) >= 2:
|
||||
endpoint_id = int(parts[1])
|
||||
except (ValueError, IndexError):
|
||||
MideaLogger.warning(f"Failed to extract endpoint ID from {self._entity_key}, using default 1")
|
||||
|
||||
# 构建控制命令
|
||||
control = {
|
||||
"run_mode": "1" if is_on else "0",
|
||||
"endpoint": endpoint_id
|
||||
}
|
||||
await self.coordinator.async_send_switch_control(control)
|
||||
|
||||
@@ -291,30 +291,6 @@
|
||||
"execute": {
|
||||
"name": "Execute"
|
||||
},
|
||||
"power": {
|
||||
"name": "Power"
|
||||
},
|
||||
"humidify": {
|
||||
"name": "Humidify"
|
||||
},
|
||||
"swing": {
|
||||
"name": "Swing"
|
||||
},
|
||||
"anion": {
|
||||
"name": "Anion"
|
||||
},
|
||||
"display_on_off": {
|
||||
"name": "Display On/Off"
|
||||
},
|
||||
"dust_reset": {
|
||||
"name": "Dust Reset"
|
||||
},
|
||||
"temp_wind_switch": {
|
||||
"name": "Temp Wind Switch"
|
||||
},
|
||||
"filter_reset": {
|
||||
"name": "Filter Reset"
|
||||
},
|
||||
"heat_status": {
|
||||
"name": "Heat Status"
|
||||
},
|
||||
@@ -373,6 +349,12 @@
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"warm_target_temp": {
|
||||
"name": "Warm Target Temperature"
|
||||
},
|
||||
"boil_target_temp": {
|
||||
"name": "Boil Target Temperature"
|
||||
},
|
||||
"add_rinse": {
|
||||
"name": "Add Rinse"
|
||||
},
|
||||
@@ -1533,6 +1515,9 @@
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"temp_wind_switch": {
|
||||
"name": "Wind Change with Temperature"
|
||||
},
|
||||
"screen_close": {
|
||||
"name": "Screen Close"
|
||||
},
|
||||
@@ -2387,6 +2372,33 @@
|
||||
},
|
||||
"is_lock_rc": {
|
||||
"name": "Remote Control Lock"
|
||||
},
|
||||
"endpoint_1_onoff": {
|
||||
"name": "Button 1"
|
||||
},
|
||||
"endpoint_2_onoff": {
|
||||
"name": "Button 2"
|
||||
},
|
||||
"endpoint_3_onoff": {
|
||||
"name": "Button 3"
|
||||
},
|
||||
"endpoint_4_onoff": {
|
||||
"name": "Button 4"
|
||||
},
|
||||
"endpoint_5_onoff": {
|
||||
"name": "Button 5"
|
||||
},
|
||||
"endpoint_6_onoff": {
|
||||
"name": "Button 6"
|
||||
},
|
||||
"endpoint_7_onoff": {
|
||||
"name": "Button 7"
|
||||
},
|
||||
"endpoint_8_onoff": {
|
||||
"name": "Button 8"
|
||||
},
|
||||
"work_switch": {
|
||||
"name": "Work Switch"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,30 +291,6 @@
|
||||
"execute": {
|
||||
"name": "执行"
|
||||
},
|
||||
"power": {
|
||||
"name": "电源"
|
||||
},
|
||||
"humidify": {
|
||||
"name": "加湿"
|
||||
},
|
||||
"swing": {
|
||||
"name": "摆风"
|
||||
},
|
||||
"anion": {
|
||||
"name": "负离子"
|
||||
},
|
||||
"display_on_off": {
|
||||
"name": "显示开关"
|
||||
},
|
||||
"dust_reset": {
|
||||
"name": "灰尘重置"
|
||||
},
|
||||
"temp_wind_switch": {
|
||||
"name": "温风开关"
|
||||
},
|
||||
"filter_reset": {
|
||||
"name": "滤网重置"
|
||||
},
|
||||
"heat_status": {
|
||||
"name": "加热状态"
|
||||
},
|
||||
@@ -377,6 +353,12 @@
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"warm_target_temp": {
|
||||
"name": "保温目标温度"
|
||||
},
|
||||
"boil_target_temp": {
|
||||
"name": "煮沸目标温度"
|
||||
},
|
||||
"add_rinse": {
|
||||
"name": "加漂洗"
|
||||
},
|
||||
@@ -1537,6 +1519,9 @@
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"temp_wind_switch": {
|
||||
"name": "风随温变"
|
||||
},
|
||||
"screen_close": {
|
||||
"name": "屏幕关闭"
|
||||
},
|
||||
@@ -2391,6 +2376,33 @@
|
||||
},
|
||||
"is_lock_rc": {
|
||||
"name": "遥控锁定"
|
||||
},
|
||||
"endpoint_1_onoff": {
|
||||
"name": "按键一"
|
||||
},
|
||||
"endpoint_2_onoff": {
|
||||
"name": "按键二"
|
||||
},
|
||||
"endpoint_3_onoff": {
|
||||
"name": "按键三"
|
||||
},
|
||||
"endpoint_4_onoff": {
|
||||
"name": "按键四"
|
||||
},
|
||||
"endpoint_5_onoff": {
|
||||
"name": "按键五"
|
||||
},
|
||||
"endpoint_6_onoff": {
|
||||
"name": "按键六"
|
||||
},
|
||||
"endpoint_7_onoff": {
|
||||
"name": "按键七"
|
||||
},
|
||||
"endpoint_8_onoff": {
|
||||
"name": "按键八"
|
||||
},
|
||||
"work_switch": {
|
||||
"name": "工作开关"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user