mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Use climate enums in iaqualink (#70671)
This commit is contained in:
parent
add7103d55
commit
cf8f2132a2
@ -11,15 +11,19 @@ from iaqualink.const import (
|
|||||||
)
|
)
|
||||||
from iaqualink.device import AqualinkHeater, AqualinkPump, AqualinkSensor, AqualinkState
|
from iaqualink.device import AqualinkHeater, AqualinkPump, AqualinkSensor, AqualinkState
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.components.climate.const import DOMAIN, HVAC_MODE_HEAT, HVAC_MODE_OFF
|
from homeassistant.components.climate.const import (
|
||||||
|
DOMAIN as CLIMATE_DOMAIN,
|
||||||
|
ClimateEntityFeature,
|
||||||
|
HVACMode,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AqualinkEntity, refresh_system
|
from . import AqualinkEntity, refresh_system
|
||||||
from .const import CLIMATE_SUPPORTED_MODES, DOMAIN as AQUALINK_DOMAIN
|
from .const import DOMAIN as AQUALINK_DOMAIN
|
||||||
from .utils import await_or_reraise
|
from .utils import await_or_reraise
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -34,7 +38,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up discovered switches."""
|
"""Set up discovered switches."""
|
||||||
devs = []
|
devs = []
|
||||||
for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]:
|
for dev in hass.data[AQUALINK_DOMAIN][CLIMATE_DOMAIN]:
|
||||||
devs.append(HassAqualinkThermostat(dev))
|
devs.append(HassAqualinkThermostat(dev))
|
||||||
async_add_entities(devs, True)
|
async_add_entities(devs, True)
|
||||||
|
|
||||||
@ -42,6 +46,7 @@ async def async_setup_entry(
|
|||||||
class HassAqualinkThermostat(AqualinkEntity, ClimateEntity):
|
class HassAqualinkThermostat(AqualinkEntity, ClimateEntity):
|
||||||
"""Representation of a thermostat."""
|
"""Representation of a thermostat."""
|
||||||
|
|
||||||
|
_attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF]
|
||||||
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -49,11 +54,6 @@ class HassAqualinkThermostat(AqualinkEntity, ClimateEntity):
|
|||||||
"""Return the name of the thermostat."""
|
"""Return the name of the thermostat."""
|
||||||
return self.dev.label.split(" ")[0]
|
return self.dev.label.split(" ")[0]
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self) -> list[str]:
|
|
||||||
"""Return the list of supported HVAC modes."""
|
|
||||||
return CLIMATE_SUPPORTED_MODES
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pump(self) -> AqualinkPump:
|
def pump(self) -> AqualinkPump:
|
||||||
"""Return the pump device for the current thermostat."""
|
"""Return the pump device for the current thermostat."""
|
||||||
@ -61,19 +61,19 @@ class HassAqualinkThermostat(AqualinkEntity, ClimateEntity):
|
|||||||
return self.dev.system.devices[pump]
|
return self.dev.system.devices[pump]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> str:
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""Return the current HVAC mode."""
|
"""Return the current HVAC mode."""
|
||||||
state = AqualinkState(self.heater.state)
|
state = AqualinkState(self.heater.state)
|
||||||
if state == AqualinkState.ON:
|
if state == AqualinkState.ON:
|
||||||
return HVAC_MODE_HEAT
|
return HVACMode.HEAT
|
||||||
return HVAC_MODE_OFF
|
return HVACMode.OFF
|
||||||
|
|
||||||
@refresh_system
|
@refresh_system
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Turn the underlying heater switch on or off."""
|
"""Turn the underlying heater switch on or off."""
|
||||||
if hvac_mode == HVAC_MODE_HEAT:
|
if hvac_mode == HVACMode.HEAT:
|
||||||
await await_or_reraise(self.heater.turn_on())
|
await await_or_reraise(self.heater.turn_on())
|
||||||
elif hvac_mode == HVAC_MODE_OFF:
|
elif hvac_mode == HVACMode.OFF:
|
||||||
await await_or_reraise(self.heater.turn_off())
|
await await_or_reraise(self.heater.turn_off())
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning("Unknown operation mode: %s", hvac_mode)
|
_LOGGER.warning("Unknown operation mode: %s", hvac_mode)
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
"""Constants for the the iaqualink component."""
|
"""Constants for the the iaqualink component."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components.climate.const import HVAC_MODE_HEAT, HVAC_MODE_OFF
|
|
||||||
|
|
||||||
DOMAIN = "iaqualink"
|
DOMAIN = "iaqualink"
|
||||||
CLIMATE_SUPPORTED_MODES = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
|
||||||
UPDATE_INTERVAL = timedelta(seconds=30)
|
UPDATE_INTERVAL = timedelta(seconds=30)
|
||||||
|
Loading…
Reference in New Issue
Block a user