Skip to content

Commit

Permalink
Code update after #1555
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Mar 24, 2024
1 parent da87daa commit e212d4a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
53 changes: 35 additions & 18 deletions custom_components/xiaomi_gateway3/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class XAqaraS2(XEntity, ClimateEntity):
_attr_hvac_mode = None
_attr_hvac_modes = [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT]
_attr_precision = PRECISION_WHOLE
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
)
_attr_temperature_unit = UnitOfTemperature.CELSIUS
# support only KTWKQ03ES for now
_attr_max_temp = 30
Expand All @@ -42,6 +44,9 @@ class XAqaraS2(XEntity, ClimateEntity):
_enabled = None
_mode = None

def on_init(self):
self.listen_attrs |= {"power", "current_temp", "hvac_mode", "target_temp"}

def set_state(self, data: dict):
self._enabled = data.get("power")
self._attr_current_temperature = data.get("current_temp")
Expand Down Expand Up @@ -109,22 +114,35 @@ async def async_set_hvac_mode(self, hvac_mode: str) -> None:
return
self.device.write(payload)

class ScdvbHAVC(XEntity, ClimateEntity):

class XScdvbHAVC(XEntity, ClimateEntity):
_attr_fan_mode = None
_attr_fan_modes = [FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO]
_attr_hvac_mode = None
_attr_hvac_modes = [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT, HVACMode.AUTO, HVACMode.DRY, HVACMode.FAN_ONLY]
_attr_hvac_modes = [
HVACMode.OFF,
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.AUTO,
HVACMode.DRY,
HVACMode.FAN_ONLY,
]
_attr_precision = PRECISION_WHOLE
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
)
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_max_temp = 32
_attr_min_temp = 16
_attr_target_temperature_step = 1

_enabled = None
_mode = None
@callback
def async_set_state(self, data: dict):

def on_init(self):
self.listen_attrs |= {"current_temp", "fan_mode", "hvac_mode", "target_temp"}

def set_state(self, data: dict):
if "climate" in data:
self._enabled = data["climate"]
if "hvac_mode" in data:
Expand All @@ -140,30 +158,29 @@ def async_set_state(self, data: dict):
return

self._attr_hvac_mode = self._mode if self._enabled else HVACMode.OFF
async def async_update(self):
await self.device_read(self.subscribed_attrs)

async def async_set_temperature(self, **kwargs) -> None:
if kwargs[ATTR_TEMPERATURE] == 0:
return
await self.device_send({"target_temp": kwargs[ATTR_TEMPERATURE]})
async def async_set_temperature(self, temperature: int, **kwargs) -> None:
if temperature:
self.device.write({"target_temp": temperature})

async def async_set_fan_mode(self, fan_mode: str) -> None:
if not self._enabled:
await self.device_send({"climate": True})
self.device.write({"climate": True})
self._attr_hvac_mode = self._mode
await self.device_send({"fan_mode": fan_mode})
self.device.write({"fan_mode": fan_mode})

async def async_set_hvac_mode(self, hvac_mode: str) -> None:
if hvac_mode == HVACMode.OFF:
await self.device_send({"climate": False})
self.device.write({"climate": False})
else:
if not self._enabled:
await self.device_send({"climate": True})
# better support HomeKit
self.device.write({"climate": True})
# better support HomeKit
if hvac_mode == HVACMode.AUTO:
hvac_mode = self._mode
await self.device_send({"hvac_mode": hvac_mode})
self.device.write({"hvac_mode": hvac_mode})


XEntity.NEW["climate.model.lumi.airrtc.tcpecn02"] = XAqaraS2
XEntity.NEW["climate.model.lumi.airrtc.agl001"] = XAqaraE1
XEntity.NEW["climate.model.14050"] = XScdvbHAVC
11 changes: 10 additions & 1 deletion custom_components/xiaomi_gateway3/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@
# https://github.com/AlexxIT/XiaomiGateway3/issues/101
"lumi.airrtc.tcpecn02": ["Aqara", "Thermostat S2 CN", "KTWKQ03ES"],
"spec": [
# BoolConv("power", mi="3.1.85", xiaomi="power_status"),
ClimateConv("climate", "climate", mi="14.2.85"),
BoolConv("power", mi="3.1.85"),
BaseConv("current_temp", mi="3.2.85"),
MapConv("hvac_mode", mi="14.8.85", map={0: "heat", 1: "cool", 15: "off"}),
MapConv("fan_mode", mi="14.10.85", map={0: "low", 1: "medium", 2: "high", 3: "auto"}),
Expand Down Expand Up @@ -3004,6 +3004,15 @@
BoolConv("natural_wind", "switch", mi="3.p.7"),
MapConv("fan_level", "select", mi="3.p.2", map={1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6"}),
]
}, {
14050: ["Scdvb", "Air Conditioner", "scdvb.aircondition.acm"],
"spec": [
BaseConv("climate", "climate", mi="2.p.1"),
MapConv("hvac_mode", mi="2.p.2", map={0: "cool", 1: "heat", 2: "fan_only", 3: "dry"}),
MapConv("fan_mode", mi="3.p.1", map={0: "auto", 1: "low", 2: "medium", 3: "high"}),
BaseConv("current_temp", mi="4.p.1"),
BaseConv("target_temp", mi="2.p.3"),
],
}, {
"default": "mesh", # default Mesh device
"spec": [
Expand Down

0 comments on commit e212d4a

Please sign in to comment.