Add config flow to ecobee (#26634)

* Add basic config flow

* Fix json files

* Update __init__.py

* Fix json errors

* Move constants to const.py

* Add ecobee to generated config flows

* Update config_flow for updated API

* Update manifest to include new dependencies

Bump pyecobee, add aiofiles.

* Update constants for ecobee

* Modify ecobee setup to use config flow

* Bump dependency

* Update binary_sensor to use config_entry

* Update sensor to use config_entry

* Update __init__.py

* Update weather to use config_entry

* Update notify.py

* Update ecobee constants

* Update climate to use config_entry

* Avoid a breaking change on ecobee services

* Store api key from old config entry

* Allow unloading of config entry

* Show user a form before import

* Refine import flow

* Update strings.json to remove import step

Not needed.

* Move third party imports to top of module

* Remove periods from end of log messages

* Make configuration.yaml config optional

* Remove unused strings

* Reorganize config flow

* Remove unneeded requirement

* No need to store API key

* Update async_unload_entry

* Clean up if/else statements

* Update requirements_all.txt

* Fix config schema

* Update __init__.py

* Remove check for DATA_ECOBEE_CONFIG

* Remove redundant check

* Add check for DATA_ECOBEE_CONFIG

* Change setup_platform to async

* Fix state unknown and imports

* Change init step to user

* Have import step raise specific exceptions

* Rearrange try/except block in import flow

* Convert update() and refresh() to coroutines

...and update platforms to use async_update coroutine.

* Finish converting init to async

* Preliminary tests

* Test full implementation

* Update test_config_flow.py

* Update test_config_flow.py

* Add self to codeowners

* Update test_config_flow.py

* Use MockConfigEntry

* Update test_config_flow.py

* Update CODEOWNERS

* pylint fixes

* Register services under ecobee domain

Breaking change!

* Pylint fixes

* Pylint fixes

* Pylint fixes

* Move service strings to ecobee domain

* Fix log message capitalization

* Fix import formatting

* Update .coveragerc

* Add __init__ to coveragerc

* Add option flow test

* Update .coveragerc

* Act on updated options

* Revert "Act on updated options"

This reverts commit 56b0a859f2e3e80b6f4c77a8f784a2b29ee2cce9.

* Remove hold_temp from climate

* Remove hold_temp and options from init

* Remove options handler from config flow

* Remove options strings

* Remove options flow test

* Remove hold_temp constants

* Fix climate tests

* Pass api key to user step in import flow

* Update test_config_flow.py

Ensure that the import step calls the user step with the user's api key as user input if importing from ecobee.conf/validating imported keys fails.
This commit is contained in:
Mark Coombes authored and Martin Hjelmare committed 2019-09-25 22:38:21 +02:00
1 parent cff7fd0ef3
commit f6995b8d17
21 files changed
+623 -218

No files matched your search

+25 -18
View File
@@ -1,5 +1,6 @@
"""Support for Ecobee sensors."""
from homeassistant.components import ecobee
from pyecobee.const import ECOBEE_STATE_CALIBRATING, ECOBEE_STATE_UNKNOWN
from homeassistant.const import (
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_TEMPERATURE,
@@ -7,7 +8,7 @@ from homeassistant.const import (
)
from homeassistant.helpers.entity import Entity
ECOBEE_CONFIG_FILE = "ecobee.conf"
from .const import DOMAIN
SENSOR_TYPES = {
"temperature": ["Temperature", TEMP_FAHRENHEIT],
@@ -15,11 +16,14 @@ SENSOR_TYPES = {
}
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Ecobee sensors."""
if discovery_info is None:
return
data = ecobee.NETWORK
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Old way of setting up ecobee sensors."""
pass
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up ecobee (temperature and humidity) sensors."""
data = hass.data[DOMAIN]
dev = list()
for index in range(len(data.ecobee.thermostats)):
for sensor in data.ecobee.get_remote_sensors(index):
@@ -27,16 +31,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if item["type"] not in ("temperature", "humidity"):
continue
dev.append(EcobeeSensor(sensor["name"], item["type"], index))
dev.append(EcobeeSensor(data, sensor["name"], item["type"], index))
add_entities(dev, True)
async_add_entities(dev, True)
class EcobeeSensor(Entity):
"""Representation of an Ecobee sensor."""
def __init__(self, sensor_name, sensor_type, sensor_index):
def __init__(self, data, sensor_name, sensor_type, sensor_index):
"""Initialize the sensor."""
self.data = data
self._name = "{} {}".format(sensor_name, SENSOR_TYPES[sensor_type][0])
self.sensor_name = sensor_name
self.type = sensor_type
@@ -59,6 +64,12 @@ class EcobeeSensor(Entity):
@property
def state(self):
"""Return the state of the sensor."""
if self._state in [ECOBEE_STATE_CALIBRATING, ECOBEE_STATE_UNKNOWN]:
return None
if self.type == "temperature":
return float(self._state) / 10
return self._state
@property
@@ -66,14 +77,10 @@ class EcobeeSensor(Entity):
"""Return the unit of measurement this sensor expresses itself in."""
return self._unit_of_measurement
def update(self):
async def async_update(self):
"""Get the latest state of the sensor."""
data = ecobee.NETWORK
data.update()
for sensor in data.ecobee.get_remote_sensors(self.index):
await self.data.update()
for sensor in self.data.ecobee.get_remote_sensors(self.index):
for item in sensor["capability"]:
if item["type"] == self.type and self.sensor_name == sensor["name"]:
if self.type == "temperature" and item["value"] != "unknown":
self._state = float(item["value"]) / 10
else:
self._state = item["value"]
self._state = item["value"]