-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Add Enphase Envoy component #15081
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
Add Enphase Envoy component #15081
Changes from 15 commits
c7ca273
75c87fa
30ece48
e549f4e
4adfbde
66d0df8
ad17cb1
b8d3738
fe90ffd
a38ebe7
a325c8a
7d1df3a
77e5355
d43d1bc
d90bd63
8d88fa2
bf47d88
5004d3c
11cc650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| """ | ||
| Support for Enphase Envoy solar energy monitor. | ||
|
|
||
| For more details about this platform, please refer to the documentation at | ||
| https://home-assistant.io/components/sensor.enphase_envoy/ | ||
| """ | ||
| import logging | ||
| import voluptuous as vol | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a blank line between logging and voluptuous. |
||
|
|
||
| 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) | ||
| from homeassistant.const import (CONF_MONITORED_CONDITIONS) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Group imports from the same module. I use from homeassistant.const import (
CONF_IP_ADDRESS, CONF_MONITORED_CONDITIONS) |
||
|
|
||
|
|
||
| REQUIREMENTS = ['envoy_reader==0.1'] | ||
| _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"), | ||
| "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"), | ||
| "lifetime_consumption": ("Envoy Lifetime Energy Consumption", "Wh") | ||
| } | ||
|
|
||
|
|
||
| ICON = 'mdi:flash' | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_IP_ADDRESS): cv.string, | ||
| vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SENSORS)): | ||
| vol.All(cv.ensure_list, [vol.In(list(SENSORS))]) | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Set up the Enphase Envoy sensor.""" | ||
| ip_address = config[CONF_IP_ADDRESS] | ||
| monitored_conditions = config[CONF_MONITORED_CONDITIONS] | ||
|
|
||
| # Iterate through the list of sensors | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent the comment with the code that the comment is aimed at. |
||
| for condition in monitored_conditions: | ||
| add_devices([Envoy(ip_address, condition, SENSORS[condition][0], | ||
| SENSORS[condition][1])], True) | ||
|
|
||
|
|
||
| class Envoy(Entity): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too many blank lines (3) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
| """Implementation of the Enphase Envoy sensors.""" | ||
|
|
||
| def __init__(self, ip_address, sensor_type, name, unit): | ||
| """Initialize the sensor.""" | ||
| self._ip_address = ip_address | ||
| self._name = name | ||
| self._unit_of_measurement = unit | ||
| self._type = sensor_type | ||
| self._state = None | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the sensor.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def state(self): | ||
| """Return the state of the sensor.""" | ||
| return self._state | ||
|
|
||
| @property | ||
| def unit_of_measurement(self): | ||
| """Return the unit of measurement of this entity, if any.""" | ||
| return self._unit_of_measurement | ||
|
|
||
| @property | ||
| def icon(self): | ||
| """Icon to use in the frontend, if any.""" | ||
| return ICON | ||
|
|
||
| def update(self): | ||
| """Get the energy production data from the Enphase Envoy.""" | ||
| import envoy_reader | ||
|
|
||
| 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)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,6 +302,9 @@ enocean==0.40 | |
| # homeassistant.components.sensor.envirophat | ||
| # envirophat==0.0.6 | ||
|
|
||
| # homeassistant.components.sensor.enphase_envoy | ||
| envoy_reader==0.1 | ||
|
|
||
| # homeassistant.components.sensor.season | ||
| ephem==3.7.6.0 | ||
|
|
||
|
|
@@ -1451,3 +1454,5 @@ zigpy-xbee==0.1.1 | |
|
|
||
| # homeassistant.components.zha | ||
| zigpy==0.1.0 | ||
|
|
||
| # homeassistant.components.sensor.enphase_envoy | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a blank line between standard library and 3rd party imports and 3rd party and homeassistant imports.