Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix climate device init setup error and support Scdvb HAVC #1255

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions custom_components/xiaomi_gateway3/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
HVACMode.OFF: HVACAction.OFF,
HVACMode.COOL: HVACAction.COOLING,
HVACMode.HEAT: HVACAction.HEATING,
HVACMode.DRY: HVACAction.DRYING,
HVACMode.FAN_ONLY: HVACAction.FAN,
}


Expand All @@ -32,6 +34,8 @@ async def async_setup_entry(
def new_entity(gateway: XGateway, device: XDevice, conv: Converter) -> XEntity:
if conv.mi == "4.21.85":
return AqaraE1(gateway, device, conv)
if device.model == 14050:
return ScdvbHAVC(gateway, device, conv)
else:
return XiaomiClimate(gateway, device, conv)

Expand All @@ -46,26 +50,29 @@ class XiaomiClimate(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_RANGE | 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
_attr_min_temp = 17
_attr_target_temperature_step = 1
_enabled = None
_mode = None

@callback
def async_set_state(self, data: dict):
self._enabled = data.get("power")
self._attr_current_temperature = data.get("current_temp")
self._attr_fan_mode = data.get("fan_mode")
self._attr_hvac_mode = data.get("hvac_mode")
self._mode = data.get("hvac_mode")
# better support HomeKit
# https://github.com/AlexxIT/XiaomiGateway3/issues/707#issuecomment-1099109552
self._attr_hvac_action = ACTIONS.get(self._attr_hvac_mode)
# fix scenes with turned off climate
# https://github.com/AlexxIT/XiaomiGateway3/issues/101#issuecomment-757781988
self._attr_target_temperature = data.get("target_temp", 0)
self._attr_hvac_mode = self._mode if self._enabled else HVACMode.OFF

async def async_update(self):
await self.device_read(self.subscribed_attrs)
Expand Down Expand Up @@ -128,3 +135,59 @@ async def async_set_hvac_mode(self, hvac_mode: str) -> None:
else:
return
await self.device_send(payload)

class ScdvbHAVC(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_precision = PRECISION_WHOLE
_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):
if "climate" in data:
self._enabled = data["climate"]
if "hvac_mode" in data:
self._mode = data["hvac_mode"]
if "fan_mode" in data:
self._attr_fan_mode = data["fan_mode"]
if "current_temp" in data:
self._attr_current_temperature = data["current_temp"]
if "target_temp" in data:
self._attr_target_temperature = data["target_temp"]

if self._enabled is None or self._mode is None:
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_fan_mode(self, fan_mode: str) -> None:
if not self._enabled:
await self.device_send({"climate": True})
self._attr_hvac_mode = self._mode
await self.device_send({"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})
else:
if not self._enabled:
await self.device_send({"climate": True})
# better support HomeKit
if hvac_mode == HVACMode.AUTO:
hvac_mode = self._mode
await self.device_send({"hvac_mode": hvac_mode})
11 changes: 10 additions & 1 deletion custom_components/xiaomi_gateway3/core/converters/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,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"),
Converter("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={
Expand Down Expand Up @@ -3228,6 +3228,15 @@
0: "follow_switch", 1: "opposite_to_switch", 2: "off", 3: "on"
})
]
}, {
14050: ["Scdvb", "Air Conditioner", "scdvb.aircondition.acm"],
"spec": [
Converter("climate", "climate", mi="2.p.1"),
MapConv("hvac_mode", mi="2.p.2", map={0: "cool", 1: "heat", 2: "fan_only", 3: "dry"}, parent="climate"),
MapConv("fan_mode", mi="3.p.1", map={0: "auto", 1: "low", 2: "medium", 3: "high"}, parent="climate"),
Converter("current_temp", mi="4.p.1", parent="climate"),
Converter("target_temp", mi="2.p.3", parent="climate"),
],
}, {
"default": "mesh", # default Mesh device
"spec": [
Expand Down
Loading