1 """Support for ZhongHong HVAC Controller."""
3 from __future__
import annotations
8 import voluptuous
as vol
9 from zhong_hong_hvac.hub
import ZhongHongGateway
10 from zhong_hong_hvac.hvac
import HVAC
as ZhongHongHVAC
14 PLATFORM_SCHEMA
as CLIMATE_PLATFORM_SCHEMA,
23 EVENT_HOMEASSISTANT_STOP,
29 async_dispatcher_connect,
30 async_dispatcher_send,
35 _LOGGER = logging.getLogger(__name__)
37 CONF_GATEWAY_ADDRRESS =
"gateway_address"
40 DEFAULT_GATEWAY_ADDRRESS = 1
42 SIGNAL_DEVICE_ADDED =
"zhong_hong_device_added"
43 SIGNAL_ZHONG_HONG_HUB_START =
"zhong_hong_hub_start"
45 PLATFORM_SCHEMA = CLIMATE_PLATFORM_SCHEMA.extend(
47 vol.Required(CONF_HOST): cv.string,
48 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
50 CONF_GATEWAY_ADDRRESS, default=DEFAULT_GATEWAY_ADDRRESS
55 ZHONG_HONG_MODE_COOL =
"cool"
56 ZHONG_HONG_MODE_HEAT =
"heat"
57 ZHONG_HONG_MODE_DRY =
"dry"
58 ZHONG_HONG_MODE_FAN_ONLY =
"fan_only"
62 ZHONG_HONG_MODE_COOL: HVACMode.COOL,
63 ZHONG_HONG_MODE_HEAT: HVACMode.HEAT,
64 ZHONG_HONG_MODE_DRY: HVACMode.DRY,
65 ZHONG_HONG_MODE_FAN_ONLY: HVACMode.FAN_ONLY,
72 add_entities: AddEntitiesCallback,
73 discovery_info: DiscoveryInfoType |
None =
None,
75 """Set up the ZhongHong HVAC platform."""
77 host = config.get(CONF_HOST)
78 port = config.get(CONF_PORT)
79 gw_addr = config.get(CONF_GATEWAY_ADDRRESS)
80 hub = ZhongHongGateway(host, port, gw_addr)
83 for (addr_out, addr_in)
in hub.discovery_ac()
86 _LOGGER.debug(
"We got %s zhong_hong climate devices", len(devices))
88 hub_is_initialized =
False
91 """Start the hub socket and query status of all devices."""
93 hub.query_all_status()
96 """Start hub socket after all climate entity is set up."""
97 nonlocal hub_is_initialized
98 if not all(device.is_initialized
for device
in devices):
101 if hub_is_initialized:
104 _LOGGER.debug(
"zhong_hong hub start listen event")
105 await hass.async_add_executor_job(_start_hub)
106 hub_is_initialized =
True
113 def stop_listen(event):
114 """Stop ZhongHongHub socket."""
117 hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_listen)
121 """Representation of a ZhongHong controller support HVAC."""
130 _attr_should_poll =
False
131 _attr_supported_features = (
132 ClimateEntityFeature.TARGET_TEMPERATURE
133 | ClimateEntityFeature.FAN_MODE
134 | ClimateEntityFeature.TURN_OFF
135 | ClimateEntityFeature.TURN_ON
137 _attr_temperature_unit = UnitOfTemperature.CELSIUS
138 _enable_turn_on_off_backwards_compatibility =
False
141 """Set up the ZhongHong climate devices."""
143 self.
_device_device = ZhongHongHVAC(hub, addr_out, addr_in)
152 """Register callbacks."""
158 """Handle state update."""
159 _LOGGER.debug(
"async update ha state")
160 if self.
_device_device.current_operation:
162 self.
_device_device.current_operation.lower()
164 if self.
_device_device.current_temperature:
166 if self.
_device_device.current_fan_mode:
168 if self.
_device_device.target_temperature:
174 """Return the name of the thermostat, if any."""
179 """Return the unique ID of the HVAC."""
180 return f
"zhong_hong_hvac_{self._device.addr_out}_{self._device.addr_in}"
184 """Return current operation ie. heat, cool, idle."""
191 """Return the current temperature."""
196 """Return the temperature we try to reach."""
201 """Return the supported step of target temperature."""
206 """Return true if on."""
207 return self.
_device_device.is_on
211 """Return the fan setting."""
216 """Return the list of available fan modes."""
217 return self.
_device_device.fan_list
221 """Return the minimum temperature."""
222 return self.
_device_device.min_temp
226 """Return the maximum temperature."""
227 return self.
_device_device.max_temp
238 """Set new target temperature."""
239 if (temperature := kwargs.get(ATTR_TEMPERATURE))
is not None:
242 if (operation_mode := kwargs.get(ATTR_HVAC_MODE))
is not None:
246 """Set new target operation mode."""
247 if hvac_mode == HVACMode.OFF:
252 if not self.
is_onis_on:
255 self.
_device_device.set_operation_mode(hvac_mode.upper())
258 """Set new target fan mode."""
None set_hvac_mode(self, HVACMode hvac_mode)
None set_fan_mode(self, str fan_mode)
def target_temperature(self)
None set_temperature(self, **Any kwargs)
None set_hvac_mode(self, HVACMode hvac_mode)
def __init__(self, hub, addr_out, addr_in)
def current_temperature(self)
def target_temperature_step(self)
None async_added_to_hass(self)
def _after_update(self, climate)
None schedule_update_ha_state(self, bool force_refresh=False)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)