This commit is contained in:
Paulus Schoutsen 2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View file

@ -3,8 +3,7 @@ import logging
import voluptuous as vol
from homeassistant.components.binary_sensor import (
PLATFORM_SCHEMA, BinarySensorDevice)
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorDevice
from homeassistant.const import CONF_MONITORED_CONDITIONS
import homeassistant.helpers.config_validation as cv
@ -12,10 +11,13 @@ from . import BINARY_SENSORS, DATA_RAINCLOUD, ICON_MAP, RainCloudEntity
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(BINARY_SENSORS)):
vol.All(cv.ensure_list, [vol.In(BINARY_SENSORS)]),
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(BINARY_SENSORS)): vol.All(
cv.ensure_list, [vol.In(BINARY_SENSORS)]
)
}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
@ -24,12 +26,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
sensors = []
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
if sensor_type == 'status':
if sensor_type == "status":
sensors.append(RainCloudBinarySensor(raincloud.controller, sensor_type))
sensors.append(
RainCloudBinarySensor(raincloud.controller, sensor_type))
sensors.append(
RainCloudBinarySensor(raincloud.controller.faucet,
sensor_type))
RainCloudBinarySensor(raincloud.controller.faucet, sensor_type)
)
else:
# create a sensor for each zone managed by faucet
@ -52,14 +53,14 @@ class RainCloudBinarySensor(RainCloudEntity, BinarySensorDevice):
"""Get the latest data and updates the state."""
_LOGGER.debug("Updating RainCloud sensor: %s", self._name)
self._state = getattr(self.data, self._sensor_type)
if self._sensor_type == 'status':
self._state = self._state == 'Online'
if self._sensor_type == "status":
self._state = self._state == "Online"
@property
def icon(self):
"""Return the icon of this device."""
if self._sensor_type == 'is_watering':
return 'mdi:water' if self.is_on else 'mdi:water-off'
if self._sensor_type == 'status':
return 'mdi:pipe' if self.is_on else 'mdi:pipe-disconnected'
if self._sensor_type == "is_watering":
return "mdi:water" if self.is_on else "mdi:water-off"
if self._sensor_type == "status":
return "mdi:pipe" if self.is_on else "mdi:pipe-disconnected"
return ICON_MAP.get(self._sensor_type)