diff --git a/custom_components/midea_auto_cloud/__init__.py b/custom_components/midea_auto_cloud/__init__.py index 9e99798..9a687a7 100644 --- a/custom_components/midea_auto_cloud/__init__.py +++ b/custom_components/midea_auto_cloud/__init__.py @@ -131,16 +131,16 @@ 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) + # 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 diff --git a/custom_components/midea_auto_cloud/device_mapping/T0xE2.py b/custom_components/midea_auto_cloud/device_mapping/T0xE2.py index 7cf75af..36c5854 100644 --- a/custom_components/midea_auto_cloud/device_mapping/T0xE2.py +++ b/custom_components/midea_auto_cloud/device_mapping/T0xE2.py @@ -50,48 +50,15 @@ DEVICE_MAPPING = { } }, Platform.SWITCH: { - "music": { - "device_class": SwitchDeviceClass.SWITCH, - }, "ti_protect": { "device_class": SwitchDeviceClass.SWITCH, }, - "fast_wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "ali_manager": { - "device_class": SwitchDeviceClass.SWITCH, - }, "heat": { "device_class": SwitchDeviceClass.SWITCH, }, - "ele_exception": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "communication_error": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "eplus": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "summer": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "winter": { - "device_class": SwitchDeviceClass.SWITCH, - }, "efficient": { "device_class": SwitchDeviceClass.SWITCH, }, - "night": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "bath_person": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "cloud": { - "device_class": SwitchDeviceClass.SWITCH, - }, "bath": { "device_class": SwitchDeviceClass.SWITCH, }, @@ -101,87 +68,12 @@ DEVICE_MAPPING = { "whole_heat": { "device_class": SwitchDeviceClass.SWITCH, }, - "sterilization": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "frequency_hot": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "scene": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "big_water": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "negative_ions": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "screen_off": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "t_hot": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "baby_wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "dad_wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "mom_wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "wash_with_temp": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "single_wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "people_wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "one_egg": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "two_egg": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "always_fell": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "smart_sterilize": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "sound_dad": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "door_status": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "limit_error": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "sensor_error": { - "device_class": SwitchDeviceClass.SWITCH, - }, "auto_off": { "device_class": SwitchDeviceClass.SWITCH, }, - "clean": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "cloud_appoint": { - "device_class": SwitchDeviceClass.SWITCH, - }, "protect": { "device_class": SwitchDeviceClass.SWITCH, }, - "midea_manager": { - "device_class": SwitchDeviceClass.SWITCH, - }, "sleep": { "device_class": SwitchDeviceClass.SWITCH, }, @@ -191,9 +83,6 @@ DEVICE_MAPPING = { "shower": { "device_class": SwitchDeviceClass.SWITCH, }, - "scroll_hot": { - "device_class": SwitchDeviceClass.SWITCH, - }, "fast_hot_power": { "device_class": SwitchDeviceClass.SWITCH, }, @@ -206,54 +95,12 @@ DEVICE_MAPPING = { "water_flow": { "device_class": SwitchDeviceClass.SWITCH, }, - "appoint_wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "now_wash": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "get_time": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "get_temp": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "warm_power": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "sterilize_high_temp": { - "device_class": SwitchDeviceClass.SWITCH, - }, "bottom_heat": { "device_class": SwitchDeviceClass.SWITCH, }, "top_heat": { "device_class": SwitchDeviceClass.SWITCH, }, - "show_h": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "uv_sterilize": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "need_discharge": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "elec_warning": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "water_cyclic": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "tech_water": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "protect_show": { - "device_class": SwitchDeviceClass.SWITCH, - }, - "appoint_power": { - "device_class": SwitchDeviceClass.SWITCH, - } }, Platform.SELECT: { "mode": { @@ -365,22 +212,11 @@ DEVICE_MAPPING = { "unit_of_measurement": UnitOfTime.MINUTES, "state_class": SensorStateClass.MEASUREMENT }, - "version": { - "device_class": SensorDeviceClass.ENUM - }, "tds_value": { "device_class": SensorDeviceClass.WATER, "unit_of_measurement": "ppm", "state_class": SensorStateClass.MEASUREMENT }, - "scene_id": { - "device_class": SensorDeviceClass.ENUM - }, - "volume": { - "device_class": SensorDeviceClass.SOUND_PRESSURE, - "unit_of_measurement": "%", - "state_class": SensorStateClass.MEASUREMENT - }, "heat_water_level": { "device_class": SensorDeviceClass.WATER, "unit_of_measurement": "%", diff --git a/custom_components/midea_auto_cloud/sensor.py b/custom_components/midea_auto_cloud/sensor.py index e539bb6..9b227be 100644 --- a/custom_components/midea_auto_cloud/sensor.py +++ b/custom_components/midea_auto_cloud/sensor.py @@ -5,7 +5,6 @@ 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 diff --git a/custom_components/midea_auto_cloud/water_heater.py b/custom_components/midea_auto_cloud/water_heater.py index 925475a..cce82a7 100644 --- a/custom_components/midea_auto_cloud/water_heater.py +++ b/custom_components/midea_auto_cloud/water_heater.py @@ -1,14 +1,23 @@ from homeassistant.components.water_heater import WaterHeaterEntity, WaterHeaterEntityFeature +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( Platform, ATTR_TEMPERATURE ) +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + from .const import DOMAIN from .midea_entity import MideaEntity from . import load_device_config -async def async_setup_entry(hass, config_entry, async_add_entities): +async def async_setup_entry( + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up water heater entities for Midea devices.""" account_bucket = hass.data.get(DOMAIN, {}).get("accounts", {}).get(config_entry.entry_id) if not account_bucket: async_add_entities([]) @@ -51,30 +60,6 @@ class MideaWaterHeaterEntityEntity(MideaEntity, WaterHeaterEntity): self._manufacturer = manufacturer self._rationale = rationale self._config = config - # Legacy compatibility: register update and restore display attributes - if self._device: - self._device.register_update(self.update_state) - if (rationale_local := self._config.get("rationale")) is not None: - self._rationale = rationale_local - if self._rationale is None: - self._rationale = ["off", "on"] - self._attr_native_unit_of_measurement = self._config.get("unit_of_measurement") - self._attr_device_class = self._config.get("device_class") - self._attr_state_class = self._config.get("state_class") - self._attr_icon = self._config.get("icon") - from .const import DOMAIN as _DOMAIN - self._attr_unique_id = f"{_DOMAIN}.{self._device.device_id}_{self._entity_key}" - self._attr_device_info = { - "manufacturer": "Midea" if self._manufacturer is None else self._manufacturer, - "model": f"{self._device.model}", - "identifiers": {( _DOMAIN, self._device.device_id)}, - "name": self._device.device_name - } - name = self._config.get("name") - if name is None: - name = self._entity_key.replace("_", " ").title() - self._attr_name = f"{self._device.device_name} {name}" - self.entity_id = self._attr_unique_id self._key_power = self._config.get("power") self._key_operation_list = self._config.get("operation_list") self._key_min_temp = self._config.get("min_temp") @@ -167,9 +152,3 @@ class MideaWaterHeaterEntityEntity(MideaEntity, WaterHeaterEntity): if new_status: await self.async_set_attributes(new_status) - def update_state(self, status): - try: - self.schedule_update_ha_state() - except Exception: - pass -