forked from HomeAssistant/midea-meiju-codec
fix: reform water heater entity.
This commit is contained in:
@@ -131,16 +131,16 @@ async def async_setup(hass: HomeAssistant, config: ConfigType):
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
cjson = os.getcwd() + "/cjson.lua"
|
cjson = os.getcwd() + "/cjson.lua"
|
||||||
bit = os.getcwd() + "/bit.lua"
|
bit = os.getcwd() + "/bit.lua"
|
||||||
if not os.path.exists(cjson):
|
# if not os.path.exists(cjson):
|
||||||
from .const import CJSON_LUA
|
from .const import CJSON_LUA
|
||||||
cjson_lua = base64.b64decode(CJSON_LUA.encode("utf-8")).decode("utf-8")
|
cjson_lua = base64.b64decode(CJSON_LUA.encode("utf-8")).decode("utf-8")
|
||||||
with open(cjson, "wt") as fp:
|
with open(cjson, "wt") as fp:
|
||||||
fp.write(cjson_lua)
|
fp.write(cjson_lua)
|
||||||
if not os.path.exists(bit):
|
# if not os.path.exists(bit):
|
||||||
from .const import BIT_LUA
|
from .const import BIT_LUA
|
||||||
bit_lua = base64.b64decode(BIT_LUA.encode("utf-8")).decode("utf-8")
|
bit_lua = base64.b64decode(BIT_LUA.encode("utf-8")).decode("utf-8")
|
||||||
with open(bit, "wt") as fp:
|
with open(bit, "wt") as fp:
|
||||||
fp.write(bit_lua)
|
fp.write(bit_lua)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@@ -50,48 +50,15 @@ DEVICE_MAPPING = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Platform.SWITCH: {
|
Platform.SWITCH: {
|
||||||
"music": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"ti_protect": {
|
"ti_protect": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
"fast_wash": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"ali_manager": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"heat": {
|
"heat": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"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": {
|
"efficient": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
"night": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"bath_person": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"cloud": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"bath": {
|
"bath": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
@@ -101,87 +68,12 @@ DEVICE_MAPPING = {
|
|||||||
"whole_heat": {
|
"whole_heat": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"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": {
|
"auto_off": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
"clean": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"cloud_appoint": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"protect": {
|
"protect": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
"midea_manager": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"sleep": {
|
"sleep": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
@@ -191,9 +83,6 @@ DEVICE_MAPPING = {
|
|||||||
"shower": {
|
"shower": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
"scroll_hot": {
|
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
|
||||||
},
|
|
||||||
"fast_hot_power": {
|
"fast_hot_power": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
@@ -206,54 +95,12 @@ DEVICE_MAPPING = {
|
|||||||
"water_flow": {
|
"water_flow": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"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": {
|
"bottom_heat": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"device_class": SwitchDeviceClass.SWITCH,
|
||||||
},
|
},
|
||||||
"top_heat": {
|
"top_heat": {
|
||||||
"device_class": SwitchDeviceClass.SWITCH,
|
"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: {
|
Platform.SELECT: {
|
||||||
"mode": {
|
"mode": {
|
||||||
@@ -365,22 +212,11 @@ DEVICE_MAPPING = {
|
|||||||
"unit_of_measurement": UnitOfTime.MINUTES,
|
"unit_of_measurement": UnitOfTime.MINUTES,
|
||||||
"state_class": SensorStateClass.MEASUREMENT
|
"state_class": SensorStateClass.MEASUREMENT
|
||||||
},
|
},
|
||||||
"version": {
|
|
||||||
"device_class": SensorDeviceClass.ENUM
|
|
||||||
},
|
|
||||||
"tds_value": {
|
"tds_value": {
|
||||||
"device_class": SensorDeviceClass.WATER,
|
"device_class": SensorDeviceClass.WATER,
|
||||||
"unit_of_measurement": "ppm",
|
"unit_of_measurement": "ppm",
|
||||||
"state_class": SensorStateClass.MEASUREMENT
|
"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": {
|
"heat_water_level": {
|
||||||
"device_class": SensorDeviceClass.WATER,
|
"device_class": SensorDeviceClass.WATER,
|
||||||
"unit_of_measurement": "%",
|
"unit_of_measurement": "%",
|
||||||
|
@@ -5,7 +5,6 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .core.logger import MideaLogger
|
|
||||||
from .midea_entity import MideaEntity
|
from .midea_entity import MideaEntity
|
||||||
from . import load_device_config
|
from . import load_device_config
|
||||||
|
|
||||||
|
@@ -1,14 +1,23 @@
|
|||||||
from homeassistant.components.water_heater import WaterHeaterEntity, WaterHeaterEntityFeature
|
from homeassistant.components.water_heater import WaterHeaterEntity, WaterHeaterEntityFeature
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
Platform,
|
Platform,
|
||||||
ATTR_TEMPERATURE
|
ATTR_TEMPERATURE
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .midea_entity import MideaEntity
|
from .midea_entity import MideaEntity
|
||||||
from . import load_device_config
|
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)
|
account_bucket = hass.data.get(DOMAIN, {}).get("accounts", {}).get(config_entry.entry_id)
|
||||||
if not account_bucket:
|
if not account_bucket:
|
||||||
async_add_entities([])
|
async_add_entities([])
|
||||||
@@ -51,30 +60,6 @@ class MideaWaterHeaterEntityEntity(MideaEntity, WaterHeaterEntity):
|
|||||||
self._manufacturer = manufacturer
|
self._manufacturer = manufacturer
|
||||||
self._rationale = rationale
|
self._rationale = rationale
|
||||||
self._config = config
|
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_power = self._config.get("power")
|
||||||
self._key_operation_list = self._config.get("operation_list")
|
self._key_operation_list = self._config.get("operation_list")
|
||||||
self._key_min_temp = self._config.get("min_temp")
|
self._key_min_temp = self._config.get("min_temp")
|
||||||
@@ -167,9 +152,3 @@ class MideaWaterHeaterEntityEntity(MideaEntity, WaterHeaterEntity):
|
|||||||
if new_status:
|
if new_status:
|
||||||
await self.async_set_attributes(new_status)
|
await self.async_set_attributes(new_status)
|
||||||
|
|
||||||
def update_state(self, status):
|
|
||||||
try:
|
|
||||||
self.schedule_update_ha_state()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user