forked from home-assistant/core
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Climate component for Advantage Air MyAir
- Loading branch information
Showing
2 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
""" | ||
Support for MyAir AC Zoning Control. | ||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/climate.myair/ | ||
""" | ||
import logging | ||
|
||
import voluptuous as vol | ||
|
||
from homeassistant.components.nest import DATA_NEST | ||
from homeassistant.components.climate import ( | ||
STATE_AUTO, STATE_COOL, STATE_HEAT, ClimateDevice, | ||
PLATFORM_SCHEMA, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, | ||
ATTR_TEMPERATURE) | ||
from homeassistant.const import ( | ||
TEMP_CELSIUS, TEMP_FAHRENHEIT, | ||
CONF_SCAN_INTERVAL, STATE_ON, STATE_OFF, STATE_UNKNOWN) | ||
|
||
#DEPENDENCIES = ['pymyair'] | ||
_LOGGER = logging.getLogger(__name__) | ||
|
||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
vol.Optional(CONF_SCAN_INTERVAL): | ||
vol.All(vol.Coerce(int), vol.Range(min=1)), | ||
}) | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Setup the MyAir Zoning""" | ||
if discovery_info is None: | ||
return | ||
|
||
_LOGGER.debug("Setting up myair") | ||
|
||
temp_unit = hass.config.units.temperature_unit | ||
|
||
myairdevice = hass.data[DATA_MYAIR] | ||
|
||
add_devices( | ||
[MyAirZone(zoneid, myairdevice.myair) | ||
for zoneid in myairdevice.zones()], | ||
True | ||
) | ||
|
||
class MyAirZone(ClimateDevice): | ||
"""Representation of a MyAir Zone.""" | ||
|
||
def __init__(self, zone_id, myair_system): | ||
"""Initialize the thermostat.""" | ||
self.name = None | ||
self.zone_id = zone_id | ||
self.myair_system = myair_system | ||
self._fan_list = ['low', 'medium', 'high', STATE_AUTO] | ||
self._operation_list = [STATE_OFF, STATE_HEAT, STATE_COOL, STATE_DRY, STATE_FAN_ONLY] | ||
|
||
# feature of device | ||
self._has_fan = True | ||
|
||
# data attributes | ||
self._name = None | ||
self._humidity = None | ||
self._target_temperature = None | ||
self._temperature = None | ||
self._temperature_scale = TEMP_CELSIUS | ||
self._mode = None | ||
self._fan = None | ||
self._is_locked = None | ||
self._locked_temperature = None | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the zone, if any.""" | ||
return self._name | ||
|
||
@property | ||
def temperature_unit(self): | ||
"""Return the unit of measurement.""" | ||
return self._temperature_scale | ||
|
||
@property | ||
def current_temperature(self): | ||
"""Return the current temperature.""" | ||
return self._temperature | ||
|
||
@property | ||
def current_operation(self): | ||
"""Return current operation ie. heat, cool, idle.""" | ||
if self._mode in [STATE_HEAT, STATE_COOL, STATE_DRY, STATE_FAN_ONLY, STATE_OFF]: | ||
return self._mode | ||
else: | ||
return STATE_UNKNOWN | ||
|
||
@property | ||
def target_temperature(self): | ||
"""Return the temperature we try to reach.""" | ||
return self._target_temperature | ||
|
||
def set_temperature(self, **kwargs): | ||
"""Set new target temperature.""" | ||
temp = kwargs.get(ATTR_TEMPERATURE) | ||
_LOGGER.debug("MyAir set_temperature-output-value=%s", temp) | ||
self.myair_system.setZone(self.zoneid, target=temp) | ||
|
||
def set_operation_mode(self, operation_mode): | ||
"""Set operation mode.""" | ||
if operation_mode in [STATE_HEAT, STATE_COOL, STATE_DRY, STATE_FAN_ONLY, STATE_OFF]: | ||
_LOGGER.debug("Myair set_operation-mode=%s", operation_mode) | ||
# TODO: changing one zone changes all zones operation mode, update refresh should reflect for all zones | ||
# This is confusing!! | ||
if operation_mode in [STATE_ON, STATE_OFF]: | ||
self.myair_system.setZone(self.zoneid, state=operation_mode) | ||
else: | ||
self.myair_system.setSystem(state=operation_mode) | ||
@property | ||
def operation_list(self): | ||
"""List of available operation modes.""" | ||
return self._operation_list | ||
|
||
@property | ||
def current_fan_mode(self): | ||
"""Return whether the fan is on.""" | ||
if self._has_fan: | ||
# Return whether the fan is on | ||
return STATE_ON if self._fan else STATE_AUTO | ||
else: | ||
# No Fan available so disable slider | ||
return None | ||
|
||
@property | ||
def fan_list(self): | ||
"""List of available fan modes.""" | ||
return self._fan_list | ||
|
||
def set_fan_mode(self, fan): | ||
"""Turn fan on/off.""" | ||
self.device.fan = fan.lower() | ||
|
||
|
||
def update(self): | ||
"""Cache value from MyAir""" | ||
zone_state = self.myair_system.getZone(self.zone_id) | ||
system_mode = self.myair_system.getMode() | ||
self._name = zone_state.get('name') | ||
self._temperature = zone_state.get('actualTemp') | ||
self._mode = self.myair_system.get('setting') | ||
self._target_temperature = zone_state.get('desiredTemp') | ||
self.operation_mode = system_mode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
""" | ||
Support for MyAir devices. | ||
For more details about this component, please refer to the documentation at | ||
https://home-assistant.io/components/myair/ | ||
""" | ||
import logging | ||
import socket | ||
|
||
import voluptuous as vol | ||
|
||
import homeassistant.helpers.config_validation as cv | ||
from homeassistant.helpers import discovery | ||
from homeassistant.const import (CONF_STRUCTURE, CONF_FILENAME) | ||
from homeassistant.loader import get_component | ||
|
||
_CONFIGURING = {} | ||
_LOGGER = logging.getLogger(__name__) | ||
|
||
DOMAIN = 'myair' | ||
|
||
DATA_MYAIR = 'myair' | ||
|
||
CONF_IP = 'ip' | ||
CONF_PORT = 'port' | ||
CONF_KEY = 'key' | ||
CONF_NAME = 'name' | ||
|
||
CONFIG_SCHEMA = vol.Schema({ | ||
DOMAIN: vol.Schema({ | ||
vol.Required(CONF_IP): cv.string, | ||
vol.Required(CONF_PORT): vol.All(vol.Coerce(int), vol.Range(min=1)),, | ||
vol.Required(CONF_NAME): cv.string, | ||
vol.Required(CONF_KEY): cv.string | ||
}) | ||
}) | ||
|
||
def setup(hass, config): | ||
"""Setup the Myair component.""" | ||
|
||
import myair | ||
|
||
conf = config[DOMAIN] | ||
|
||
_LOGGER.debug("proceeding with setup") | ||
|
||
conf = config[DOMAIN] | ||
conf_ip = conf[CONF_IP] | ||
conf_port = conf[CONF_PORT] | ||
conf_key = conf[CONF_KEY] | ||
|
||
myair = myair.MyAir(conf_ip,conf_port,conf_key) | ||
|
||
hass.data[DATA_MYAIR] = MyAirDevice(hass, conf, myair) | ||
|
||
_LOGGER.debug("proceeding with discovery") | ||
discovery.load_platform(hass, 'climate', DOMAIN, {}, config) | ||
_LOGGER.debug("setup done") | ||
|
||
return True | ||
|
||
|
||
class MyAirDevice(object): | ||
"""Structure MyAir functions for hass.""" | ||
|
||
def __init__(self, hass, conf, myair): | ||
"""Init MyAir Devices.""" | ||
self.hass = hass | ||
self._myair = myair | ||
|
||
def zones(self): | ||
"""Generator returning list of devices and their location.""" | ||
try: | ||
zonecount = self._myair.getZoneCount() | ||
for zoneid in range(1,zonecount+1): | ||
yield zoneid | ||
except socket.error: | ||
_LOGGER.error( | ||
"Connection error connecting to the myair system") | ||
|
||
@property | ||
def myair(self): | ||
return self._myair | ||
|
||
|
||
|