diff --git a/CODEOWNERS b/CODEOWNERS index a96f3bb5b82374..a805719782782f 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -279,7 +279,7 @@ homeassistant/components/quantum_gateway/* @cisasteelersfan homeassistant/components/qwikswitch/* @kellerza homeassistant/components/rainbird/* @konikvranik homeassistant/components/raincloud/* @vanstinator -homeassistant/components/rainforest_eagle/* @gtdiehl +homeassistant/components/rainforest_eagle/* @gtdiehl @jcalbert homeassistant/components/rainmachine/* @bachya homeassistant/components/random/* @fabaff homeassistant/components/repetier/* @MTrab diff --git a/homeassistant/components/rainforest_eagle/manifest.json b/homeassistant/components/rainforest_eagle/manifest.json index 59e4947f9bb604..cb8e95df42f0a9 100644 --- a/homeassistant/components/rainforest_eagle/manifest.json +++ b/homeassistant/components/rainforest_eagle/manifest.json @@ -2,7 +2,11 @@ "domain": "rainforest_eagle", "name": "Rainforest Eagle-200", "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": [], - "codeowners": ["@gtdiehl"] + "codeowners": ["@gtdiehl", + "@jcalbert"] } diff --git a/homeassistant/components/rainforest_eagle/sensor.py b/homeassistant/components/rainforest_eagle/sensor.py index 315bbdff51b787..99751e63f5b231 100644 --- a/homeassistant/components/rainforest_eagle/sensor.py +++ b/homeassistant/components/rainforest_eagle/sensor.py @@ -4,6 +4,7 @@ from eagle200_reader import EagleReader from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout +from uEagle import Eagle as LegacyReader import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA @@ -49,6 +50,25 @@ ) +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): """Create the Eagle-200 sensor.""" 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] 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: _LOGGER.error("Failed to connect during setup: %s", error) return @@ -138,3 +158,21 @@ def get_state(self, sensor_type): state = self.data.get(sensor_type) _LOGGER.debug("Updating: %s - %s", sensor_type, 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 diff --git a/requirements_all.txt b/requirements_all.txt index 548ad2bd7ea756..e8f6342d3010b8 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2008,6 +2008,9 @@ twentemilieu==0.2.0 # homeassistant.components.twilio twilio==6.32.0 +# homeassistant.components.rainforest_eagle +uEagle==0.0.1 + # homeassistant.components.unifiled unifiled==0.11