Add rainforest_eagle support for legacy hardware (#28082)

* Add compatibility with Legacy EAGLE models.

* added mdns resultion via zeroconf

* Added requirements to requirements_all.txt

* Fixed model determination bug

* Fixed formatting issue for Eagle-200 responses.

* Remove mDNS resolution, IP now required.

* added pypi deps, fixed handling of optional params

manifest updates

* Fixed import order per isort.

* Two pylint fixes.

* More consistent try-fail structure to guessing hardware.  Errors actually fail.
This commit is contained in:
Joseph Albert 2020-02-16 00:10:04 -05:00 committed by GitHub
parent f6d9e6b6c5
commit fee0d8dbdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 4 deletions

View File

@ -279,7 +279,7 @@ homeassistant/components/quantum_gateway/* @cisasteelersfan
homeassistant/components/qwikswitch/* @kellerza homeassistant/components/qwikswitch/* @kellerza
homeassistant/components/rainbird/* @konikvranik homeassistant/components/rainbird/* @konikvranik
homeassistant/components/raincloud/* @vanstinator homeassistant/components/raincloud/* @vanstinator
homeassistant/components/rainforest_eagle/* @gtdiehl homeassistant/components/rainforest_eagle/* @gtdiehl @jcalbert
homeassistant/components/rainmachine/* @bachya homeassistant/components/rainmachine/* @bachya
homeassistant/components/random/* @fabaff homeassistant/components/random/* @fabaff
homeassistant/components/repetier/* @MTrab homeassistant/components/repetier/* @MTrab

View File

@ -2,7 +2,11 @@
"domain": "rainforest_eagle", "domain": "rainforest_eagle",
"name": "Rainforest Eagle-200", "name": "Rainforest Eagle-200",
"documentation": "https://www.home-assistant.io/integrations/rainforest_eagle", "documentation": "https://www.home-assistant.io/integrations/rainforest_eagle",
"requirements": ["eagle200_reader==0.2.1"], "requirements": [
"eagle200_reader==0.2.1",
"uEagle==0.0.1"
],
"dependencies": [], "dependencies": [],
"codeowners": ["@gtdiehl"] "codeowners": ["@gtdiehl",
"@jcalbert"]
} }

View File

@ -4,6 +4,7 @@ import logging
from eagle200_reader import EagleReader from eagle200_reader import EagleReader
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
from uEagle import Eagle as LegacyReader
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
@ -49,6 +50,25 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
) )
def hwtest(cloud_id, install_code, ip_address):
"""Try API call 'get_network_info' to see if target device is Legacy or Eagle-200."""
reader = LeagleReader(cloud_id, install_code, ip_address)
response = reader.get_network_info()
# Branch to test if target is Legacy Model
if "NetworkInfo" in response:
if response["NetworkInfo"].get("ModelId", None) == "Z109-EAGLE":
return reader
# Branch to test if target is Eagle-200 Model
if "Response" in response:
if response["Response"].get("Command", None) == "get_network_info":
return EagleReader(ip_address, cloud_id, install_code)
# Catch-all if hardware ID tests fail
raise ValueError("Couldn't determine device model.")
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Create the Eagle-200 sensor.""" """Create the Eagle-200 sensor."""
ip_address = config[CONF_IP_ADDRESS] ip_address = config[CONF_IP_ADDRESS]
@ -56,7 +76,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
install_code = config[CONF_INSTALL_CODE] install_code = config[CONF_INSTALL_CODE]
try: try:
eagle_reader = EagleReader(ip_address, cloud_id, install_code) eagle_reader = hwtest(cloud_id, install_code, ip_address)
except (ConnectError, HTTPError, Timeout, ValueError) as error: except (ConnectError, HTTPError, Timeout, ValueError) as error:
_LOGGER.error("Failed to connect during setup: %s", error) _LOGGER.error("Failed to connect during setup: %s", error)
return return
@ -138,3 +158,21 @@ class EagleData:
state = self.data.get(sensor_type) state = self.data.get(sensor_type)
_LOGGER.debug("Updating: %s - %s", sensor_type, state) _LOGGER.debug("Updating: %s - %s", sensor_type, state)
return state return state
class LeagleReader(LegacyReader):
"""Wraps uEagle to make it behave like eagle_reader, offering update()."""
def update(self):
"""Fetch and return the four sensor values in a dict."""
out = {}
resp = self.get_instantaneous_demand()["InstantaneousDemand"]
out["instantanous_demand"] = resp["Demand"]
resp = self.get_current_summation()["CurrentSummation"]
out["summation_delivered"] = resp["SummationDelivered"]
out["summation_received"] = resp["SummationReceived"]
out["summation_total"] = out["summation_delivered"] - out["summation_received"]
return out

View File

@ -2008,6 +2008,9 @@ twentemilieu==0.2.0
# homeassistant.components.twilio # homeassistant.components.twilio
twilio==6.32.0 twilio==6.32.0
# homeassistant.components.rainforest_eagle
uEagle==0.0.1
# homeassistant.components.unifiled # homeassistant.components.unifiled
unifiled==0.11 unifiled==0.11