From 2b0b431a2a5a6e1c0aa7862ee6e84c684b4db18b Mon Sep 17 00:00:00 2001 From: Jesse Rizzo <32472573+jesserizzo@users.noreply.github.com> Date: Sat, 1 Sep 2018 16:45:47 -0500 Subject: [PATCH] Update to EnvoyReader 0.2, support for more hardware (#16212) * Add support for older Envoy models * Stop requiring envoy model name in config * Update to envoy_reader0.2 * Minor formatting fixes * run script/gen_requirements_all.py * Minor formatting fixes * Change some strings to constants, use getattr to call function --- .../components/sensor/enphase_envoy.py | 35 +++++-------------- requirements_all.txt | 2 +- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/sensor/enphase_envoy.py b/homeassistant/components/sensor/enphase_envoy.py index 6afe887537c..7f8cff0f885 100644 --- a/homeassistant/components/sensor/enphase_envoy.py +++ b/homeassistant/components/sensor/enphase_envoy.py @@ -14,25 +14,27 @@ import homeassistant.helpers.config_validation as cv from homeassistant.const import (CONF_IP_ADDRESS, CONF_MONITORED_CONDITIONS) -REQUIREMENTS = ['envoy_reader==0.1'] +REQUIREMENTS = ['envoy_reader==0.2'] _LOGGER = logging.getLogger(__name__) SENSORS = { "production": ("Envoy Current Energy Production", 'W'), "daily_production": ("Envoy Today's Energy Production", "Wh"), - "7_days_production": ("Envoy Last Seven Days Energy Production", "Wh"), + "seven_days_production": ("Envoy Last Seven Days Energy Production", "Wh"), "lifetime_production": ("Envoy Lifetime Energy Production", "Wh"), "consumption": ("Envoy Current Energy Consumption", "W"), "daily_consumption": ("Envoy Today's Energy Consumption", "Wh"), - "7_days_consumption": ("Envoy Last Seven Days Energy Consumption", "Wh"), + "seven_days_consumption": ("Envoy Last Seven Days Energy Consumption", + "Wh"), "lifetime_consumption": ("Envoy Lifetime Energy Consumption", "Wh") } ICON = 'mdi:flash' +CONST_DEFAULT_HOST = "envoy" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Required(CONF_IP_ADDRESS): cv.string, + vol.Optional(CONF_IP_ADDRESS, default=CONST_DEFAULT_HOST): cv.string, vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SENSORS)): vol.All(cv.ensure_list, [vol.In(list(SENSORS))])}) @@ -81,27 +83,6 @@ class Envoy(Entity): def update(self): """Get the energy production data from the Enphase Envoy.""" - import envoy_reader + from envoy_reader import EnvoyReader - if self._type == "production": - self._state = int(envoy_reader.production(self._ip_address)) - elif self._type == "daily_production": - self._state = int(envoy_reader.daily_production(self._ip_address)) - elif self._type == "7_days_production": - self._state = int(envoy_reader.seven_days_production( - self._ip_address)) - elif self._type == "lifetime_production": - self._state = int(envoy_reader.lifetime_production( - self._ip_address)) - - elif self._type == "consumption": - self._state = int(envoy_reader.consumption(self._ip_address)) - elif self._type == "daily_consumption": - self._state = int(envoy_reader.daily_consumption( - self._ip_address)) - elif self._type == "7_days_consumption": - self._state = int(envoy_reader.seven_days_consumption( - self._ip_address)) - elif self._type == "lifetime_consumption": - self._state = int(envoy_reader.lifetime_consumption( - self._ip_address)) + self._state = getattr(EnvoyReader(self._ip_address), self._type)() diff --git a/requirements_all.txt b/requirements_all.txt index ff95a8fc2ad..8c2080d12fa 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -321,7 +321,7 @@ enocean==0.40 # envirophat==0.0.6 # homeassistant.components.sensor.enphase_envoy -envoy_reader==0.1 +envoy_reader==0.2 # homeassistant.components.sensor.season ephem==3.7.6.0