Skip to content
Snippets Groups Projects
Commit 7528da45 authored by Rob Johnson's avatar Rob Johnson Committed by Paulus Schoutsen
Browse files

Vera Thermostat Support (#3247)

* vera thermostat & climate support

* disable abstract

* code review changes

* fix

* fix build

* remove old method
parent 8da85d7a
No related branches found
No related tags found
No related merge requests found
"""
Support for Vera thermostats.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.vera/
"""
import logging
from homeassistant.util import convert
from homeassistant.components.climate import ClimateDevice
from homeassistant.const import TEMP_FAHRENHEIT, ATTR_TEMPERATURE
from homeassistant.components.vera import (
VeraDevice, VERA_DEVICES, VERA_CONTROLLER)
DEPENDENCIES = ['vera']
_LOGGER = logging.getLogger(__name__)
OPERATION_LIST = ["Heat", "Cool", "Auto Changeover", "Off"]
FAN_OPERATION_LIST = ["On", "Auto", "Cycle"]
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Find and return Vera thermostats."""
add_devices_callback(
VeraThermostat(device, VERA_CONTROLLER) for
device in VERA_DEVICES['climate'])
# pylint: disable=abstract-method
class VeraThermostat(VeraDevice, ClimateDevice):
"""Representation of a Vera Thermostat."""
def __init__(self, vera_device, controller):
"""Initialize the Vera device."""
VeraDevice.__init__(self, vera_device, controller)
@property
def current_operation(self):
"""Return current operation ie. heat, cool, idle."""
mode = self.vera_device.get_hvac_mode()
if mode == "HeatOn":
return OPERATION_LIST[0] # heat
elif mode == "CoolOn":
return OPERATION_LIST[1] # cool
elif mode == "AutoChangeOver":
return OPERATION_LIST[2] # auto
elif mode == "Off":
return OPERATION_LIST[3] # off
return "Off"
@property
def operation_list(self):
"""List of available operation modes."""
return OPERATION_LIST
@property
def current_fan_mode(self):
"""Return the fan setting."""
mode = self.vera_device.get_fan_mode()
if mode == "ContinuousOn":
return FAN_OPERATION_LIST[0] # on
elif mode == "Auto":
return FAN_OPERATION_LIST[1] # auto
elif mode == "PeriodicOn":
return FAN_OPERATION_LIST[2] # cycle
return "Auto"
@property
def fan_list(self):
"""List of available fan modes."""
return FAN_OPERATION_LIST
def set_fan_mode(self, mode):
"""Set new target temperature."""
if mode == FAN_OPERATION_LIST[0]:
self.vera_device.fan_on()
elif mode == FAN_OPERATION_LIST[1]:
self.vera_device.fan_auto()
elif mode == FAN_OPERATION_LIST[2]:
return self.vera_device.fan_cycle()
@property
def current_power_mwh(self):
"""Current power usage in mWh."""
power = self.vera_device.power
if power:
return convert(power, float, 0.0) * 1000
def update(self):
"""Called by the vera device callback to update state."""
self._state = self.vera_device.get_hvac_mode()
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return TEMP_FAHRENHEIT
@property
def current_temperature(self):
"""Return the current temperature."""
return self.vera_device.get_current_temperature()
@property
def operation(self):
"""Return current operation ie. heat, cool, idle."""
return self.vera_device.get_hvac_state()
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
return self.vera_device.get_current_goal_temperature()
def set_temperature(self, **kwargs):
"""Set new target temperatures."""
if kwargs.get(ATTR_TEMPERATURE) is not None:
self.vera_device.set_temperature(kwargs.get(ATTR_TEMPERATURE))
def set_operation_mode(self, operation_mode):
"""Set HVAC mode (auto, cool, heat, off)."""
if operation_mode == OPERATION_LIST[3]: # off
self.vera_device.turn_off()
elif operation_mode == OPERATION_LIST[2]: # auto
self.vera_device.turn_auto_on()
elif operation_mode == OPERATION_LIST[1]: # cool
self.vera_device.turn_cool_on()
elif operation_mode == OPERATION_LIST[0]: # heat
self.vera_device.turn_heat_on()
def turn_fan_on(self):
"""Turn fan on."""
self.vera_device.fan_on()
def turn_fan_off(self):
"""Turn fan off."""
self.vera_device.fan_auto()
...@@ -34,7 +34,7 @@ SERVICE_SET_HVAC_MODE = "set_hvac_mode" ...@@ -34,7 +34,7 @@ SERVICE_SET_HVAC_MODE = "set_hvac_mode"
STATE_HEAT = "heat" STATE_HEAT = "heat"
STATE_COOL = "cool" STATE_COOL = "cool"
STATE_IDLE = "idle" STATE_IDLE = "idle"
STATE_AUTO = 'auto' STATE_AUTO = "auto"
ATTR_CURRENT_TEMPERATURE = "current_temperature" ATTR_CURRENT_TEMPERATURE = "current_temperature"
ATTR_AWAY_MODE = "away_mode" ATTR_AWAY_MODE = "away_mode"
......
...@@ -20,7 +20,7 @@ from homeassistant.const import ( ...@@ -20,7 +20,7 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP) EVENT_HOMEASSISTANT_STOP)
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['pyvera==0.2.15'] REQUIREMENTS = ['pyvera==0.2.16']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
...@@ -42,10 +42,14 @@ CONFIG_SCHEMA = vol.Schema({ ...@@ -42,10 +42,14 @@ CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({ DOMAIN: vol.Schema({
vol.Required(CONF_CONTROLLER): cv.url, vol.Required(CONF_CONTROLLER): cv.url,
vol.Optional(CONF_EXCLUDE, default=[]): VERA_ID_LIST_SCHEMA, vol.Optional(CONF_EXCLUDE, default=[]): VERA_ID_LIST_SCHEMA,
vol.Optional(CONF_LIGHTS, default=[]): VERA_ID_LIST_SCHEMA, vol.Optional(CONF_LIGHTS, default=[]): VERA_ID_LIST_SCHEMA
}), }),
}, extra=vol.ALLOW_EXTRA) }, extra=vol.ALLOW_EXTRA)
VERA_COMPONENTS = [
'binary_sensor', 'sensor', 'light', 'switch', 'lock', 'climate'
]
# pylint: disable=unused-argument, too-many-function-args # pylint: disable=unused-argument, too-many-function-args
def setup(hass, base_config): def setup(hass, base_config):
...@@ -83,7 +87,7 @@ def setup(hass, base_config): ...@@ -83,7 +87,7 @@ def setup(hass, base_config):
continue continue
VERA_DEVICES[dev_type].append(device) VERA_DEVICES[dev_type].append(device)
for component in 'binary_sensor', 'sensor', 'light', 'switch', 'lock': for component in VERA_COMPONENTS:
discovery.load_platform(hass, component, DOMAIN, {}, base_config) discovery.load_platform(hass, component, DOMAIN, {}, base_config)
return True return True
...@@ -103,6 +107,8 @@ def map_vera_device(vera_device, remap): ...@@ -103,6 +107,8 @@ def map_vera_device(vera_device, remap):
return 'switch' return 'switch'
if isinstance(vera_device, veraApi.VeraLock): if isinstance(vera_device, veraApi.VeraLock):
return 'lock' return 'lock'
if isinstance(vera_device, veraApi.VeraThermostat):
return 'climate'
if isinstance(vera_device, veraApi.VeraSwitch): if isinstance(vera_device, veraApi.VeraSwitch):
if vera_device.device_id in remap: if vera_device.device_id in remap:
return 'light' return 'light'
......
...@@ -400,7 +400,7 @@ python-wink==0.7.14 ...@@ -400,7 +400,7 @@ python-wink==0.7.14
# pyuserinput==0.1.11 # pyuserinput==0.1.11
# homeassistant.components.vera # homeassistant.components.vera
pyvera==0.2.15 pyvera==0.2.16
# homeassistant.components.wemo # homeassistant.components.wemo
pywemo==0.4.6 pywemo==0.4.6
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment