Added rainsensor (#11023)

* Added rainsensor

Added rainsensor

* Added to coverage ignore

* Fixed issues

* script\gen_requirements_all.py

script\gen_requirements_all.py

* Gen requirements

* requirements

* requirements

* Fix docstring

* Fix log message

* Revert change
This commit is contained in:
Jordy 2017-12-25 10:07:18 +01:00 committed by Fabian Affolter
parent 94ac0b5ed8
commit 7269070d97
5 changed files with 137 additions and 24 deletions

View file

@ -477,6 +477,7 @@ omit =
homeassistant/components/notify/yessssms.py homeassistant/components/notify/yessssms.py
homeassistant/components/nuimo_controller.py homeassistant/components/nuimo_controller.py
homeassistant/components/prometheus.py homeassistant/components/prometheus.py
homeassistant/components/rainbird.py
homeassistant/components/remember_the_milk/__init__.py homeassistant/components/remember_the_milk/__init__.py
homeassistant/components/remote/harmony.py homeassistant/components/remote/harmony.py
homeassistant/components/remote/itach.py homeassistant/components/remote/itach.py
@ -571,6 +572,7 @@ omit =
homeassistant/components/sensor/pyload.py homeassistant/components/sensor/pyload.py
homeassistant/components/sensor/qnap.py homeassistant/components/sensor/qnap.py
homeassistant/components/sensor/radarr.py homeassistant/components/sensor/radarr.py
homeassistant/components/sensor/rainbird.py
homeassistant/components/sensor/ripple.py homeassistant/components/sensor/ripple.py
homeassistant/components/sensor/sabnzbd.py homeassistant/components/sensor/sabnzbd.py
homeassistant/components/sensor/scrape.py homeassistant/components/sensor/scrape.py

View file

@ -0,0 +1,47 @@
"""
Support for Rain Bird Irrigation system LNK WiFi Module.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/rainbird/
"""
import logging
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.const import (CONF_HOST, CONF_PASSWORD)
REQUIREMENTS = ['pyrainbird==0.1.3']
_LOGGER = logging.getLogger(__name__)
DATA_RAINBIRD = 'rainbird'
DOMAIN = 'rainbird'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
}),
}, extra=vol.ALLOW_EXTRA)
def setup(hass, config):
"""Set up the Rain Bird componenent."""
conf = config[DOMAIN]
server = conf.get(CONF_HOST)
password = conf.get(CONF_PASSWORD)
from pyrainbird import RainbirdController
controller = RainbirdController()
controller.setConfig(server, password)
_LOGGER.debug("Rain Bird Controller set to: %s", server)
initialstatus = controller.currentIrrigation()
if initialstatus == -1:
_LOGGER.error("Error getting state. Possible configuration issues")
return False
hass.data[DATA_RAINBIRD] = controller
return True

View file

@ -0,0 +1,80 @@
"""
Support for Rain Bird Irrigation system LNK WiFi Module.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/sensor.rainbird/
"""
import logging
import voluptuous as vol
from homeassistant.components.rainbird import DATA_RAINBIRD
import homeassistant.helpers.config_validation as cv
from homeassistant.const import CONF_MONITORED_CONDITIONS
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.helpers.entity import Entity
DEPENDENCIES = ['rainbird']
_LOGGER = logging.getLogger(__name__)
# sensor_type [ description, unit, icon ]
SENSOR_TYPES = {
'rainsensor': ['Rainsensor', None, 'mdi:water']
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SENSOR_TYPES)):
vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up a Rain Bird sensor."""
controller = hass.data[DATA_RAINBIRD]
sensors = []
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
sensors.append(
RainBirdSensor(controller, sensor_type))
add_devices(sensors, True)
class RainBirdSensor(Entity):
"""A sensor implementation for Rain Bird device."""
def __init__(self, controller, sensor_type):
"""Initialize the Rain Bird sensor."""
self._sensor_type = sensor_type
self._controller = controller
self._name = SENSOR_TYPES[self._sensor_type][0]
self._icon = SENSOR_TYPES[self._sensor_type][2]
self._unit_of_measurement = SENSOR_TYPES[self._sensor_type][1]
self._state = None
@property
def state(self):
"""Return the state of the sensor."""
return self._state
def update(self):
"""Get the latest data and updates the states."""
_LOGGER.debug("Updating sensor: %s", self._name)
if self._sensor_type == 'rainsensor':
self._state = self._controller.currentRainSensorState()
@property
def name(self):
"""Return the name of this camera."""
return self._name
@property
def unit_of_measurement(self):
"""Return the units of measurement."""
return self._unit_of_measurement
@property
def icon(self):
"""Return icon."""
return self._icon

View file

@ -2,29 +2,26 @@
Support for Rain Bird Irrigation system LNK WiFi Module. Support for Rain Bird Irrigation system LNK WiFi Module.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/rainbird/ https://home-assistant.io/components/switch.rainbird/
""" """
import logging import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.components.rainbird import DATA_RAINBIRD
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA) from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, from homeassistant.const import (CONF_SWITCHES, CONF_ZONE,
CONF_FRIENDLY_NAME, CONF_TRIGGER_TIME, CONF_FRIENDLY_NAME, CONF_TRIGGER_TIME,
CONF_SCAN_INTERVAL, CONF_HOST, CONF_PASSWORD) CONF_SCAN_INTERVAL)
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.exceptions import PlatformNotReady
REQUIREMENTS = ['pyrainbird==0.1.0'] DEPENDENCIES = ['rainbird']
DOMAIN = 'rainbird' DOMAIN = 'rainbird'
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_PLATFORM): DOMAIN,
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_SWITCHES, default={}): vol.Schema({ vol.Required(CONF_SWITCHES, default={}): vol.Schema({
cv.string: { cv.string: {
vol.Optional(CONF_FRIENDLY_NAME): cv.string, vol.Optional(CONF_FRIENDLY_NAME): cv.string,
@ -38,20 +35,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Rain Bird switches over a Rain Bird controller.""" """Set up Rain Bird switches over a Rain Bird controller."""
server = config.get(CONF_HOST) controller = hass.data[DATA_RAINBIRD]
password = config.get(CONF_PASSWORD)
from pyrainbird import RainbirdController
controller = RainbirdController(_LOGGER)
controller.setConfig(server, password)
_LOGGER.debug("Rain Bird Controller set to " + str(server))
if controller.currentIrrigation() == -1:
_LOGGER.error("Error getting state. Possible configuration issues")
raise PlatformNotReady
else:
_LOGGER.debug("Initialized Rain Bird Controller")
devices = [] devices = []
for dev_id, switch in config.get(CONF_SWITCHES).items(): for dev_id, switch in config.get(CONF_SWITCHES).items():

View file

@ -799,8 +799,8 @@ pyowm==2.7.1
# homeassistant.components.qwikswitch # homeassistant.components.qwikswitch
pyqwikswitch==0.4 pyqwikswitch==0.4
# homeassistant.components.switch.rainbird # homeassistant.components.rainbird
pyrainbird==0.1.0 pyrainbird==0.1.3
# homeassistant.components.climate.sensibo # homeassistant.components.climate.sensibo
pysensibo==1.0.1 pysensibo==1.0.1