mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 16:17:20 +00:00
St*pid mistake.. wrong place
This commit is contained in:
parent
cce4a569e4
commit
f837451633
@ -1,84 +1,60 @@
|
|||||||
"""
|
|
||||||
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 as helpers
|
||||||
import homeassistant.helpers.config_validation as cv
|
import logging
|
||||||
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__)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
STATE_VAR = 'rainbird.activestation'
|
||||||
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(CONF_HOST)
|
server = config[DOMAIN].get('stickip')
|
||||||
password = config[DOMAIN].get(CONF_PASSWORD)
|
password = config[DOMAIN].get('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 set to " + str(server))
|
_LOGGER.info("Rainbird Controller setup 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():
|
def stopirrigation(call):
|
||||||
"""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")
|
||||||
elif result == 0:
|
print("Success")
|
||||||
|
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
|
||||||
|
|
||||||
@ -90,9 +66,8 @@ def setup(hass, config):
|
|||||||
hass.services.register(DOMAIN, 'stop_irrigation', stopirrigation)
|
hass.services.register(DOMAIN, 'stop_irrigation', stopirrigation)
|
||||||
|
|
||||||
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,
|
year=None, month=None, day=None, hour=None, minute=None, second=[00,30]
|
||||||
hour=None, minute=None, second=[00, 30]
|
|
||||||
)
|
)
|
||||||
_LOGGER.info("Initialized Rainbird Controller")
|
_LOGGER.info("Initialized Rainbird Controller")
|
||||||
|
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
import homeassistant.helpers as helpers
|
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
REQUIREMENTS = ['pyrainbird==0.0.7']
|
|
||||||
|
|
||||||
# Home Assistant Setup
|
|
||||||
DOMAIN = 'rainbird'
|
|
||||||
|
|
||||||
SERVER = ''
|
|
||||||
PASSWORD = ''
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
STATE_VAR = 'rainbird.activestation'
|
|
||||||
|
|
||||||
def setup(hass, config):
|
|
||||||
|
|
||||||
server = config[DOMAIN].get('stickip')
|
|
||||||
password = config[DOMAIN].get('password')
|
|
||||||
|
|
||||||
# RainbirdSetup
|
|
||||||
from pyrainbird import RainbirdController
|
|
||||||
|
|
||||||
controller = RainbirdController(_LOGGER)
|
|
||||||
controller.setConfig(server, password)
|
|
||||||
_LOGGER.info("Rainbird Controller setup to " + str(server))
|
|
||||||
|
|
||||||
def startirrigation(call):
|
|
||||||
station_id = call.data.get('station')
|
|
||||||
duration = call.data.get('duration')
|
|
||||||
_LOGGER.info("Requesting irrigation for " +
|
|
||||||
str(station_id) + " duration " + str(duration))
|
|
||||||
result = controller.startIrrigation(station_id, duration)
|
|
||||||
if (result == 1):
|
|
||||||
_LOGGER.info("Irrigation started on " + str(station_id) +
|
|
||||||
" for " + str(duration))
|
|
||||||
elif (result == 0):
|
|
||||||
_LOGGER.error("Error sending request")
|
|
||||||
else:
|
|
||||||
_LOGGER.error("Request was not acknowledged!")
|
|
||||||
|
|
||||||
def stopirrigation(call):
|
|
||||||
_LOGGER.info("Stop request irrigation")
|
|
||||||
result = controller.stopIrrigation()
|
|
||||||
if (result == 1):
|
|
||||||
_LOGGER.info("Stopped irrigation")
|
|
||||||
print("Success")
|
|
||||||
elif (result == 0):
|
|
||||||
_LOGGER.error("Error sending request")
|
|
||||||
else:
|
|
||||||
_LOGGER.error("Request was not acknowledged!")
|
|
||||||
|
|
||||||
def getirrigation():
|
|
||||||
_LOGGER.info("Request irrigation state")
|
|
||||||
result = controller.currentIrrigation()
|
|
||||||
if (result < 0):
|
|
||||||
_LOGGER.error("Error sending request")
|
|
||||||
return -1
|
|
||||||
|
|
||||||
return result
|
|
||||||
initialstatus = getirrigation()
|
|
||||||
hass.states.set(STATE_VAR, initialstatus)
|
|
||||||
|
|
||||||
hass.services.register(DOMAIN, 'start_irrigation', startirrigation)
|
|
||||||
hass.services.register(DOMAIN, 'stop_irrigation', stopirrigation)
|
|
||||||
|
|
||||||
helpers.event.track_time_change(
|
|
||||||
hass, lambda _: hass.states.set(STATE_VAR, getirrigation()),
|
|
||||||
year=None, month=None, day=None, hour=None, minute=None, second=[00,30]
|
|
||||||
)
|
|
||||||
_LOGGER.info("Initialized Rainbird Controller")
|
|
||||||
|
|
||||||
return True
|
|
Loading…
x
Reference in New Issue
Block a user