Support Hydrawise API v1.4 (#34448)

* Now supports Hydrawise API v1.4

* Removed dependency and codeowners name.

* Update CODEOWNERS to include hydrawise

* Changes made from review comments.

* Clean up update.

* Added device class for timestamp and switch. Consolodate methods to parent class.

* Cap next_cycle at 2 years to prevent time overflow.

* Addressed review comments.

* Updated DEVICE_MAP and icon() based on review comments.
This commit is contained in:
David Ryan 2020-06-21 17:55:47 -04:00 committed by GitHub
parent fed6625324
commit 29adc6a27b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 85 deletions

View file

@ -7,13 +7,7 @@ from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensor
from homeassistant.const import CONF_MONITORED_CONDITIONS
import homeassistant.helpers.config_validation as cv
from . import (
BINARY_SENSORS,
DATA_HYDRAWISE,
DEVICE_MAP,
DEVICE_MAP_INDEX,
HydrawiseEntity,
)
from . import BINARY_SENSORS, DATA_HYDRAWISE, HydrawiseEntity
_LOGGER = logging.getLogger(__name__)
@ -32,17 +26,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
sensors = []
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
if sensor_type in ["status", "rain_sensor"]:
if sensor_type == "status":
sensors.append(
HydrawiseBinarySensor(hydrawise.controller_status, sensor_type)
HydrawiseBinarySensor(hydrawise.current_controller, sensor_type)
)
else:
# create a sensor for each zone
for zone in hydrawise.relays:
zone_data = zone
zone_data["running"] = hydrawise.controller_status.get("running", False)
sensors.append(HydrawiseBinarySensor(zone_data, sensor_type))
sensors.append(HydrawiseBinarySensor(zone, sensor_type))
add_entities(sensors, True)
@ -61,21 +52,6 @@ class HydrawiseBinarySensor(HydrawiseEntity, BinarySensorEntity):
mydata = self.hass.data[DATA_HYDRAWISE].data
if self._sensor_type == "status":
self._state = mydata.status == "All good!"
elif self._sensor_type == "rain_sensor":
for sensor in mydata.sensors:
if sensor["name"] == "Rain":
self._state = sensor["active"] == 1
elif self._sensor_type == "is_watering":
if not mydata.running:
self._state = False
elif int(mydata.running[0]["relay"]) == self.data["relay"]:
self._state = True
else:
self._state = False
@property
def device_class(self):
"""Return the device class of the sensor type."""
return DEVICE_MAP[self._sensor_type][
DEVICE_MAP_INDEX.index("DEVICE_CLASS_INDEX")
]
relay_data = mydata.relays[self.data["relay"] - 1]
self._state = relay_data["timestr"] == "Now"