mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-12-22 12:27:12 +00:00
feat: add multi-tub support for T0xD9.
This commit is contained in:
@@ -369,6 +369,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
|||||||
for k in preset_keys:
|
for k in preset_keys:
|
||||||
if k not in device.attributes:
|
if k not in device.attributes:
|
||||||
device.attributes[k] = None
|
device.attributes[k] = None
|
||||||
|
# 针对T0xD9复式洗衣机,设置默认的筒选择为左筒
|
||||||
|
if device.device_type == 0xD9:
|
||||||
|
device.attributes["db_location_selection"] = "left"
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,22 @@ class MiedaDevice(threading.Thread):
|
|||||||
new_status[attr] = self._attributes.get(attr)
|
new_status[attr] = self._attributes.get(attr)
|
||||||
new_status[attribute] = value
|
new_status[attribute] = value
|
||||||
|
|
||||||
|
# 针对T0xD9复式洗衣机,当切换筒选择时,立即刷新状态以显示新筒的状态
|
||||||
|
if self._device_type == 0xD9 and attribute == "db_location_selection":
|
||||||
|
# 更新属性
|
||||||
|
self._attributes[attribute] = value
|
||||||
|
# 立即刷新状态以显示新筒的状态
|
||||||
|
await self.refresh_status()
|
||||||
|
return
|
||||||
|
|
||||||
|
# 针对T0xD9复式洗衣机,根据选择的筒添加db_location参数
|
||||||
|
if self._device_type == 0xD9 and attribute != "db_location_selection":
|
||||||
|
location_selection = self._attributes.get("db_location_selection", "left")
|
||||||
|
if location_selection == "left":
|
||||||
|
new_status["db_location"] = 1
|
||||||
|
elif location_selection == "right":
|
||||||
|
new_status["db_location"] = 2
|
||||||
|
|
||||||
# Convert dot-notation attributes to nested structure for transmission
|
# Convert dot-notation attributes to nested structure for transmission
|
||||||
nested_status = self._convert_to_nested_structure(new_status)
|
nested_status = self._convert_to_nested_structure(new_status)
|
||||||
|
|
||||||
@@ -193,6 +209,16 @@ class MiedaDevice(threading.Thread):
|
|||||||
await cloud.send_device_control(self._device_id, control=nested_status, status=self._attributes)
|
await cloud.send_device_control(self._device_id, control=nested_status, status=self._attributes)
|
||||||
|
|
||||||
async def set_attributes(self, attributes):
|
async def set_attributes(self, attributes):
|
||||||
|
# 针对T0xD9复式洗衣机,当切换筒选择时,立即刷新状态以显示新筒的状态
|
||||||
|
if self._device_type == 0xD9 and "db_location_selection" in attributes:
|
||||||
|
# 更新属性
|
||||||
|
for attribute, value in attributes.items():
|
||||||
|
if attribute in self._attributes.keys():
|
||||||
|
self._attributes[attribute] = value
|
||||||
|
# 立即刷新状态以显示新筒的状态
|
||||||
|
await self.refresh_status()
|
||||||
|
return
|
||||||
|
|
||||||
new_status = {}
|
new_status = {}
|
||||||
for attr in self._centralized:
|
for attr in self._centralized:
|
||||||
new_status[attr] = self._attributes.get(attr)
|
new_status[attr] = self._attributes.get(attr)
|
||||||
@@ -202,6 +228,14 @@ class MiedaDevice(threading.Thread):
|
|||||||
has_new = True
|
has_new = True
|
||||||
new_status[attribute] = value
|
new_status[attribute] = value
|
||||||
|
|
||||||
|
# 针对T0xD9复式洗衣机,根据选择的筒添加db_location参数
|
||||||
|
if self._device_type == 0xD9 and "db_location_selection" not in attributes:
|
||||||
|
location_selection = self._attributes.get("db_location_selection", "left")
|
||||||
|
if location_selection == "left":
|
||||||
|
new_status["db_location"] = 1
|
||||||
|
elif location_selection == "right":
|
||||||
|
new_status["db_location"] = 2
|
||||||
|
|
||||||
# Convert dot-notation attributes to nested structure for transmission
|
# Convert dot-notation attributes to nested structure for transmission
|
||||||
nested_status = self._convert_to_nested_structure(new_status)
|
nested_status = self._convert_to_nested_structure(new_status)
|
||||||
|
|
||||||
@@ -291,6 +325,15 @@ class MiedaDevice(threading.Thread):
|
|||||||
|
|
||||||
async def refresh_status(self):
|
async def refresh_status(self):
|
||||||
for query in self._queries:
|
for query in self._queries:
|
||||||
|
# 针对T0xD9复式洗衣机,根据选择的筒动态添加db_location参数
|
||||||
|
actual_query = query.copy() if isinstance(query, dict) else query
|
||||||
|
if self._device_type == 0xD9 and isinstance(actual_query, dict):
|
||||||
|
location_selection = self._attributes.get("db_location_selection", "left")
|
||||||
|
if location_selection == "left":
|
||||||
|
actual_query["db_location"] = 1
|
||||||
|
elif location_selection == "right":
|
||||||
|
actual_query["db_location"] = 2
|
||||||
|
|
||||||
cloud = self._cloud
|
cloud = self._cloud
|
||||||
if cloud and hasattr(cloud, "get_device_status"):
|
if cloud and hasattr(cloud, "get_device_status"):
|
||||||
if isinstance(cloud, MSmartHomeCloud):
|
if isinstance(cloud, MSmartHomeCloud):
|
||||||
@@ -300,23 +343,23 @@ class MiedaDevice(threading.Thread):
|
|||||||
sn=self.sn,
|
sn=self.sn,
|
||||||
model_number=self.subtype,
|
model_number=self.subtype,
|
||||||
manufacturer_code=self._manufacturer_code,
|
manufacturer_code=self._manufacturer_code,
|
||||||
query=query
|
query=actual_query
|
||||||
):
|
):
|
||||||
self._parse_cloud_message(status)
|
self._parse_cloud_message(status)
|
||||||
else:
|
else:
|
||||||
if self._lua_runtime is not None:
|
if self._lua_runtime is not None:
|
||||||
if query_cmd := self._lua_runtime.build_query(query):
|
if query_cmd := self._lua_runtime.build_query(actual_query):
|
||||||
await self._build_send(query_cmd)
|
await self._build_send(query_cmd)
|
||||||
|
|
||||||
elif isinstance(cloud, MeijuCloud):
|
elif isinstance(cloud, MeijuCloud):
|
||||||
if status := await cloud.get_device_status(
|
if status := await cloud.get_device_status(
|
||||||
appliance_code=self._device_id,
|
appliance_code=self._device_id,
|
||||||
query=query
|
query=actual_query
|
||||||
):
|
):
|
||||||
self._parse_cloud_message(status)
|
self._parse_cloud_message(status)
|
||||||
else:
|
else:
|
||||||
if self._lua_runtime is not None:
|
if self._lua_runtime is not None:
|
||||||
if query_cmd := self._lua_runtime.build_query(query):
|
if query_cmd := self._lua_runtime.build_query(actual_query):
|
||||||
await self._build_send(query_cmd)
|
await self._build_send(query_cmd)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from homeassistant.components.switch import SwitchDeviceClass
|
|||||||
DEVICE_MAPPING = {
|
DEVICE_MAPPING = {
|
||||||
"default": {
|
"default": {
|
||||||
"rationale": ["off", "on"],
|
"rationale": ["off", "on"],
|
||||||
"queries": [{}],
|
"queries": [{"query_type": "db"}],
|
||||||
"calculate": {
|
"calculate": {
|
||||||
"get": [
|
"get": [
|
||||||
{
|
{
|
||||||
@@ -50,6 +50,12 @@ DEVICE_MAPPING = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Platform.SELECT: {
|
Platform.SELECT: {
|
||||||
|
"db_location_selection": {
|
||||||
|
"options": {
|
||||||
|
"left": {"db_location_selection": "left"},
|
||||||
|
"right": {"db_location_selection": "right"}
|
||||||
|
}
|
||||||
|
},
|
||||||
"db_running_status": {
|
"db_running_status": {
|
||||||
"options": {
|
"options": {
|
||||||
"off": {"db_power": "off", "db_running_status": "off"},
|
"off": {"db_power": "off", "db_running_status": "off"},
|
||||||
|
|||||||
@@ -471,8 +471,12 @@
|
|||||||
"db_detergent": {
|
"db_detergent": {
|
||||||
"name": "DB Detergent"
|
"name": "DB Detergent"
|
||||||
},
|
},
|
||||||
"db_location": {
|
"db_location_selection": {
|
||||||
"name": "DB Location"
|
"name": "Bucket Selection",
|
||||||
|
"state": {
|
||||||
|
"left": "Left Bucket",
|
||||||
|
"right": "Right Bucket"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"db_position": {
|
"db_position": {
|
||||||
"name": "DB Position"
|
"name": "DB Position"
|
||||||
|
|||||||
@@ -471,8 +471,12 @@
|
|||||||
"db_detergent": {
|
"db_detergent": {
|
||||||
"name": "洗涤剂"
|
"name": "洗涤剂"
|
||||||
},
|
},
|
||||||
"db_location": {
|
"db_location_selection": {
|
||||||
"name": "地点"
|
"name": "选择筒",
|
||||||
|
"state": {
|
||||||
|
"left": "左筒",
|
||||||
|
"right": "右筒"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"db_position": {
|
"db_position": {
|
||||||
"name": "位置"
|
"name": "位置"
|
||||||
|
|||||||
Reference in New Issue
Block a user