mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +00:00
Enphase envoy individual inverter production (#24445)
* bump envoy_reader version to 0.4 * bump dependency envoy_reader to 0.4 * Enphase envoy get individual inverter production * Add period in function description * Fix dumb typo * Define _attributes in __init__ * Better error messages, make update async * Fix format error * Fix pylint errors * set unknown state to None * Bump envoy_reader version to 0.8 * Change attributes to separate sensors * Fix dumb thing * Improve platform_setup for inverters * Remove unneeded self._attributes, refactor platform setup * Refactor platform setup
This commit is contained in:
parent
32685f16bf
commit
f90fe7e628
@ -3,7 +3,7 @@
|
|||||||
"name": "Enphase envoy",
|
"name": "Enphase envoy",
|
||||||
"documentation": "https://www.home-assistant.io/components/enphase_envoy",
|
"documentation": "https://www.home-assistant.io/components/enphase_envoy",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"envoy_reader==0.4"
|
"envoy_reader==0.8"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
|
@ -7,21 +7,26 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import (
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SENSORS = {
|
SENSORS = {
|
||||||
"production": ("Envoy Current Energy Production", POWER_WATT),
|
"production": ("Envoy Current Energy Production", POWER_WATT),
|
||||||
"daily_production": ("Envoy Today's Energy Production", "Wh"),
|
"daily_production": ("Envoy Today's Energy Production", ENERGY_WATT_HOUR),
|
||||||
"seven_days_production": ("Envoy Last Seven Days Energy Production", "Wh"),
|
"seven_days_production": ("Envoy Last Seven Days Energy Production",
|
||||||
"lifetime_production": ("Envoy Lifetime Energy Production", "Wh"),
|
ENERGY_WATT_HOUR),
|
||||||
"consumption": ("Envoy Current Energy Consumption", "W"),
|
"lifetime_production": ("Envoy Lifetime Energy Production",
|
||||||
"daily_consumption": ("Envoy Today's Energy Consumption", "Wh"),
|
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",
|
"seven_days_consumption": ("Envoy Last Seven Days Energy Consumption",
|
||||||
"Wh"),
|
ENERGY_WATT_HOUR),
|
||||||
"lifetime_consumption": ("Envoy Lifetime Energy Consumption", "Wh")
|
"lifetime_consumption": ("Envoy Lifetime Energy Consumption",
|
||||||
|
ENERGY_WATT_HOUR),
|
||||||
|
"inverters": ("Envoy Inverter", POWER_WATT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -34,15 +39,29 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.All(cv.ensure_list, [vol.In(list(SENSORS))])})
|
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."""
|
"""Set up the Enphase Envoy sensor."""
|
||||||
|
from envoy_reader.envoy_reader import EnvoyReader
|
||||||
|
|
||||||
ip_address = config[CONF_IP_ADDRESS]
|
ip_address = config[CONF_IP_ADDRESS]
|
||||||
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
monitored_conditions = config[CONF_MONITORED_CONDITIONS]
|
||||||
|
|
||||||
|
entities = []
|
||||||
# Iterate through the list of sensors
|
# Iterate through the list of sensors
|
||||||
for condition in monitored_conditions:
|
for condition in monitored_conditions:
|
||||||
add_entities([Envoy(ip_address, condition, SENSORS[condition][0],
|
if condition == "inverters":
|
||||||
SENSORS[condition][1])], True)
|
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):
|
class Envoy(Entity):
|
||||||
@ -76,8 +95,23 @@ class Envoy(Entity):
|
|||||||
"""Icon to use in the frontend, if any."""
|
"""Icon to use in the frontend, if any."""
|
||||||
return ICON
|
return ICON
|
||||||
|
|
||||||
def update(self):
|
async def async_update(self):
|
||||||
"""Get the energy production data from the Enphase Envoy."""
|
"""Get the energy production data from the Enphase Envoy."""
|
||||||
from envoy_reader import EnvoyReader
|
from envoy_reader.envoy_reader import EnvoyReader
|
||||||
|
|
||||||
self._state = getattr(EnvoyReader(self._ip_address), self._type)()
|
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
|
||||||
|
@ -424,7 +424,7 @@ env_canada==0.0.10
|
|||||||
# envirophat==0.0.6
|
# envirophat==0.0.6
|
||||||
|
|
||||||
# homeassistant.components.enphase_envoy
|
# homeassistant.components.enphase_envoy
|
||||||
envoy_reader==0.4
|
envoy_reader==0.8
|
||||||
|
|
||||||
# homeassistant.components.season
|
# homeassistant.components.season
|
||||||
ephem==3.7.6.0
|
ephem==3.7.6.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user