Eph ember support operation modes (#15820)
* add operation mode support for climate.EphEmber * fix linting errors from py3.5 * remove STATE_ALL_DAY and cleanup some code based on review * use explicit None return with get * fix none return
This commit is contained in:
parent
1205eaaa22
commit
d3fed52254
2 changed files with 59 additions and 7 deletions
|
@ -9,24 +9,35 @@ from datetime import timedelta
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
ClimateDevice, PLATFORM_SCHEMA, STATE_HEAT, STATE_IDLE, SUPPORT_AUX_HEAT,
|
||||
ClimateDevice, PLATFORM_SCHEMA, STATE_HEAT, STATE_OFF,
|
||||
STATE_AUTO, SUPPORT_AUX_HEAT, SUPPORT_OPERATION_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE)
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS, CONF_USERNAME, CONF_PASSWORD, ATTR_TEMPERATURE)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['pyephember==0.1.1']
|
||||
REQUIREMENTS = ['pyephember==0.2.0']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Return cached results if last scan was less then this time ago
|
||||
SCAN_INTERVAL = timedelta(seconds=120)
|
||||
|
||||
OPERATION_LIST = [STATE_AUTO, STATE_HEAT, STATE_OFF]
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string
|
||||
})
|
||||
|
||||
EPH_TO_HA_STATE = {
|
||||
'AUTO': STATE_AUTO,
|
||||
'ON': STATE_HEAT,
|
||||
'OFF': STATE_OFF
|
||||
}
|
||||
|
||||
HA_STATE_TO_EPH = {value: key for key, value in EPH_TO_HA_STATE.items()}
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the ephember thermostat."""
|
||||
|
@ -61,9 +72,11 @@ class EphEmberThermostat(ClimateDevice):
|
|||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
if self._hot_water:
|
||||
return SUPPORT_AUX_HEAT
|
||||
return SUPPORT_AUX_HEAT | SUPPORT_OPERATION_MODE
|
||||
|
||||
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_AUX_HEAT
|
||||
return (SUPPORT_TARGET_TEMPERATURE |
|
||||
SUPPORT_AUX_HEAT |
|
||||
SUPPORT_OPERATION_MODE)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -93,12 +106,40 @@ class EphEmberThermostat(ClimateDevice):
|
|||
|
||||
return 1
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Show Device Attributes."""
|
||||
attributes = {
|
||||
'currently_active': self._zone['isCurrentlyActive']
|
||||
}
|
||||
return attributes
|
||||
|
||||
@property
|
||||
def current_operation(self):
|
||||
"""Return current operation ie. heat, cool, idle."""
|
||||
mode = self._ember.get_zone_mode(self._zone_name)
|
||||
return self.map_mode_eph_hass(mode)
|
||||
|
||||
@property
|
||||
def operation_list(self):
|
||||
"""Return the supported operations."""
|
||||
return OPERATION_LIST
|
||||
|
||||
def set_operation_mode(self, operation_mode):
|
||||
"""Set the operation mode."""
|
||||
mode = self.map_mode_hass_eph(operation_mode)
|
||||
if mode is not None:
|
||||
self._ember.set_mode_by_name(self._zone_name, mode)
|
||||
else:
|
||||
_LOGGER.error("Invalid operation mode provided %s", operation_mode)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return current state."""
|
||||
if self._zone['isCurrentlyActive']:
|
||||
return STATE_HEAT
|
||||
return STATE_IDLE
|
||||
return True
|
||||
|
||||
return None
|
||||
|
||||
@property
|
||||
def is_aux_heat_on(self):
|
||||
|
@ -152,3 +193,14 @@ class EphEmberThermostat(ClimateDevice):
|
|||
def update(self):
|
||||
"""Get the latest data."""
|
||||
self._zone = self._ember.get_zone(self._zone_name)
|
||||
|
||||
@staticmethod
|
||||
def map_mode_hass_eph(operation_mode):
|
||||
"""Map from home assistant mode to eph mode."""
|
||||
from pyephember.pyephember import ZoneMode
|
||||
return getattr(ZoneMode, HA_STATE_TO_EPH.get(operation_mode), None)
|
||||
|
||||
@staticmethod
|
||||
def map_mode_eph_hass(operation_mode):
|
||||
"""Map from eph mode to home assistant mode."""
|
||||
return EPH_TO_HA_STATE.get(operation_mode.name, STATE_AUTO)
|
||||
|
|
|
@ -835,7 +835,7 @@ pyemby==1.5
|
|||
pyenvisalink==2.3
|
||||
|
||||
# homeassistant.components.climate.ephember
|
||||
pyephember==0.1.1
|
||||
pyephember==0.2.0
|
||||
|
||||
# homeassistant.components.sensor.fido
|
||||
pyfido==2.1.1
|
||||
|
|
Loading…
Add table
Reference in a new issue