Use HVACAction in zha sensors (#70769)

This commit is contained in:
epenet 2022-04-26 11:26:59 +02:00 committed by GitHub
parent 09350d350d
commit c44b7cc4c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,13 +5,7 @@ import functools
import numbers
from typing import Any
from homeassistant.components.climate.const import (
CURRENT_HVAC_COOL,
CURRENT_HVAC_FAN,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF,
)
from homeassistant.components.climate.const import HVACAction
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
@ -631,7 +625,7 @@ class ThermostatHVACAction(Sensor, id_suffix="hvac_action"):
return self._pi_demand_action
@property
def _rm_rs_action(self) -> str | None:
def _rm_rs_action(self) -> HVACAction | None:
"""Return the current HVAC action based on running mode and running state."""
if (running_state := self._channel.running_state) is None:
@ -642,14 +636,14 @@ class ThermostatHVACAction(Sensor, id_suffix="hvac_action"):
| self._channel.RunningState.Heat_2nd_Stage_On
)
if running_state & rs_heat:
return CURRENT_HVAC_HEAT
return HVACAction.HEATING
rs_cool = (
self._channel.RunningState.Cool_State_On
| self._channel.RunningState.Cool_2nd_Stage_On
)
if running_state & rs_cool:
return CURRENT_HVAC_COOL
return HVACAction.COOLING
running_state = self._channel.running_state
if running_state and running_state & (
@ -657,30 +651,30 @@ class ThermostatHVACAction(Sensor, id_suffix="hvac_action"):
| self._channel.RunningState.Fan_2nd_Stage_On
| self._channel.RunningState.Fan_3rd_Stage_On
):
return CURRENT_HVAC_FAN
return HVACAction.FAN
running_state = self._channel.running_state
if running_state and running_state & self._channel.RunningState.Idle:
return CURRENT_HVAC_IDLE
return HVACAction.IDLE
if self._channel.system_mode != self._channel.SystemMode.Off:
return CURRENT_HVAC_IDLE
return CURRENT_HVAC_OFF
return HVACAction.IDLE
return HVACAction.OFF
@property
def _pi_demand_action(self) -> str | None:
def _pi_demand_action(self) -> HVACAction:
"""Return the current HVAC action based on pi_demands."""
heating_demand = self._channel.pi_heating_demand
if heating_demand is not None and heating_demand > 0:
return CURRENT_HVAC_HEAT
return HVACAction.HEATING
cooling_demand = self._channel.pi_cooling_demand
if cooling_demand is not None and cooling_demand > 0:
return CURRENT_HVAC_COOL
return HVACAction.COOLING
if self._channel.system_mode != self._channel.SystemMode.Off:
return CURRENT_HVAC_IDLE
return CURRENT_HVAC_OFF
return HVACAction.IDLE
return HVACAction.OFF
@callback
def async_set_state(self, *args, **kwargs) -> None:
@ -697,14 +691,14 @@ class SinopeHVACAction(ThermostatHVACAction):
"""Sinope Thermostat HVAC action sensor."""
@property
def _rm_rs_action(self) -> str | None:
def _rm_rs_action(self) -> HVACAction:
"""Return the current HVAC action based on running mode and running state."""
running_mode = self._channel.running_mode
if running_mode == self._channel.RunningMode.Heat:
return CURRENT_HVAC_HEAT
return HVACAction.HEATING
if running_mode == self._channel.RunningMode.Cool:
return CURRENT_HVAC_COOL
return HVACAction.COOLING
running_state = self._channel.running_state
if running_state and running_state & (
@ -712,13 +706,13 @@ class SinopeHVACAction(ThermostatHVACAction):
| self._channel.RunningState.Fan_2nd_Stage_On
| self._channel.RunningState.Fan_3rd_Stage_On
):
return CURRENT_HVAC_FAN
return HVACAction.FAN
if (
self._channel.system_mode != self._channel.SystemMode.Off
and running_mode == self._channel.SystemMode.Off
):
return CURRENT_HVAC_IDLE
return CURRENT_HVAC_OFF
return HVACAction.IDLE
return HVACAction.OFF
@MULTI_MATCH(channel_names=CHANNEL_BASIC)