mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00: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 pyatmo
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
DEFAULT_MIN_TEMP,
|
DEFAULT_MIN_TEMP,
|
||||||
HVAC_MODE_AUTO,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_BOOST,
|
PRESET_BOOST,
|
||||||
|
ClimateEntityFeature,
|
||||||
|
HVACAction,
|
||||||
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -96,17 +94,17 @@ NETATMO_MAP_PRESET = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HVAC_MAP_NETATMO = {
|
HVAC_MAP_NETATMO = {
|
||||||
PRESET_SCHEDULE: HVAC_MODE_AUTO,
|
PRESET_SCHEDULE: HVACMode.AUTO,
|
||||||
STATE_NETATMO_HG: HVAC_MODE_AUTO,
|
STATE_NETATMO_HG: HVACMode.AUTO,
|
||||||
PRESET_FROST_GUARD: HVAC_MODE_AUTO,
|
PRESET_FROST_GUARD: HVACMode.AUTO,
|
||||||
PRESET_BOOST: HVAC_MODE_HEAT,
|
PRESET_BOOST: HVACMode.HEAT,
|
||||||
STATE_NETATMO_OFF: HVAC_MODE_OFF,
|
STATE_NETATMO_OFF: HVACMode.OFF,
|
||||||
STATE_NETATMO_MANUAL: HVAC_MODE_AUTO,
|
STATE_NETATMO_MANUAL: HVACMode.AUTO,
|
||||||
PRESET_MANUAL: HVAC_MODE_AUTO,
|
PRESET_MANUAL: HVACMode.AUTO,
|
||||||
STATE_NETATMO_AWAY: HVAC_MODE_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
|
DEFAULT_MAX_TEMP = 30
|
||||||
|
|
||||||
@ -168,7 +166,7 @@ async def async_setup_entry(
|
|||||||
class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||||
"""Representation a Netatmo thermostat."""
|
"""Representation a Netatmo thermostat."""
|
||||||
|
|
||||||
_attr_hvac_mode = HVAC_MODE_AUTO
|
_attr_hvac_mode = HVACMode.AUTO
|
||||||
_attr_max_temp = DEFAULT_MAX_TEMP
|
_attr_max_temp = DEFAULT_MAX_TEMP
|
||||||
_attr_preset_modes = SUPPORT_PRESET
|
_attr_preset_modes = SUPPORT_PRESET
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
@ -221,9 +219,9 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
self._boilerstatus: bool | None = None
|
self._boilerstatus: bool | None = None
|
||||||
self._selected_schedule = 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:
|
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}"
|
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"]
|
and self._room.entity_id == room["id"]
|
||||||
):
|
):
|
||||||
if room["therm_setpoint_mode"] == STATE_NETATMO_OFF:
|
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_preset_mode = STATE_NETATMO_OFF
|
||||||
self._attr_target_temperature = 0
|
self._attr_target_temperature = 0
|
||||||
elif room["therm_setpoint_mode"] == STATE_NETATMO_MAX:
|
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_preset_mode = PRESET_MAP_NETATMO[PRESET_BOOST]
|
||||||
self._attr_target_temperature = DEFAULT_MAX_TEMP
|
self._attr_target_temperature = DEFAULT_MAX_TEMP
|
||||||
elif room["therm_setpoint_mode"] == STATE_NETATMO_MANUAL:
|
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"]
|
self._attr_target_temperature = room["therm_setpoint_temperature"]
|
||||||
else:
|
else:
|
||||||
self._attr_target_temperature = room["therm_setpoint_temperature"]
|
self._attr_target_temperature = room["therm_setpoint_temperature"]
|
||||||
if self._attr_target_temperature == DEFAULT_MAX_TEMP:
|
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()
|
self.async_write_ha_state()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -333,7 +331,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self) -> str | None:
|
def hvac_action(self) -> HVACAction:
|
||||||
"""Return the current running hvac operation if supported."""
|
"""Return the current running hvac operation if supported."""
|
||||||
if self._model == NA_THERM and self._boilerstatus is not None:
|
if self._model == NA_THERM and self._boilerstatus is not None:
|
||||||
return CURRENT_HVAC_MAP_NETATMO[self._boilerstatus]
|
return CURRENT_HVAC_MAP_NETATMO[self._boilerstatus]
|
||||||
@ -341,23 +339,23 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
if (
|
if (
|
||||||
heating_req := getattr(self._room, "heating_power_request", 0)
|
heating_req := getattr(self._room, "heating_power_request", 0)
|
||||||
) is not None and heating_req > 0:
|
) is not None and heating_req > 0:
|
||||||
return CURRENT_HVAC_HEAT
|
return HVACAction.HEATING
|
||||||
return CURRENT_HVAC_IDLE
|
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."""
|
"""Set new target hvac mode."""
|
||||||
if hvac_mode == HVAC_MODE_OFF:
|
if hvac_mode == HVACMode.OFF:
|
||||||
await self.async_turn_off()
|
await self.async_turn_off()
|
||||||
elif hvac_mode == HVAC_MODE_AUTO:
|
elif hvac_mode == HVACMode.AUTO:
|
||||||
if self.hvac_mode == HVAC_MODE_OFF:
|
if self.hvac_mode == HVACMode.OFF:
|
||||||
await self.async_turn_on()
|
await self.async_turn_on()
|
||||||
await self.async_set_preset_mode(PRESET_SCHEDULE)
|
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)
|
await self.async_set_preset_mode(PRESET_BOOST)
|
||||||
|
|
||||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||||
"""Set new preset mode."""
|
"""Set new preset mode."""
|
||||||
if self.hvac_mode == HVAC_MODE_OFF:
|
if self.hvac_mode == HVACMode.OFF:
|
||||||
await self.async_turn_on()
|
await self.async_turn_on()
|
||||||
|
|
||||||
if self.target_temperature == 0:
|
if self.target_temperature == 0:
|
||||||
@ -369,7 +367,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
if (
|
if (
|
||||||
preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX)
|
preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX)
|
||||||
and self._model == NA_VALVE
|
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(
|
await self._climate_state.async_set_room_thermpoint(
|
||||||
self._room.entity_id,
|
self._room.entity_id,
|
||||||
@ -385,7 +383,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
)
|
)
|
||||||
elif (
|
elif (
|
||||||
preset_mode in (PRESET_BOOST, STATE_NETATMO_MAX)
|
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(
|
await self._climate_state.async_set_room_thermpoint(
|
||||||
self._room.entity_id, STATE_NETATMO_HOME
|
self._room.entity_id, STATE_NETATMO_HOME
|
||||||
@ -421,7 +419,7 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||||||
STATE_NETATMO_MANUAL,
|
STATE_NETATMO_MANUAL,
|
||||||
DEFAULT_MIN_TEMP,
|
DEFAULT_MIN_TEMP,
|
||||||
)
|
)
|
||||||
elif self.hvac_mode != HVAC_MODE_OFF:
|
elif self.hvac_mode != HVACMode.OFF:
|
||||||
await self._climate_state.async_set_room_thermpoint(
|
await self._climate_state.async_set_room_thermpoint(
|
||||||
self._room.entity_id, STATE_NETATMO_OFF
|
self._room.entity_id, STATE_NETATMO_OFF
|
||||||
)
|
)
|
||||||
|
@ -12,11 +12,9 @@ from homeassistant.components.climate import (
|
|||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
ATTR_PRESET_MODE,
|
ATTR_PRESET_MODE,
|
||||||
HVAC_MODE_AUTO,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_BOOST,
|
PRESET_BOOST,
|
||||||
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.components.netatmo.climate import PRESET_FROST_GUARD, PRESET_SCHEDULE
|
from homeassistant.components.netatmo.climate import PRESET_FROST_GUARD, PRESET_SCHEDULE
|
||||||
from homeassistant.components.netatmo.const import (
|
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(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
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,
|
blocking=True,
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
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(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
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,
|
blocking=True,
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
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(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
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,
|
blocking=True,
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user