mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use climate enums in oem (#70727)
This commit is contained in:
parent
76dd82f8e5
commit
df2a4223da
@ -5,18 +5,11 @@ from oemthermostat import Thermostat
|
|||||||
import requests
|
import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
|
||||||
PLATFORM_SCHEMA,
|
|
||||||
ClimateEntity,
|
|
||||||
ClimateEntityFeature,
|
|
||||||
)
|
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
CURRENT_HVAC_HEAT,
|
ClimateEntityFeature,
|
||||||
CURRENT_HVAC_IDLE,
|
HVACAction,
|
||||||
CURRENT_HVAC_OFF,
|
HVACMode,
|
||||||
HVAC_MODE_AUTO,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
@ -42,7 +35,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
SUPPORT_HVAC = [HVACMode.AUTO, HVACMode.HEAT, HVACMode.OFF]
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(
|
def setup_platform(
|
||||||
@ -69,6 +62,7 @@ def setup_platform(
|
|||||||
class ThermostatDevice(ClimateEntity):
|
class ThermostatDevice(ClimateEntity):
|
||||||
"""Interface class for the oemthermostat module."""
|
"""Interface class for the oemthermostat module."""
|
||||||
|
|
||||||
|
_attr_hvac_modes = SUPPORT_HVAC
|
||||||
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
|
|
||||||
def __init__(self, thermostat, name):
|
def __init__(self, thermostat, name):
|
||||||
@ -83,24 +77,16 @@ class ThermostatDevice(ClimateEntity):
|
|||||||
self._mode = None
|
self._mode = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""Return hvac operation ie. heat, cool mode.
|
"""Return hvac operation ie. heat, cool mode.
|
||||||
|
|
||||||
Need to be one of HVAC_MODE_*.
|
Need to be one of HVAC_MODE_*.
|
||||||
"""
|
"""
|
||||||
if self._mode == 2:
|
if self._mode == 2:
|
||||||
return HVAC_MODE_HEAT
|
return HVACMode.HEAT
|
||||||
if self._mode == 1:
|
if self._mode == 1:
|
||||||
return HVAC_MODE_AUTO
|
return HVACMode.AUTO
|
||||||
return HVAC_MODE_OFF
|
return HVACMode.OFF
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self):
|
|
||||||
"""Return the list of available hvac operation modes.
|
|
||||||
|
|
||||||
Need to be a subset of HVAC_MODES.
|
|
||||||
"""
|
|
||||||
return SUPPORT_HVAC
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -113,13 +99,13 @@ class ThermostatDevice(ClimateEntity):
|
|||||||
return TEMP_CELSIUS
|
return TEMP_CELSIUS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self):
|
def hvac_action(self) -> HVACAction:
|
||||||
"""Return current hvac i.e. heat, cool, idle."""
|
"""Return current hvac i.e. heat, cool, idle."""
|
||||||
if not self._mode:
|
if not self._mode:
|
||||||
return CURRENT_HVAC_OFF
|
return HVACAction.OFF
|
||||||
if self._state:
|
if self._state:
|
||||||
return CURRENT_HVAC_HEAT
|
return HVACAction.HEATING
|
||||||
return CURRENT_HVAC_IDLE
|
return HVACAction.IDLE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
@ -131,13 +117,13 @@ class ThermostatDevice(ClimateEntity):
|
|||||||
"""Return the temperature we try to reach."""
|
"""Return the temperature we try to reach."""
|
||||||
return self._setpoint
|
return self._setpoint
|
||||||
|
|
||||||
def set_hvac_mode(self, hvac_mode):
|
def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set new target hvac mode."""
|
"""Set new target hvac mode."""
|
||||||
if hvac_mode == HVAC_MODE_AUTO:
|
if hvac_mode == HVACMode.AUTO:
|
||||||
self.thermostat.mode = 1
|
self.thermostat.mode = 1
|
||||||
elif hvac_mode == HVAC_MODE_HEAT:
|
elif hvac_mode == HVACMode.HEAT:
|
||||||
self.thermostat.mode = 2
|
self.thermostat.mode = 2
|
||||||
elif hvac_mode == HVAC_MODE_OFF:
|
elif hvac_mode == HVACMode.OFF:
|
||||||
self.thermostat.mode = 0
|
self.thermostat.mode = 0
|
||||||
|
|
||||||
def set_temperature(self, **kwargs):
|
def set_temperature(self, **kwargs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user