mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
Use climate enums in netatmo (#70724)
This commit is contained in:
parent
09393d6f64
commit
073833fcec
@ -7,16 +7,14 @@ from typing import Any
|
||||
import pyatmo
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
DEFAULT_MIN_TEMP,
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
PRESET_AWAY,
|
||||
PRESET_BOOST,
|
||||
ClimateEntityFeature,
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
@ -96,17 +94,17 @@ NETATMO_MAP_PRESET = {
|
||||
}
|
||||
|
||||
HVAC_MAP_NETATMO = {
|
||||
PRESET_SCHEDULE: HVAC_MODE_AUTO,
|
||||
STATE_NETATMO_HG: HVAC_MODE_AUTO,
|
||||
PRESET_FROST_GUARD: HVAC_MODE_AUTO,
|
||||
PRESET_BOOST: HVAC_MODE_HEAT,
|
||||
STATE_NETATMO_OFF: HVAC_MODE_OFF,
|
||||
STATE_NETATMO_MANUAL: HVAC_MODE_AUTO,
|
||||
PRESET_MANUAL: HVAC_MODE_AUTO,
|
||||
STATE_NETATMO_AWAY: HVAC_MODE_AUTO,
|
||||
PRESET_SCHEDULE: HVACMode.AUTO,
|
||||
STATE_NETATMO_HG: HVACMode.AUTO,
|
||||
PRESET_FROST_GUARD: HVACMode.AUTO,
|
||||
PRESET_BOOST: HVACMode.HEAT,
|
||||
STATE_NETATMO_OFF: HVACMode.OFF,
|
||||
STATE_NETATMO_MANUAL: HVACMode.AUTO,
|
||||
PRESET_MANUAL: HVACMode.AUTO,
|
||||
STATE_NETATMO_AWAY: HVACMode.AUTO,
|
||||
}
|
||||
|
||||
CURRENT_HVAC_MAP_NETATMO = {True: CURRENT_HVAC_HEAT, False: CURRENT_HVAC_IDLE}
|
||||
CURRENT_HVAC_MAP_NETATMO = {True: HVACAction.HEATING, False: HVACAction.IDLE}
|
||||
|
||||
DEFAULT_MAX_TEMP = 30
|
||||
|
||||
@ -168,7 +166,7 @@ async def async_setup_entry(
|
||||
class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||
"""Representation a Netatmo thermostat."""
|
||||
|
||||
_attr_hvac_mode = HVAC_MODE_AUTO
|
||||
_attr_hvac_mode = HVACMode.AUTO
|
||||
_attr_max_temp = DEFAULT_MAX_TEMP
|
||||
_attr_preset_modes = SUPPORT_PRESET
|
||||
_attr_supported_features = (
|
||||
@ -221,9 +219,9 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||
self._boilerstatus: bool | None = None
|
||||
self._selected_schedule = None
|
||||
|
||||
self._attr_hvac_modes = [HVAC_MODE_AUTO, HVAC_MODE_HEAT]
|
||||
self._attr_hvac_modes = [HVACMode.AUTO, HVACMode.HEAT]
|
||||
if self._model == NA_THERM:
|
||||
self._attr_hvac_modes.append(HVAC_MODE_OFF)
|
||||
self._attr_hvac_modes.append(HVACMode.OFF)
|
||||
|
||||
self._attr_unique_id = f"{self._room.entity_id}-{self._model}"
|
||||
|
||||
@ -307,20 +305,20 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||
and self._room.entity_id == room["id"]
|
||||
):
|
||||
if room["therm_setpoint_mode"] == STATE_NETATMO_OFF:
|
||||
self._attr_hvac_mode = HVAC_MODE_OFF
|
||||
self._attr_hvac_mode = HVACMode.OFF
|
||||
self._attr_preset_mode = STATE_NETATMO_OFF
|
||||
self._attr_target_temperature = 0
|
||||
elif room["therm_setpoint_mode"] == STATE_NETATMO_MAX:
|
||||
self._attr_hvac_mode = HVAC_MODE_HEAT
|
||||
self._attr_hvac_mode = HVACMode.HEAT
|
||||
self._attr_preset_mode = PRESET_MAP_NETATMO[PRESET_BOOST]
|
||||
self._attr_target_temperature = DEFAULT_MAX_TEMP
|
||||
elif room["therm_setpoint_mode"] == STATE_NETATMO_MANUAL:
|
||||
self._attr_hvac_mode = HVAC_MODE_HEAT
|
||||
self._attr_hvac_mode = HVACMode.HEAT
|
||||
self._attr_target_temperature = room["therm_setpoint_temperature"]
|
||||
else:
|
||||
self._attr_target_temperature = room["therm_setpoint_temperature"]
|
||||
if self._attr_target_temperature == DEFAULT_MAX_TEMP:
|
||||
self._attr_hvac_mode = HVAC_MODE_HEAT
|
||||
self._attr_hvac_mode = HVACMode.HEAT
|
||||
self.async_write_ha_state()
|
||||
return
|
||||
|
||||
@ -333,7 +331,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||
return
|
||||
|
||||
@property
|
||||
def hvac_action(self) -> str | None:
|
||||
def hvac_action(self) -> HVACAction:
|
||||
"""Return the current running hvac operation if supported."""
|
||||
if self._model == NA_THERM and self._boilerstatus is not None:
|
||||
return CURRENT_HVAC_MAP_NETATMO[self._boilerstatus]
|
||||
@ -341,23 +339,23 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||
if (
|
||||
heating_req := getattr(self._room, "heating_power_request", 0)
|
||||
) is not None and heating_req > 0:
|
||||
return CURRENT_HVAC_HEAT
|
||||
return CURRENT_HVAC_IDLE
|
||||
return HVACAction.HEATING
|
||||
return HVACAction.IDLE
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set new target hvac mode."""
|
||||
if hvac_mode == HVAC_MODE_OFF:
|
||||
if hvac_mode == HVACMode.OFF:
|
||||
await self.async_turn_off()
|
||||
elif hvac_mode == HVAC_MODE_AUTO:
|
||||
if self.hvac_mode == HVAC_MODE_OFF:
|
||||
elif hvac_mode == HVACMode.AUTO:
|
||||
if self.hvac_mode == HVACMode.OFF:
|
||||
await self.async_turn_on()
|
||||
await self.async_set_preset_mode(PRESET_SCHEDULE)
|
||||
elif hvac_mode == HVAC_MODE_HEAT:
|
||||
elif hvac_mode == HVACMode.HEAT:
|
||||
await self.async_set_preset_mode(PRESET_BOOST)
|
||||
|
||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||
"""Set new preset mode."""
|
||||
if self.hvac_mode == HVAC_MODE_OFF:
|
||||
if self.hvac_mode == HVACMode.OFF:
|
||||
await self.async_turn_on()
|
||||
|
||||
if self.target_temperature == 0:
|
||||
@ -369,7 +367,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||
if (
|
||||
preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX)
|
||||
and self._model == NA_VALVE
|
||||
and self.hvac_mode == HVAC_MODE_HEAT
|
||||
and self.hvac_mode == HVACMode.HEAT
|
||||
):
|
||||
await self._climate_state.async_set_room_thermpoint(
|
||||
self._room.entity_id,
|
||||
@ -385,7 +383,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||
)
|
||||
elif (
|
||||
preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX)
|
||||
and self.hvac_mode == HVAC_MODE_HEAT
|
||||
and self.hvac_mode == HVACMode.HEAT
|
||||
):
|
||||
await self._climate_state.async_set_room_thermpoint(
|
||||
self._room.entity_id, STATE_NETATMO_HOME
|
||||
@ -421,7 +419,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||
STATE_NETATMO_MANUAL,
|
||||
DEFAULT_MIN_TEMP,
|
||||
)
|
||||
elif self.hvac_mode != HVAC_MODE_OFF:
|
||||
elif self.hvac_mode != HVACMode.OFF:
|
||||
await self._climate_state.async_set_room_thermpoint(
|
||||
self._room.entity_id, STATE_NETATMO_OFF
|
||||
)
|
||||
|
@ -12,11 +12,9 @@ from homeassistant.components.climate import (
|
||||
from homeassistant.components.climate.const import (
|
||||
ATTR_HVAC_MODE,
|
||||
ATTR_PRESET_MODE,
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
PRESET_AWAY,
|
||||
PRESET_BOOST,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.components.netatmo.climate import PRESET_FROST_GUARD, PRESET_SCHEDULE
|
||||
from homeassistant.components.netatmo.const import (
|
||||
@ -93,7 +91,7 @@ async def test_webhook_event_handling_thermostats(hass, config_entry, netatmo_au
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{ATTR_ENTITY_ID: climate_entity_livingroom, ATTR_HVAC_MODE: HVAC_MODE_HEAT},
|
||||
{ATTR_ENTITY_ID: climate_entity_livingroom, ATTR_HVAC_MODE: HVACMode.HEAT},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -131,7 +129,7 @@ async def test_webhook_event_handling_thermostats(hass, config_entry, netatmo_au
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{ATTR_ENTITY_ID: climate_entity_livingroom, ATTR_HVAC_MODE: HVAC_MODE_OFF},
|
||||
{ATTR_ENTITY_ID: climate_entity_livingroom, ATTR_HVAC_MODE: HVACMode.OFF},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -166,7 +164,7 @@ async def test_webhook_event_handling_thermostats(hass, config_entry, netatmo_au
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{ATTR_ENTITY_ID: climate_entity_livingroom, ATTR_HVAC_MODE: HVAC_MODE_AUTO},
|
||||
{ATTR_ENTITY_ID: climate_entity_livingroom, ATTR_HVAC_MODE: HVACMode.AUTO},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
Loading…
Reference in New Issue
Block a user