mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-09-28 02:32:40 +00:00
v0.0.4
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
from homeassistant.components.climate import *
|
||||
from homeassistant.components.climate import (
|
||||
ClimateEntity,
|
||||
ClimateEntityFeature,
|
||||
HVACMode,
|
||||
ATTR_HVAC_MODE,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
Platform,
|
||||
CONF_DEVICE_ID,
|
||||
CONF_ENTITIES,
|
||||
CONF_DEVICE,
|
||||
ATTR_TEMPERATURE
|
||||
)
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
DEVICES
|
||||
)
|
||||
from .core.logger import MideaLogger
|
||||
from .midea_entities import MideaEntity, Rationale
|
||||
|
||||
|
||||
@@ -17,34 +23,31 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
device_id = config_entry.data.get(CONF_DEVICE_ID)
|
||||
device = hass.data[DOMAIN][DEVICES][device_id].get(CONF_DEVICE)
|
||||
manufacturer = hass.data[DOMAIN][DEVICES][device_id].get("manufacturer")
|
||||
rationale = hass.data[DOMAIN][DEVICES][device_id].get("rationale")
|
||||
entities = hass.data[DOMAIN][DEVICES][device_id].get(CONF_ENTITIES).get(Platform.CLIMATE)
|
||||
devs = []
|
||||
if entities is not None:
|
||||
for entity_key, config in entities.items():
|
||||
devs.append(MideaClimateEntity(device, manufacturer, entity_key, config))
|
||||
devs.append(MideaClimateEntity(device, manufacturer, rationale, entity_key, config))
|
||||
async_add_entities(devs)
|
||||
|
||||
|
||||
class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
def __init__(self, device, manufacturer, entity_key, config):
|
||||
super().__init__(device, manufacturer, entity_key, config)
|
||||
def __init__(self, device, manufacturer, rationale, entity_key, config):
|
||||
super().__init__(device, manufacturer, rationale, entity_key, config)
|
||||
self._key_power = self._config.get("power")
|
||||
self._key_hvac_modes = self._config.get("hvac_modes")
|
||||
self._key_preset_modes = self._config.get("preset_modes")
|
||||
self._key_aux_heat = self._config.get("aux_heat")
|
||||
self._key_swing_modes = self._config.get("swing_modes")
|
||||
self._key_fan_modes = self._config.get("fan_modes")
|
||||
self._key_current_temperature_low = self._config.get("current_temperature_low")
|
||||
self._key_min_temp = self._config.get("min_temp")
|
||||
self._key_max_temp = self._config.get("max_temp")
|
||||
self._key_current_temperature = self._config.get("current_temperature")
|
||||
self._key_target_temperature = self._config.get("target_temperature")
|
||||
self._attr_temperature_unit = self._config.get("temperature_unit")
|
||||
self._attr_precision = self._config.get("precision")
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self.hvac_mode
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
features = 0
|
||||
@@ -62,7 +65,7 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
return self._device.get_attribute("indoor_temperature")
|
||||
return self._device.get_attribute(self._key_current_temperature)
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
@@ -103,7 +106,7 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
|
||||
@property
|
||||
def preset_mode(self):
|
||||
return self.get_mode(self._key_preset_modes)
|
||||
return self._dict_get_selected(self._key_preset_modes)
|
||||
|
||||
@property
|
||||
def fan_modes(self):
|
||||
@@ -111,7 +114,7 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
|
||||
@property
|
||||
def fan_mode(self):
|
||||
return self.get_mode(self._key_fan_modes, Rationale.LESS)
|
||||
return self._dict_get_selected(self._key_fan_modes, Rationale.LESS)
|
||||
|
||||
@property
|
||||
def swing_modes(self):
|
||||
@@ -119,7 +122,7 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
|
||||
@property
|
||||
def swing_mode(self):
|
||||
return self.get_mode(self._key_swing_modes)
|
||||
return self._dict_get_selected(self._key_swing_modes)
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
@@ -127,7 +130,7 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
|
||||
@property
|
||||
def hvac_mode(self):
|
||||
return self.get_mode(self._key_hvac_modes)
|
||||
return self._dict_get_selected(self._key_hvac_modes)
|
||||
|
||||
@property
|
||||
def hvac_modes(self):
|
||||
@@ -135,13 +138,13 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
|
||||
@property
|
||||
def is_aux_heat(self):
|
||||
return self._device.get_attribute(self._key_aux_heat) == "on"
|
||||
return self._get_status_on_off(self._key_aux_heat)
|
||||
|
||||
def turn_on(self):
|
||||
self._device.set_attribute(attribute=self._key_power, value="on")
|
||||
self._set_status_on_off(self._key_power, True)
|
||||
|
||||
def turn_off(self):
|
||||
self._device.set_attribute(attribute=self._key_power, value="off")
|
||||
self._set_status_on_off(self._key_power, False)
|
||||
|
||||
def set_temperature(self, **kwargs):
|
||||
if ATTR_TEMPERATURE not in kwargs:
|
||||
@@ -159,16 +162,15 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
new_status[self._key_target_temperature[1]] = temp_dec
|
||||
else:
|
||||
new_status[self._key_target_temperature] = temperature
|
||||
MideaLogger.error(new_status)
|
||||
self._device.set_attributes(new_status)
|
||||
|
||||
def set_fan_mode(self, fan_mode: str):
|
||||
new_statis = self._key_fan_modes.get(fan_mode)
|
||||
self._device.set_attributes(new_statis)
|
||||
new_status = self._key_fan_modes.get(fan_mode)
|
||||
self._device.set_attributes(new_status)
|
||||
|
||||
def set_preset_mode(self, preset_mode: str):
|
||||
new_statis = self._key_preset_modes.get(preset_mode)
|
||||
self._device.set_attributes(new_statis)
|
||||
new_status = self._key_preset_modes.get(preset_mode)
|
||||
self._device.set_attributes(new_status)
|
||||
|
||||
def set_hvac_mode(self, hvac_mode: str):
|
||||
new_status = self._key_hvac_modes.get(hvac_mode)
|
||||
@@ -179,10 +181,10 @@ class MideaClimateEntity(MideaEntity, ClimateEntity):
|
||||
self._device.set_attributes(new_status)
|
||||
|
||||
def turn_aux_heat_on(self) -> None:
|
||||
self._device.set_attribute(attr=self._key_aux_heat, value="on")
|
||||
self._set_status_on_off(self._key_aux_heat, True)
|
||||
|
||||
def turn_aux_heat_off(self) -> None:
|
||||
self._device.set_attribute(attr=self._key_aux_heat, value="off")
|
||||
self._set_status_on_off(self._key_aux_heat, False)
|
||||
|
||||
def update_state(self, status):
|
||||
try:
|
||||
|
Reference in New Issue
Block a user