Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
33 changes: 27 additions & 6 deletions homeassistant/components/zhong_hong/climate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Support for ZhongHong HVAC Controller."""

from datetime import timedelta
import logging
from typing import Any, override

Expand Down Expand Up @@ -40,6 +41,7 @@

DEFAULT_PORT = 9999
DEFAULT_GATEWAY_ADDRRESS = 1
SCAN_INTERVAL = timedelta(seconds=60)

SIGNAL_DEVICE_ADDED = "zhong_hong_device_added"
SIGNAL_ZHONG_HONG_HUB_START = "zhong_hong_hub_start"
Expand Down Expand Up @@ -140,7 +142,7 @@ class ZhongHongClimate(ClimateEntity):
HVACMode.FAN_ONLY,
HVACMode.OFF,
]
_attr_should_poll = False
_attr_should_poll = True
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
Expand Down Expand Up @@ -183,6 +185,17 @@ def _after_update(self, climate):
self._attr_target_temperature = self._device.target_temperature
self.schedule_update_ha_state()

def update(self) -> None:
"""Poll the gateway for fresh status when the connection is healthy."""
if self._hub.connected:
self._device.update()

@property
@override
def available(self) -> bool:
"""Return False when the gateway connection is unhealthy."""
return self._hub.connected

@property
@override
def hvac_mode(self) -> HVACMode:
Expand Down Expand Up @@ -227,18 +240,23 @@ def max_temp(self) -> float:
@override
def turn_on(self) -> None:
"""Turn on ac."""
return self._device.turn_on()
if not self._device.turn_on():
_LOGGER.warning("%s: failed to send turn-on command", self.entity_id)
Comment on lines +243 to +244

@override
def turn_off(self) -> None:
"""Turn off ac."""
return self._device.turn_off()
if not self._device.turn_off():
_LOGGER.warning("%s: failed to send turn-off command", self.entity_id)

@override
def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is not None:
self._device.set_temperature(temperature)
if not self._device.set_temperature(temperature):
_LOGGER.warning(
"%s: failed to send temperature command", self.entity_id
)

if (operation_mode := kwargs.get(ATTR_HVAC_MODE)) is not None:
self.set_hvac_mode(operation_mode)
Expand All @@ -254,12 +272,15 @@ def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
if not self.is_on:
self.turn_on()

self._device.set_operation_mode(hvac_mode.upper())
if not self._device.set_operation_mode(hvac_mode.upper()):
_LOGGER.warning("%s: failed to send mode command", self.entity_id)

@override
def set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode."""
mapped_mode = FAN_MODE_MAP.get(fan_mode)
if not mapped_mode:
_LOGGER.error("Unsupported fan mode: %s", fan_mode)
self._device.set_fan_mode(mapped_mode)
return
if not self._device.set_fan_mode(mapped_mode):
_LOGGER.warning("%s: failed to send fan command", self.entity_id)
2 changes: 1 addition & 1 deletion homeassistant/components/zhong_hong/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"iot_class": "local_push",
"loggers": ["zhong_hong_hvac"],
"quality_scale": "legacy",
"requirements": ["zhong-hong-hvac==1.0.13"]
"requirements": ["zhong-hong-hvac==1.0.15"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading