This commit is contained in:
Home Assistant Version Control
2026-07-24 15:19:02 +00:00
parent 8abf4efaec
commit 2d21a40fd6
48 changed files with 4181 additions and 232 deletions
+33 -2
View File
@@ -70,13 +70,17 @@ else:
from .const import (
CONF_ACCOUNT,
CONF_KEY,
CONF_MAC,
CONF_MODEL,
CONF_REFRESH_INTERVAL,
CONF_SERVER,
CONF_SN,
CONF_SUBTYPE,
DEVICES,
DOMAIN,
EXTRA_CONTROL,
EXTRA_SENSOR,
supports_model,
)
from .midea_devices import MIDEA_DEVICES
@@ -105,7 +109,7 @@ class MideaLanConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call-arg]
"""
VERSION = 2
MINOR_VERSION = 1
MINOR_VERSION = 2
def __init__(self) -> None:
"""MideaLanConfigFlow class."""
@@ -140,7 +144,7 @@ class MideaLanConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call-arg]
record_file = storage_path.joinpath(f"{data[CONF_DEVICE_ID]!s}.json")
save_json(str(record_file), data)
def _load_device_config(self, device_id: str) -> Any: # noqa: ANN401
def _load_device_config(self, device_id: str) -> Any: # ruff:ignore[any-type]
"""Load device config from json file with device id.
Returns
@@ -798,6 +802,8 @@ class MideaLanConfigFlow(ConfigFlow, domain=DOMAIN): # type: ignore[call-arg]
CONF_SUBTYPE: user_input[CONF_SUBTYPE],
CONF_TOKEN: user_input[CONF_TOKEN],
CONF_KEY: user_input[CONF_KEY],
CONF_MAC: device.get(CONF_MAC),
CONF_SN: device.get(CONF_SN),
}
# save device json config when adding new device
self._save_device_config(data)
@@ -937,13 +943,38 @@ class MideaLanOptionsFlowHandler(OptionsFlow):
return self.async_create_entry(title="", data=user_input)
sensors = {}
switches = {}
device_id = self._config_entry.data.get(CONF_DEVICE_ID)
device = (
self.hass.data.get(DOMAIN, {}).get(DEVICES, {}).get(device_id)
if device_id is not None
else None
)
selected_attributes = set(
self._config_entry.options.get(CONF_SENSORS, []),
) | set(self._config_entry.options.get(CONF_SWITCHES, []))
for attribute, attribute_config in cast(
"dict",
MIDEA_DEVICES[cast("int", self._device_type)]["entities"],
).items():
if not supports_model(
self._config_entry.data.get(CONF_MODEL),
attribute_config,
):
continue
attribute_name = (
attribute if isinstance(attribute, str) else attribute.value
)
required_attribute = attribute_config.get("required_attribute")
if (
required_attribute is not None
and (
device is None
or required_attribute not in device.attributes
or device.get_attribute(required_attribute) is None
)
and attribute_name not in selected_attributes
):
continue
if attribute_config.get("type") in EXTRA_SENSOR:
sensors[attribute_name] = attribute_config.get("name")
elif attribute_config.get(