From 0b850b555f30b704fdf2cf4fbf02ee885e0ee5ad Mon Sep 17 00:00:00 2001
From: Thom Troy <ttroy50@gmail.com>
Date: Mon, 23 Oct 2017 14:52:39 +0100
Subject: [PATCH] add eph ember controls (#9721)

* add eph ember controls

* updates based on review

* remove unused import

* update to new version of pyephember

* added myself to codeowners as requested

* make codeowners alphabetical

* run fixed gen_requirements_all

* Update ephember.py
---
 .coveragerc                                  |   1 +
 CODEOWNERS                                   |   2 +-
 homeassistant/components/climate/ephember.py | 117 +++++++++++++++++++
 requirements_all.txt                         |   3 +
 4 files changed, 122 insertions(+), 1 deletion(-)
 create mode 100644 homeassistant/components/climate/ephember.py

diff --git a/.coveragerc b/.coveragerc
index ec03242880c..ddbd4a1e0b1 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -275,6 +275,7 @@ omit =
     homeassistant/components/camera/ring.py
     homeassistant/components/camera/synology.py
     homeassistant/components/camera/yi.py
+    homeassistant/components/climate/ephember.py
     homeassistant/components/climate/eq3btsmart.py
     homeassistant/components/climate/flexit.py
     homeassistant/components/climate/heatmiser.py
diff --git a/CODEOWNERS b/CODEOWNERS
index 0830adcc355..46e01c2b89f 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -41,6 +41,7 @@ homeassistant/components/*/zwave.py @home-assistant/z-wave
 # Indiviudal components
 homeassistant/components/alarm_control_panel/egardia.py @jeroenterheerdt
 homeassistant/components/camera/yi.py @bachya
+homeassistant/components/climate/ephember.py @ttroy50
 homeassistant/components/climate/eq3btsmart.py @rytilahti
 homeassistant/components/climate/sensibo.py @andrey-git
 homeassistant/components/cover/template.py @PhracturedBlue
@@ -58,7 +59,6 @@ homeassistant/components/sensor/waqi.py @andrey-git
 homeassistant/components/switch/rainmachine.py @bachya
 homeassistant/components/switch/tplink.py @rytilahti
 
-homeassistant/components/*/axis.py @Kane610
 homeassistant/components/*/broadlink.py @danielhiversen
 homeassistant/components/*/rfxtrx.py @danielhiversen
 homeassistant/components/tesla.py @zabuldon
diff --git a/homeassistant/components/climate/ephember.py b/homeassistant/components/climate/ephember.py
new file mode 100644
index 00000000000..79ff767c82b
--- /dev/null
+++ b/homeassistant/components/climate/ephember.py
@@ -0,0 +1,117 @@
+"""
+Support for the EPH Controls Ember themostats.
+
+For more details about this platform, please refer to the documentation at
+https://home-assistant.io/components/climate.ephember/
+"""
+import logging
+from datetime import timedelta
+import voluptuous as vol
+
+from homeassistant.components.climate import (
+    ClimateDevice, PLATFORM_SCHEMA, STATE_HEAT, STATE_IDLE)
+from homeassistant.const import (
+    TEMP_CELSIUS, CONF_USERNAME, CONF_PASSWORD)
+import homeassistant.helpers.config_validation as cv
+
+REQUIREMENTS = ['pyephember==0.1.1']
+
+_LOGGER = logging.getLogger(__name__)
+
+# Return cached results if last scan was less then this time ago
+SCAN_INTERVAL = timedelta(seconds=120)
+
+PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
+    vol.Required(CONF_USERNAME): cv.string,
+    vol.Required(CONF_PASSWORD): cv.string
+})
+
+
+def setup_platform(hass, config, add_devices, discovery_info=None):
+    """Set up the ephember thermostat."""
+    from pyephember.pyephember import EphEmber
+
+    username = config.get(CONF_USERNAME)
+    password = config.get(CONF_PASSWORD)
+
+    try:
+        ember = EphEmber(username, password)
+        zones = ember.get_zones()
+        for zone in zones:
+            add_devices([EphEmberThermostat(ember, zone)])
+    except RuntimeError:
+        _LOGGER.error("Cannot connect to EphEmber")
+        return
+
+    return
+
+
+class EphEmberThermostat(ClimateDevice):
+    """Representation of a HeatmiserV3 thermostat."""
+
+    def __init__(self, ember, zone):
+        """Initialize the thermostat."""
+        self._ember = ember
+        self._zone_name = zone['name']
+        self._zone = zone
+        self._hot_water = zone['isHotWater']
+
+    @property
+    def name(self):
+        """Return the name of the thermostat, if any."""
+        return self._zone_name
+
+    @property
+    def temperature_unit(self):
+        """Return the unit of measurement which this thermostat uses."""
+        return TEMP_CELSIUS
+
+    @property
+    def current_temperature(self):
+        """Return the current temperature."""
+        return self._zone['currentTemperature']
+
+    @property
+    def target_temperature(self):
+        """Return the temperature we try to reach."""
+        return self._zone['targetTemperature']
+
+    @property
+    def current_operation(self):
+        """Return current operation ie. heat, cool, idle."""
+        if self._zone['isCurrentlyActive']:
+            return STATE_HEAT
+        else:
+            return STATE_IDLE
+
+    @property
+    def is_aux_heat_on(self):
+        """Return true if aux heater."""
+        return self._zone['isBoostActive']
+
+    def turn_aux_heat_on(self):
+        """Turn auxiliary heater on."""
+        self._ember.activate_boost_by_name(
+            self._zone_name, self._zone['targetTemperature'])
+
+    def turn_aux_heat_off(self):
+        """Turn auxiliary heater off."""
+        self._ember.deactivate_boost_by_name(self._zone_name)
+
+    def set_temperature(self, **kwargs):
+        """Set new target temperature."""
+        return
+
+    @property
+    def min_temp(self):
+        """Return the minimum temperature."""
+        return self._zone['targetTemperature']
+
+    @property
+    def max_temp(self):
+        """Return the maximum temperature."""
+        return self._zone['targetTemperature']
+
+    def update(self):
+        """Get the latest data."""
+        self._zone = self._ember.get_zone(self._zone_name)
diff --git a/requirements_all.txt b/requirements_all.txt
index 7b522beda31..5a49ac5ef89 100644
--- a/requirements_all.txt
+++ b/requirements_all.txt
@@ -626,6 +626,9 @@ pyemby==1.4
 # homeassistant.components.envisalink
 pyenvisalink==2.2
 
+# homeassistant.components.climate.ephember
+pyephember==0.1.1
+
 # homeassistant.components.sensor.fido
 pyfido==1.0.1
 
-- 
GitLab