This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

@@ -7,7 +7,11 @@ from homeassistant.helpers.entity import Entity
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, ENERGY_WATT_HOUR)
CONF_IP_ADDRESS,
CONF_MONITORED_CONDITIONS,
POWER_WATT,
ENERGY_WATT_HOUR,
)
_LOGGER = logging.getLogger(__name__)
@@ -15,32 +19,36 @@ _LOGGER = logging.getLogger(__name__)
SENSORS = {
"production": ("Envoy Current Energy Production", POWER_WATT),
"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),
"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",
ENERGY_WATT_HOUR),
"lifetime_consumption": ("Envoy Lifetime Energy Consumption",
ENERGY_WATT_HOUR),
"inverters": ("Envoy Inverter", POWER_WATT)
}
"daily_consumption": ("Envoy Today's Energy Consumption", ENERGY_WATT_HOUR),
"seven_days_consumption": (
"Envoy Last Seven Days Energy Consumption",
ENERGY_WATT_HOUR,
),
"lifetime_consumption": ("Envoy Lifetime Energy Consumption", ENERGY_WATT_HOUR),
"inverters": ("Envoy Inverter", POWER_WATT),
}
ICON = 'mdi:flash'
ICON = "mdi:flash"
CONST_DEFAULT_HOST = "envoy"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
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))])})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
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))]
),
}
)
async def async_setup_platform(hass, config, async_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
@@ -54,13 +62,20 @@ async def async_setup_platform(hass, config, async_add_entities,
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]))
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]))
entities.append(
Envoy(
ip_address, condition, SENSORS[condition][0], SENSORS[condition][1]
)
)
async_add_entities(entities)
@@ -108,8 +123,7 @@ class Envoy(Entity):
self._state = None
elif self._type == "inverters":
inverters = await (EnvoyReader(self._ip_address)
.inverters_production())
inverters = await (EnvoyReader(self._ip_address).inverters_production())
if isinstance(inverters, dict):
serial_number = self._name.split(" ")[2]
self._state = inverters[serial_number]