Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enphase envoy individual inverter production #24445

Merged
merged 17 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/enphase_envoy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Enphase envoy",
"documentation": "https://www.home-assistant.io/components/enphase_envoy",
"requirements": [
"envoy_reader==0.4"
"envoy_reader==0.8"
],
"dependencies": [],
"codeowners": []
Expand Down
64 changes: 49 additions & 15 deletions homeassistant/components/enphase_envoy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
from homeassistant.components.sensor import PLATFORM_SCHEMA
import homeassistant.helpers.config_validation as cv
from homeassistant.const import (
CONF_IP_ADDRESS, CONF_MONITORED_CONDITIONS, POWER_WATT)
CONF_IP_ADDRESS, CONF_MONITORED_CONDITIONS, POWER_WATT, ENERGY_WATT_HOUR)


_LOGGER = logging.getLogger(__name__)

SENSORS = {
"production": ("Envoy Current Energy Production", POWER_WATT),
"daily_production": ("Envoy Today's 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"),
"daily_production": ("Envoy Today's Energy Production", ENERGY_WATT_HOUR),
"seven_days_production": ("Envoy Last Seven Days Energy Production",
ENERGY_WATT_HOUR),
"lifetime_production": ("Envoy Lifetime Energy Production",
ENERGY_WATT_HOUR),
"consumption": ("Envoy Current Energy Consumption", POWER_WATT),
"daily_consumption": ("Envoy Today's Energy Consumption",
ENERGY_WATT_HOUR),
"seven_days_consumption": ("Envoy Last Seven Days Energy Consumption",
"Wh"),
"lifetime_consumption": ("Envoy Lifetime Energy Consumption", "Wh")
ENERGY_WATT_HOUR),
"lifetime_consumption": ("Envoy Lifetime Energy Consumption",
ENERGY_WATT_HOUR),
"inverters": ("Envoy Inverter", POWER_WATT)
}


Expand All @@ -34,15 +39,29 @@
vol.All(cv.ensure_list, [vol.In(list(SENSORS))])})


def setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the Enphase Envoy sensor."""
from envoy_reader.envoy_reader import EnvoyReader

ip_address = config[CONF_IP_ADDRESS]
monitored_conditions = config[CONF_MONITORED_CONDITIONS]

entities = []
# Iterate through the list of sensors
for condition in monitored_conditions:
add_entities([Envoy(ip_address, condition, SENSORS[condition][0],
SENSORS[condition][1])], True)
if condition == "inverters":
inverters = await EnvoyReader(ip_address).inverters_production()
if isinstance(inverters, dict):
for inverter in inverters:
entities.append(Envoy(ip_address, condition,
"{} {}".format(SENSORS[condition][0],
inverter),
SENSORS[condition][1]))
else:
entities.append(Envoy(ip_address, condition, SENSORS[condition][0],
SENSORS[condition][1]))
async_add_entities(entities)


class Envoy(Entity):
Expand Down Expand Up @@ -76,8 +95,23 @@ def icon(self):
"""Icon to use in the frontend, if any."""
return ICON

def update(self):
async def async_update(self):
"""Get the energy production data from the Enphase Envoy."""
from envoy_reader import EnvoyReader

self._state = getattr(EnvoyReader(self._ip_address), self._type)()
from envoy_reader.envoy_reader import EnvoyReader

if self._type != "inverters":
_state = await getattr(EnvoyReader(self._ip_address), self._type)()
if isinstance(_state, int):
self._state = _state
else:
_LOGGER.error(_state)
self._state = None

elif self._type == "inverters":
inverters = await (EnvoyReader(self._ip_address)
.inverters_production())
if isinstance(inverters, dict):
serial_number = self._name.split(" ")[2]
self._state = inverters[serial_number]
else:
self._state = None
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ env_canada==0.0.10
# envirophat==0.0.6

# homeassistant.components.enphase_envoy
envoy_reader==0.4
envoy_reader==0.8

# homeassistant.components.season
ephem==3.7.6.0
Expand Down