Recommit corrected

Recommit corrected
This commit is contained in:
J.J.Barrancos 2017-08-25 17:04:38 +02:00
parent f837451633
commit 21cca21124

View File

@ -1,60 +1,84 @@
import homeassistant.helpers as helpers """
import logging Support for Rainbird Irrigation system WiFi LNK 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 as helpers
import homeassistant.helpers.config_validation as cv
from homeassistant.const import (
CONF_HOST, CONF_PASSWORD)
REQUIREMENTS = ['pyrainbird==0.0.7'] REQUIREMENTS = ['pyrainbird==0.0.7']
# Home Assistant Setup
DOMAIN = 'rainbird' DOMAIN = 'rainbird'
STATE_VAR = 'rainbird.activestation'
SERVER = ''
PASSWORD = ''
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
STATE_VAR = 'rainbird.activestation' 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): def setup(hass, config):
"""Set up the Rainbird component."""
server = config[DOMAIN].get('stickip') server = config[DOMAIN].get(CONF_HOST)
password = config[DOMAIN].get('password') password = config[DOMAIN].get(CONF_PASSWORD)
# RainbirdSetup # RainbirdSetup
from pyrainbird import RainbirdController from pyrainbird import RainbirdController
controller = RainbirdController(_LOGGER) controller = RainbirdController(_LOGGER)
controller.setConfig(server, password) controller.setConfig(server, password)
_LOGGER.info("Rainbird Controller setup to " + str(server)) _LOGGER.info("Rainbird Controller set to " + str(server))
def startirrigation(call): def startirrigation(call):
"""
Start Irrigation command towards Rainbird WiFi LNK stick.
@param call: should be a home assistant call object with data
station for Zone to sprinkle and duration for the time
"""
station_id = call.data.get('station') station_id = call.data.get('station')
duration = call.data.get('duration') duration = call.data.get('duration')
_LOGGER.info("Requesting irrigation for " + _LOGGER.info("Requesting irrigation for " +
str(station_id) + " duration " + str(duration)) str(station_id) + " duration " + str(duration))
result = controller.startIrrigation(station_id, duration) result = controller.startIrrigation(station_id, duration)
if (result == 1): if result == 1:
_LOGGER.info("Irrigation started on " + str(station_id) + _LOGGER.info("Irrigation started on " + str(station_id) +
" for " + str(duration)) " for " + str(duration))
elif (result == 0): elif result == 0:
_LOGGER.error("Error sending request") _LOGGER.error("Error sending request")
else: else:
_LOGGER.error("Request was not acknowledged!") _LOGGER.error("Request was not acknowledged!")
def stopirrigation(call): def stopirrigation():
"""Stop the irrigation (if one is running)."""
_LOGGER.info("Stop request irrigation") _LOGGER.info("Stop request irrigation")
result = controller.stopIrrigation() result = controller.stopIrrigation()
if (result == 1): if result == 1:
_LOGGER.info("Stopped irrigation") _LOGGER.info("Stopped irrigation")
print("Success") elif result == 0:
elif (result == 0):
_LOGGER.error("Error sending request") _LOGGER.error("Error sending request")
else: else:
_LOGGER.error("Request was not acknowledged!") _LOGGER.error("Request was not acknowledged!")
def getirrigation(): def getirrigation():
"""
Get current active station.
@return: integer which station is active
"""
_LOGGER.info("Request irrigation state") _LOGGER.info("Request irrigation state")
result = controller.currentIrrigation() result = controller.currentIrrigation()
if (result < 0): if result < 0:
_LOGGER.error("Error sending request") _LOGGER.error("Error sending request")
return -1 return -1
@ -67,7 +91,8 @@ def setup(hass, config):
helpers.event.track_time_change( helpers.event.track_time_change(
hass, lambda _: hass.states.set(STATE_VAR, getirrigation()), hass, lambda _: hass.states.set(STATE_VAR, getirrigation()),
year=None, month=None, day=None, hour=None, minute=None, second=[00,30] year=None, month=None, day=None,
hour=None, minute=None, second=[00, 30]
) )
_LOGGER.info("Initialized Rainbird Controller") _LOGGER.info("Initialized Rainbird Controller")