mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-12-22 04:17:11 +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:
|
||||
if k not in device.attributes:
|
||||
device.attributes[k] = None
|
||||
# 针对T0xD9复式洗衣机,设置默认的筒选择为左筒
|
||||
if device.device_type == 0xD9:
|
||||
device.attributes["db_location_selection"] = "left"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -166,6 +166,22 @@ class MiedaDevice(threading.Thread):
|
||||
new_status[attr] = self._attributes.get(attr)
|
||||
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
|
||||
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)
|
||||
|
||||
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 = {}
|
||||
for attr in self._centralized:
|
||||
new_status[attr] = self._attributes.get(attr)
|
||||
@@ -202,6 +228,14 @@ class MiedaDevice(threading.Thread):
|
||||
has_new = True
|
||||
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
|
||||
nested_status = self._convert_to_nested_structure(new_status)
|
||||
|
||||
@@ -291,6 +325,15 @@ class MiedaDevice(threading.Thread):
|
||||
|
||||
async def refresh_status(self):
|
||||
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
|
||||
if cloud and hasattr(cloud, "get_device_status"):
|
||||
if isinstance(cloud, MSmartHomeCloud):
|
||||
@@ -300,23 +343,23 @@ class MiedaDevice(threading.Thread):
|
||||
sn=self.sn,
|
||||
model_number=self.subtype,
|
||||
manufacturer_code=self._manufacturer_code,
|
||||
query=query
|
||||
query=actual_query
|
||||
):
|
||||
self._parse_cloud_message(status)
|
||||
else:
|
||||
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)
|
||||
|
||||
elif isinstance(cloud, MeijuCloud):
|
||||
if status := await cloud.get_device_status(
|
||||
appliance_code=self._device_id,
|
||||
query=query
|
||||
query=actual_query
|
||||
):
|
||||
self._parse_cloud_message(status)
|
||||
else:
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from homeassistant.components.switch import SwitchDeviceClass
|
||||
DEVICE_MAPPING = {
|
||||
"default": {
|
||||
"rationale": ["off", "on"],
|
||||
"queries": [{}],
|
||||
"queries": [{"query_type": "db"}],
|
||||
"calculate": {
|
||||
"get": [
|
||||
{
|
||||
@@ -50,6 +50,12 @@ DEVICE_MAPPING = {
|
||||
}
|
||||
},
|
||||
Platform.SELECT: {
|
||||
"db_location_selection": {
|
||||
"options": {
|
||||
"left": {"db_location_selection": "left"},
|
||||
"right": {"db_location_selection": "right"}
|
||||
}
|
||||
},
|
||||
"db_running_status": {
|
||||
"options": {
|
||||
"off": {"db_power": "off", "db_running_status": "off"},
|
||||
|
||||
@@ -471,8 +471,12 @@
|
||||
"db_detergent": {
|
||||
"name": "DB Detergent"
|
||||
},
|
||||
"db_location": {
|
||||
"name": "DB Location"
|
||||
"db_location_selection": {
|
||||
"name": "Bucket Selection",
|
||||
"state": {
|
||||
"left": "Left Bucket",
|
||||
"right": "Right Bucket"
|
||||
}
|
||||
},
|
||||
"db_position": {
|
||||
"name": "DB Position"
|
||||
|
||||
@@ -471,8 +471,12 @@
|
||||
"db_detergent": {
|
||||
"name": "洗涤剂"
|
||||
},
|
||||
"db_location": {
|
||||
"name": "地点"
|
||||
"db_location_selection": {
|
||||
"name": "选择筒",
|
||||
"state": {
|
||||
"left": "左筒",
|
||||
"right": "右筒"
|
||||
}
|
||||
},
|
||||
"db_position": {
|
||||
"name": "位置"
|
||||
|
||||
Reference in New Issue
Block a user