-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add support for Rainforest Eagle-200 #24919
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
df67a8b
Add support for Rainforest Eagle-200
gtdiehl 37be16e
Removed direct access selector to monitored conditions
gtdiehl 24e0232
Refactored code to use throttle on the update function
gtdiehl d9b1f5f
Fixed issue in new code to use only one EagleReader instance
gtdiehl 1c0e6c1
Resolve comments
gtdiehl b66414d
Resolved comments
gtdiehl 26d7acd
Resolved comments and added Debug statement
gtdiehl fc35470
Added return statements
gtdiehl aeb6637
Fixed typo
gtdiehl d0a0c4c
Resolved comments and added debug statements
gtdiehl 2e79821
Moved get_status method into Data object and decorated it with @stati…
gtdiehl 64326b6
Resolved comments
gtdiehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """The rainforest_eagle component.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "domain": "rainforest_eagle", | ||
| "name": "Rainforest Eagle-200", | ||
| "documentation": "https://www.home-assistant.io/components/rainforest_eagle", | ||
| "requirements": [ | ||
| "eagle200_reader==0.1.4" | ||
| ], | ||
| "dependencies": [], | ||
| "codeowners": ["@gtdiehl"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| """Support for the Rainforest Eagle-200 energy monitor.""" | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| from requests.exceptions import ( | ||
| ConnectionError as ConnectError, HTTPError, Timeout) | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.sensor import PLATFORM_SCHEMA | ||
| from homeassistant.const import ( | ||
| CONF_IP_ADDRESS, CONF_SCAN_INTERVAL, ENERGY_KILO_WATT_HOUR) | ||
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.helpers.entity import Entity | ||
| from homeassistant.util import Throttle | ||
|
|
||
| CONF_CLOUD_ID = 'cloud_id' | ||
| CONF_INSTALL_CODE = 'install_code' | ||
| POWER_KILO_WATT = 'kW' | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| SCAN_INTERVAL = timedelta(seconds=30) | ||
|
|
||
| SENSORS = { | ||
| "instantanous_demand": ( | ||
| "Eagle-200 Meter Power Demand", POWER_KILO_WATT), | ||
| "summation_delivered": ( | ||
| "Eagle-200 Total Meter Energy Delivered", | ||
| ENERGY_KILO_WATT_HOUR), | ||
| "summation_received": ( | ||
| "Eagle-200 Total Meter Energy Received", | ||
| ENERGY_KILO_WATT_HOUR), | ||
| "summation_total": ( | ||
| "Eagle-200 Net Meter Energy (Delivered minus Received)", | ||
| ENERGY_KILO_WATT_HOUR) | ||
| } | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_IP_ADDRESS): cv.string, | ||
| vol.Required(CONF_CLOUD_ID): cv.string, | ||
| vol.Required(CONF_INSTALL_CODE): cv.string | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
| """Create the Eagle-200 sensor.""" | ||
| ip_address = config[CONF_IP_ADDRESS] | ||
| cloud_id = config[CONF_CLOUD_ID] | ||
| install_code = config[CONF_INSTALL_CODE] | ||
| interval = config.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL) | ||
|
|
||
| eagle_data = EagleData(ip_address, cloud_id, install_code, interval) | ||
| eagle_data.update() | ||
|
|
||
| monitored_conditions = list(SENSORS) | ||
| sensors = [] | ||
| for condition in monitored_conditions: | ||
| sensors.append(EagleSensor( | ||
| eagle_data, condition, SENSORS[condition][0], | ||
| SENSORS[condition][1])) | ||
|
|
||
| add_devices(sensors) | ||
|
|
||
|
|
||
| class EagleSensor(Entity): | ||
| """Implementation of the Rainforest Eagle-200 sensor.""" | ||
|
|
||
| def __init__( | ||
| self, eagle_data, sensor_type, name, unit): | ||
| """Initialize the sensor.""" | ||
| self.eagle_data = eagle_data | ||
| self._type = sensor_type | ||
| self._name = name | ||
| self._unit_of_measurement = unit | ||
| 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.""" | ||
| return self._unit_of_measurement | ||
|
|
||
| def update(self): | ||
| """Get the energy information from the Rainforest Eagle.""" | ||
| self.eagle_data.update() | ||
| data = self.eagle_data.data | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
| self._state = self.get_state(data) | ||
|
|
||
| def get_state(self, data): | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
| """Get the sensor value from the dictionary.""" | ||
| if data is None: | ||
| return None | ||
|
|
||
| state = data.get(self._type) | ||
| return state | ||
|
|
||
|
|
||
| class EagleData: | ||
| """Get the latest data from the Eagle-200 device.""" | ||
|
|
||
| def __init__(self, ip_address, cloud_id, install_code, interval): | ||
| """Initialize the data object.""" | ||
| self._ip_address = ip_address | ||
| self._cloud_id = cloud_id | ||
| self._install_code = install_code | ||
| self.interval = interval | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
|
|
||
| self.data = {} | ||
|
|
||
| # Apply throttling to update method using configured interval. | ||
| self.update = Throttle(interval)(self._update) | ||
|
|
||
| def _update(self): | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
| """Get the latest data from the Eagle-200 device.""" | ||
| from eagle200_reader import EagleReader | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
|
|
||
| try: | ||
| eagle_reader = EagleReader( | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
| self._ip_address, self._cloud_id, self._install_code) | ||
|
|
||
| for sensor_type in SENSORS: | ||
| self.data.update({sensor_type: getattr( | ||
| eagle_reader, sensor_type)()}) | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
| except (ConnectError, HTTPError, Timeout, ValueError) as error: | ||
| _LOGGER.error("Unable to connect to the Eagle-200: %s", error) | ||
| self.data = None | ||
|
gtdiehl marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.