From c286e2c4343c7018c044f589064b10010d999374 Mon Sep 17 00:00:00 2001 From: jbarrancos <31309880+jbarrancos@users.noreply.github.com> Date: Thu, 24 Aug 2017 18:30:36 +0200 Subject: [PATCH 01/33] Rainbird WiFi LNK Irrigation Implementation This is a component which adds support for the Rainbird WiFi LNK Irragation system. --- homeassistant/components/rainbird.py | 105 +++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 homeassistant/components/rainbird.py diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py new file mode 100644 index 00000000000..255e5af5fb5 --- /dev/null +++ b/homeassistant/components/rainbird.py @@ -0,0 +1,105 @@ +import homeassistant.loader as loader +import homeassistant.helpers as helpers +from homeassistant.helpers.entity import Entity +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') + totalstations= config[DOMAIN].get('totalstations') + + # 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 + +class Rainbird(Entity): + """The base class for raibird entities.""" + + def __init__(self,hass,stationid,name): + self._id=stationid + self._name=name + + @property + def should_poll(self): + return True + + @property + def state(self): + return self_state + + def name(self): + return self._name + + def id(self): + return self._id + + @property + def state_attributes(self): + attr = { + 'zone_id': self.stationid, + } + + return attr From c4f4e492e53b84f362998ae2fa1aff6f86ae749b Mon Sep 17 00:00:00 2001 From: jbarrancos <31309880+jbarrancos@users.noreply.github.com> Date: Thu, 24 Aug 2017 18:41:25 +0200 Subject: [PATCH 02/33] Removed some whitelines Removed some whitelines --- homeassistant/components/rainbird.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index 255e5af5fb5..1097b1ca93b 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -19,18 +19,18 @@ STATE_VAR='rainbird.activestation' def setup(hass, config): - + server = config[DOMAIN].get('stickip') password = config[DOMAIN].get('password') totalstations= config[DOMAIN].get('totalstations') - + # 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') @@ -42,7 +42,7 @@ def setup(hass, config): _LOGGER.error("Error sending request") else: _LOGGER.error("Request was not acknowledged!") - + def stopirrigation(call): _LOGGER.info("Stop request irrigation") result = controller.stopIrrigation() @@ -53,7 +53,7 @@ def setup(hass, config): _LOGGER.error("Error sending request") else: _LOGGER.error("Request was not acknowledged!") - + def getirrigation(): _LOGGER.info("Request irrigation state") result=controller.currentIrrigation() @@ -69,10 +69,10 @@ def setup(hass, config): 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 class Rainbird(Entity): @@ -81,7 +81,7 @@ class Rainbird(Entity): def __init__(self,hass,stationid,name): self._id=stationid self._name=name - + @property def should_poll(self): return True @@ -89,10 +89,10 @@ class Rainbird(Entity): @property def state(self): return self_state - + def name(self): return self._name - + def id(self): return self._id From 6c6ed293298d7c3bf0431008f45854ee9dd9d911 Mon Sep 17 00:00:00 2001 From: jbarrancos <31309880+jbarrancos@users.noreply.github.com> Date: Thu, 24 Aug 2017 22:35:30 +0200 Subject: [PATCH 03/33] Fixed some markup and removed not yet needed class Fixed issues during hound run (markup) and a class which is obsolete --- homeassistant/components/rainbird.py | 53 ++++++++-------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index 1097b1ca93b..d2b01cee0ae 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -28,16 +28,18 @@ def setup(hass, config): from pyrainbird import RainbirdController controller = RainbirdController(_LOGGER) - controller.setConfig(server,password) + 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) + 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)) + _LOGGER.info("Irrigation started on "+str(station_id)+\ + " for " + str(duration)) elif (result == 0): _LOGGER.error("Error sending request") else: @@ -48,7 +50,7 @@ def setup(hass, config): result = controller.stopIrrigation() if (result == 1): _LOGGER.info("Stopped irrigation") - print ("Success") + print("Success") elif (result == 0): _LOGGER.error("Error sending request") else: @@ -56,7 +58,7 @@ def setup(hass, config): def getirrigation(): _LOGGER.info("Request irrigation state") - result=controller.currentIrrigation() + result = controller.currentIrrigation() if (result < 0): _LOGGER.error("Error sending request") return -1 @@ -64,42 +66,15 @@ def setup(hass, config): 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]) + 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 - -class Rainbird(Entity): - """The base class for raibird entities.""" - - def __init__(self,hass,stationid,name): - self._id=stationid - self._name=name - - @property - def should_poll(self): - return True - - @property - def state(self): - return self_state - - def name(self): - return self._name - - def id(self): - return self._id - - @property - def state_attributes(self): - attr = { - 'zone_id': self.stationid, - } - - return attr From 88098283c75c0c16103c46add4c005db55602f6f Mon Sep 17 00:00:00 2001 From: jbarrancos <31309880+jbarrancos@users.noreply.github.com> Date: Thu, 24 Aug 2017 22:40:45 +0200 Subject: [PATCH 04/33] Markup fixes Markup fixes --- homeassistant/rainbird.py | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 homeassistant/rainbird.py diff --git a/homeassistant/rainbird.py b/homeassistant/rainbird.py new file mode 100644 index 00000000000..4b0ddf2b608 --- /dev/null +++ b/homeassistant/rainbird.py @@ -0,0 +1,74 @@ +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 From e548bd5312095e9f7565c25034ceff011e5495d0 Mon Sep 17 00:00:00 2001 From: jbarrancos <31309880+jbarrancos@users.noreply.github.com> Date: Thu, 24 Aug 2017 22:49:54 +0200 Subject: [PATCH 05/33] PIP8 Fixes PIP8 Fixes --- homeassistant/components/rainbird.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index d2b01cee0ae..836b0c69a62 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -1,6 +1,4 @@ -import homeassistant.loader as loader import homeassistant.helpers as helpers -from homeassistant.helpers.entity import Entity import logging @@ -8,21 +6,17 @@ REQUIREMENTS = ['pyrainbird==0.0.7'] # Home Assistant Setup DOMAIN = 'rainbird' - SERVER = '' PASSWORD = '' +STATE_VAR = 'rainbird.activestation' _LOGGER = logging.getLogger(__name__) -STATE_VAR='rainbird.activestation' - - def setup(hass, config): server = config[DOMAIN].get('stickip') password = config[DOMAIN].get('password') - totalstations= config[DOMAIN].get('totalstations') # RainbirdSetup from pyrainbird import RainbirdController @@ -34,12 +28,12 @@ def setup(hass, config): 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)) + _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)) + _LOGGER.info("Irrigation started on " + str(station_id) + + " for " + str(duration)) elif (result == 0): _LOGGER.error("Error sending request") else: @@ -70,11 +64,11 @@ def setup(hass, config): 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]) - - + 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 From 41a046a69d3c02a436649eb50f920eabefb3192c Mon Sep 17 00:00:00 2001 From: jbarrancos <31309880+jbarrancos@users.noreply.github.com> Date: Fri, 25 Aug 2017 00:08:40 +0200 Subject: [PATCH 06/33] Typo --- homeassistant/components/rainbird.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index 836b0c69a62..5eef9913470 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -23,7 +23,7 @@ def setup(hass, config): controller = RainbirdController(_LOGGER) controller.setConfig(server, password) - _LOGGER.info("Rainbird Controller setup to " + str(server)) + _LOGGER.info("Rainbird Controller set to " + str(server)) def startirrigation(call): station_id = call.data.get('station') From 7aff588bf0022eba27c1a15953779fe5c4c00c59 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Fri, 25 Aug 2017 12:01:32 +0200 Subject: [PATCH 07/33] pylint, coverage and requirement fix pylint, coverage and requirement fix --- .coveragerc | 1 + homeassistant/components/rainbird.py | 56 ++++++++++++++++++++++------ requirements_all.txt | 3 ++ 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/.coveragerc b/.coveragerc index d8041b9fe6c..8b7ffe2e966 100644 --- a/.coveragerc +++ b/.coveragerc @@ -416,6 +416,7 @@ omit = homeassistant/components/notify/xmpp.py homeassistant/components/nuimo_controller.py homeassistant/components/prometheus.py + homeassistant/components/rainbird.py homeassistant/components/remote/harmony.py homeassistant/components/remote/itach.py homeassistant/components/scene/hunterdouglas_powerview.py diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index 5eef9913470..4976b18afc2 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -1,6 +1,20 @@ -import homeassistant.helpers as helpers -import logging +""" +Module for interacting with WiFi LNK module of the Rainbird Irrigation system +This project has no affiliation with Rainbird. This module works with the +Rainbird LNK WiFi Module. For more information see: +http://www.rainbird.com/landscape/products/controllers/LNK-WiFi.htm + +This module communicates directly towards the IP Address of the WiFi module it +does not support the cloud. You can start/stop the irrigation and get the +currenltly active zone. + +I'm not a Python developer, so sorry for the bad code. I've developed it to +control it from my domtica systems. +""" + +import logging +import homeassistant.helpers as helpers REQUIREMENTS = ['pyrainbird==0.0.7'] @@ -14,6 +28,11 @@ _LOGGER = logging.getLogger(__name__) def setup(hass, config): + """ + Standard setup function Home Assistant + @param hass: default homeassistant hass class + @param config: default homeassistant config class + """ server = config[DOMAIN].get('stickip') password = config[DOMAIN].get('password') @@ -26,34 +45,49 @@ def setup(hass, config): _LOGGER.info("Rainbird Controller set to " + str(server)) 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') 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): + if result == 1: _LOGGER.info("Irrigation started on " + str(station_id) + " for " + str(duration)) - elif (result == 0): + elif result == 0: _LOGGER.error("Error sending request") else: _LOGGER.error("Request was not acknowledged!") - def stopirrigation(call): + def stopirrigation(): + """ + Stops the irrigation (if one is running) + """ + _LOGGER.info("Stop request irrigation") result = controller.stopIrrigation() - if (result == 1): + if result == 1: _LOGGER.info("Stopped irrigation") print("Success") - elif (result == 0): + elif result == 0: _LOGGER.error("Error sending request") else: _LOGGER.error("Request was not acknowledged!") def getirrigation(): + """ + Get current active station + @return: integer which station is active + """ + _LOGGER.info("Request irrigation state") result = controller.currentIrrigation() - if (result < 0): + if result < 0: _LOGGER.error("Error sending request") return -1 @@ -65,9 +99,9 @@ def setup(hass, config): 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] + 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") diff --git a/requirements_all.txt b/requirements_all.txt index cf6325e6572..e94ca4ce025 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -686,6 +686,9 @@ pyowm==2.7.1 # homeassistant.components.qwikswitch pyqwikswitch==0.4 +# homeassistant.components.rainbird +pyrainbird==0.0.7 + # homeassistant.components.climate.sensibo pysensibo==1.0.1 From 4feea9d7eca621213196b15fbee99205976314ba Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Fri, 25 Aug 2017 13:26:38 +0200 Subject: [PATCH 08/33] pydocstyle fixes pydocstyle fixes --- homeassistant/components/rainbird.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index 4976b18afc2..a5e55623eb7 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -1,5 +1,5 @@ """ -Module for interacting with WiFi LNK module of the Rainbird Irrigation system +Module for interacting with WiFi LNK module of the Rainbird Irrigation system. This project has no affiliation with Rainbird. This module works with the Rainbird LNK WiFi Module. For more information see: @@ -29,11 +29,11 @@ _LOGGER = logging.getLogger(__name__) def setup(hass, config): """ - Standard setup function Home Assistant + Call from Home Assistant. + @param hass: default homeassistant hass class @param config: default homeassistant config class """ - server = config[DOMAIN].get('stickip') password = config[DOMAIN].get('password') @@ -46,11 +46,11 @@ def setup(hass, config): def startirrigation(call): """ - Start Irrigation command towards Rainbird WiFi LNK stick + 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') duration = call.data.get('duration') _LOGGER.info("Requesting irrigation for " + @@ -65,10 +65,7 @@ def setup(hass, config): _LOGGER.error("Request was not acknowledged!") def stopirrigation(): - """ - Stops the irrigation (if one is running) - """ - + """Stop the irrigation (if one is running).""" _LOGGER.info("Stop request irrigation") result = controller.stopIrrigation() if result == 1: @@ -81,10 +78,10 @@ def setup(hass, config): def getirrigation(): """ - Get current active station + Get current active station. + @return: integer which station is active """ - _LOGGER.info("Request irrigation state") result = controller.currentIrrigation() if result < 0: From cce4a569e47a7764781a36b89e837c8219900441 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Fri, 25 Aug 2017 16:06:49 +0200 Subject: [PATCH 09/33] Changed doc and added default schema --- homeassistant/components/rainbird.py | 40 ++++++++++++---------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index a5e55623eb7..981548ec3dd 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -1,41 +1,36 @@ """ -Module for interacting with WiFi LNK module of the Rainbird Irrigation system. +Support for Rainbird Irrigation system WiFi LNK Module. -This project has no affiliation with Rainbird. This module works with the -Rainbird LNK WiFi Module. For more information see: -http://www.rainbird.com/landscape/products/controllers/LNK-WiFi.htm - -This module communicates directly towards the IP Address of the WiFi module it -does not support the cloud. You can start/stop the irrigation and get the -currenltly active zone. - -I'm not a Python developer, so sorry for the bad code. I've developed it to -control it from my domtica systems. +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'] -# Home Assistant Setup DOMAIN = 'rainbird' -SERVER = '' -PASSWORD = '' STATE_VAR = 'rainbird.activestation' _LOGGER = logging.getLogger(__name__) +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): - """ - Call from Home Assistant. - - @param hass: default homeassistant hass class - @param config: default homeassistant config class - """ - server = config[DOMAIN].get('stickip') - password = config[DOMAIN].get('password') + """Set up the Rainbird component.""" + server = config[DOMAIN].get(CONF_HOST) + password = config[DOMAIN].get(CONF_PASSWORD) # RainbirdSetup from pyrainbird import RainbirdController @@ -70,7 +65,6 @@ def setup(hass, config): result = controller.stopIrrigation() if result == 1: _LOGGER.info("Stopped irrigation") - print("Success") elif result == 0: _LOGGER.error("Error sending request") else: From f83745163326a5c0fc3fe4ecc04e9b62184b41ad Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Fri, 25 Aug 2017 16:59:37 +0200 Subject: [PATCH 10/33] St*pid mistake.. wrong place --- homeassistant/components/rainbird.py | 65 ++++++++---------------- homeassistant/rainbird.py | 74 ---------------------------- 2 files changed, 20 insertions(+), 119 deletions(-) delete mode 100644 homeassistant/rainbird.py diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index 981548ec3dd..4b0ddf2b608 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -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.config_validation as cv -from homeassistant.const import ( - CONF_HOST, CONF_PASSWORD) +import logging + REQUIREMENTS = ['pyrainbird==0.0.7'] +# Home Assistant Setup DOMAIN = 'rainbird' -STATE_VAR = 'rainbird.activestation' + +SERVER = '' +PASSWORD = '' _LOGGER = logging.getLogger(__name__) -CONFIG_SCHEMA = vol.Schema({ - DOMAIN: vol.Schema({ - vol.Required(CONF_HOST): cv.string, - vol.Required(CONF_PASSWORD): cv.string, - }), -}, extra=vol.ALLOW_EXTRA) - +STATE_VAR = 'rainbird.activestation' def setup(hass, config): - """Set up the Rainbird component.""" - server = config[DOMAIN].get(CONF_HOST) - password = config[DOMAIN].get(CONF_PASSWORD) + + 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 set to " + str(server)) + _LOGGER.info("Rainbird Controller setup to " + str(server)) 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') 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: + if (result == 1): _LOGGER.info("Irrigation started on " + str(station_id) + " for " + str(duration)) - elif result == 0: + elif (result == 0): _LOGGER.error("Error sending request") else: _LOGGER.error("Request was not acknowledged!") - def stopirrigation(): - """Stop the irrigation (if one is running).""" + def stopirrigation(call): _LOGGER.info("Stop request irrigation") result = controller.stopIrrigation() - if result == 1: + if (result == 1): _LOGGER.info("Stopped irrigation") - elif result == 0: + print("Success") + elif (result == 0): _LOGGER.error("Error sending request") else: _LOGGER.error("Request was not acknowledged!") def getirrigation(): - """ - Get current active station. - - @return: integer which station is active - """ _LOGGER.info("Request irrigation state") result = controller.currentIrrigation() - if result < 0: + if (result < 0): _LOGGER.error("Error sending request") return -1 @@ -90,9 +66,8 @@ def setup(hass, config): 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] + 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") diff --git a/homeassistant/rainbird.py b/homeassistant/rainbird.py deleted file mode 100644 index 4b0ddf2b608..00000000000 --- a/homeassistant/rainbird.py +++ /dev/null @@ -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 From 21cca21124ba18d1a852cb609bd3dffa15f0e731 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Fri, 25 Aug 2017 17:04:38 +0200 Subject: [PATCH 11/33] Recommit corrected Recommit corrected --- homeassistant/components/rainbird.py | 65 +++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index 4b0ddf2b608..981548ec3dd 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -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'] -# Home Assistant Setup DOMAIN = 'rainbird' - -SERVER = '' -PASSWORD = '' +STATE_VAR = 'rainbird.activestation' _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): - - server = config[DOMAIN].get('stickip') - password = config[DOMAIN].get('password') + """Set up the Rainbird component.""" + server = config[DOMAIN].get(CONF_HOST) + password = config[DOMAIN].get(CONF_PASSWORD) # RainbirdSetup from pyrainbird import RainbirdController controller = RainbirdController(_LOGGER) controller.setConfig(server, password) - _LOGGER.info("Rainbird Controller setup to " + str(server)) + _LOGGER.info("Rainbird Controller set to " + str(server)) 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') 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): + if result == 1: _LOGGER.info("Irrigation started on " + str(station_id) + " for " + str(duration)) - elif (result == 0): + elif result == 0: _LOGGER.error("Error sending request") else: _LOGGER.error("Request was not acknowledged!") - def stopirrigation(call): + def stopirrigation(): + """Stop the irrigation (if one is running).""" _LOGGER.info("Stop request irrigation") result = controller.stopIrrigation() - if (result == 1): + if result == 1: _LOGGER.info("Stopped irrigation") - print("Success") - elif (result == 0): + elif result == 0: _LOGGER.error("Error sending request") else: _LOGGER.error("Request was not acknowledged!") def getirrigation(): + """ + Get current active station. + + @return: integer which station is active + """ _LOGGER.info("Request irrigation state") result = controller.currentIrrigation() - if (result < 0): + if result < 0: _LOGGER.error("Error sending request") return -1 @@ -66,8 +90,9 @@ def setup(hass, config): 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] + 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") From 0eee544d1709ce3029f17fc2d21a8cd2378438f7 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Mon, 28 Aug 2017 17:57:45 +0200 Subject: [PATCH 12/33] Changed component to use entity and switch Changed component to use entity and switch. --- homeassistant/components/rainbird.py | 114 ++++++++++++++------ homeassistant/components/switch/rainbird.py | 97 +++++++++++++++++ 2 files changed, 180 insertions(+), 31 deletions(-) create mode 100644 homeassistant/components/switch/rainbird.py diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index 981548ec3dd..f98e2ba1d61 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -1,5 +1,5 @@ """ -Support for Rainbird Irrigation system WiFi LNK Module. +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/ @@ -7,15 +7,16 @@ 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.exceptions import PlatformNotReady +from homeassistant.helpers.entity_component import EntityComponent +from homeassistant.helpers.entity import Entity from homeassistant.const import ( CONF_HOST, CONF_PASSWORD) REQUIREMENTS = ['pyrainbird==0.0.7'] DOMAIN = 'rainbird' -STATE_VAR = 'rainbird.activestation' _LOGGER = logging.getLogger(__name__) @@ -28,29 +29,95 @@ CONFIG_SCHEMA = vol.Schema({ def setup(hass, config): - """Set up the Rainbird component.""" + """Set up the Rain Bird component.""" server = config[DOMAIN].get(CONF_HOST) password = config[DOMAIN].get(CONF_PASSWORD) + component = EntityComponent(_LOGGER, DOMAIN, hass) - # RainbirdSetup from pyrainbird import RainbirdController controller = RainbirdController(_LOGGER) controller.setConfig(server, password) - _LOGGER.info("Rainbird Controller set to " + str(server)) + _LOGGER.info("Rain Bird Controller set to " + str(server)) - def startirrigation(call): + rbdevice = RainbirdDevice(hass, controller) + hass.data["DATA_RAINBIRD"] = rbdevice + + initialstatus = rbdevice.update() + if initialstatus == -1: + _LOGGER.error("Error getting state. Possible configuration issues") + raise PlatformNotReady + else: + _LOGGER.info("Initialized Rain Bird Controller") + + entities = [] + entities.append(rbdevice) + component.add_entities(entities) + + return True + + +class RainbirdDevice(Entity): + """Rain Bird Device.""" + + _state = -1 + + def __init__(self, hass, controller): + """Initialize the device.""" + self.hass = hass + self.controller = controller + self._name = "Rainbird_Controller" + self._stations = {} + + # For automation purposes add 2 services + def start_irrigation_call(call): + """Start irrigation from service call.""" + station_id = call.data.get("station_id") + duration = call.data.get("duration") + if station_id and duration: + self.start_irrigation(station_id, duration) + else: + _LOGGER.warning("Error in start_irrigation call. \ + station_id and duration need to be set") + + def stop_irrigation_call(call): + """Start irrigation from service call.""" + self.stop_irrigation() + + hass.services.register(DOMAIN, 'start_irrigation', + start_irrigation_call) + hass.services.register(DOMAIN, 'stop_irrigation', + stop_irrigation_call) + + def should_poll(self): + """Return True if entity has to be polled for state.""" + return True + + @property + def name(self): + """Get the name of the device.""" + return self._name + + def available(self): + """Return True if entity is available.""" + return self._state != -1 + + @property + def state(self): + """Return the state of the entity.""" + return self._state + + def start_irrigation(self, station_id, duration): """ - Start Irrigation command towards Rainbird WiFi LNK stick. + Start Irrigation command towards Rain Bird LNK WiFi 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') - duration = call.data.get('duration') _LOGGER.info("Requesting irrigation for " + str(station_id) + " duration " + str(duration)) - result = controller.startIrrigation(station_id, duration) + result = self.controller.startIrrigation( + int(station_id), int(duration)) if result == 1: _LOGGER.info("Irrigation started on " + str(station_id) + " for " + str(duration)) @@ -59,10 +126,10 @@ def setup(hass, config): else: _LOGGER.error("Request was not acknowledged!") - def stopirrigation(): + def stop_irrigation(self): """Stop the irrigation (if one is running).""" _LOGGER.info("Stop request irrigation") - result = controller.stopIrrigation() + result = self.controller.stopIrrigation() if result == 1: _LOGGER.info("Stopped irrigation") elif result == 0: @@ -70,30 +137,15 @@ def setup(hass, config): else: _LOGGER.error("Request was not acknowledged!") - def getirrigation(): + def update(self): """ Get current active station. @return: integer which station is active """ _LOGGER.info("Request irrigation state") - result = controller.currentIrrigation() + result = self.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 + self._state = result diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py new file mode 100644 index 00000000000..5987f45bf22 --- /dev/null +++ b/homeassistant/components/switch/rainbird.py @@ -0,0 +1,97 @@ +""" +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 + +from homeassistant.components import rainbird +from homeassistant.components.switch import SwitchDevice +from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, + CONF_FRIENDLY_NAME, CONF_TRIGGER_TIME, + CONF_SCAN_INTERVAL) +from homeassistant.helpers import config_validation as cv + +DEPENDENCIES = ['rainbird'] + +_LOGGER = logging.getLogger(__name__) + + +PLATFORM_SCHEMA = vol.Schema({ + vol.Required(CONF_PLATFORM): rainbird.DOMAIN, + vol.Required(CONF_SWITCHES, default={}): vol.Schema({ + cv.string: { + vol.Optional(CONF_FRIENDLY_NAME): cv.string, + vol.Required(CONF_ZONE): cv.string, + vol.Required(CONF_TRIGGER_TIME): cv.string, + vol.Optional(CONF_SCAN_INTERVAL): cv.string, + }, + }), +}) + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up Rain Bird switches over a Rain Bird controller.""" + devices = [] + rbdevice = hass.data.get("DATA_RAINBIRD") + for key, switch in config.get(CONF_SWITCHES).items(): + devices.append(RainBirdSwitch(rbdevice, switch)) + add_devices(devices) + return True + + +class RainBirdSwitch(SwitchDevice): + """Representation of a Rain Bird switch.""" + + def __init__(self, rb, dev): + """Initialize a Rain Bird Switch Device.""" + self._rainbird = rb + self._zone = int(dev.get(CONF_ZONE)) + self._name = dev.get(CONF_FRIENDLY_NAME, "Sprinker %s" % self._zone) + self._state = self.get_device_status() + self._duration = dev.get(CONF_TRIGGER_TIME) + self._attributes = { + "duration": self._duration, + } + + @property + def device_state_attributes(self): + """Return state attributes.""" + return self._attributes + + @property + def should_poll(self): + """Return the polling state.""" + return True + + @property + def name(self): + """Get the name of the switch.""" + return self._name + + def turn_on(self, **kwargs): + """Turn the switch on.""" + self._state = True + self._rainbird.start_irrigation(self._zone, self._duration) + + def turn_off(self, **kwargs): + """Turn the switch off.""" + self._state = False + self._rainbird.stop_irrigation() + + def get_device_status(self): + """Get the status of the switch from Rain Bird Controller.""" + return self._rainbird.state == self._zone + + def update(self): + """Update switch status.""" + self._state = self.get_device_status() + + @property + def is_on(self): + """Return true if switch is on.""" + return self._state From 51c6029fe55aaccf07f6bf30df9be2ca14a352d0 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Mon, 28 Aug 2017 21:07:40 +0200 Subject: [PATCH 13/33] Fixed issue with missing key --- homeassistant/components/switch/rainbird.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 5987f45bf22..f951f257560 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -38,8 +38,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up Rain Bird switches over a Rain Bird controller.""" devices = [] rbdevice = hass.data.get("DATA_RAINBIRD") - for key, switch in config.get(CONF_SWITCHES).items(): - devices.append(RainBirdSwitch(rbdevice, switch)) + for dev_id, switch in config.get(CONF_SWITCHES).items(): + devices.append(RainBirdSwitch(rbdevice, switch, dev_id)) add_devices(devices) return True @@ -47,9 +47,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class RainBirdSwitch(SwitchDevice): """Representation of a Rain Bird switch.""" - def __init__(self, rb, dev): + def __init__(self, rb, dev, dev_id): """Initialize a Rain Bird Switch Device.""" self._rainbird = rb + self._devid = dev_id self._zone = int(dev.get(CONF_ZONE)) self._name = dev.get(CONF_FRIENDLY_NAME, "Sprinker %s" % self._zone) self._state = self.get_device_status() From 689484216d73383ddedb8e89c29442db933f91b8 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Tue, 29 Aug 2017 13:45:18 +0200 Subject: [PATCH 14/33] Using latest module and fixed state issue - pyrainbird 0.0.9 allows the override (if ever needed) connection retry/sleep - Forces state towards the Entity when switching the switches. Gives better UI experience. --- homeassistant/components/rainbird.py | 6 +++++- homeassistant/components/switch/rainbird.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py index f98e2ba1d61..48a40cc30fe 100644 --- a/homeassistant/components/rainbird.py +++ b/homeassistant/components/rainbird.py @@ -14,7 +14,7 @@ from homeassistant.helpers.entity import Entity from homeassistant.const import ( CONF_HOST, CONF_PASSWORD) -REQUIREMENTS = ['pyrainbird==0.0.7'] +REQUIREMENTS = ['pyrainbird==0.0.9'] DOMAIN = 'rainbird' @@ -102,6 +102,10 @@ class RainbirdDevice(Entity): """Return True if entity is available.""" return self._state != -1 + def setstate(self, state): + """Force set the current state value.""" + self._state = state + @property def state(self): """Return the state of the entity.""" diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index f951f257560..f341f1324f6 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -57,6 +57,7 @@ class RainBirdSwitch(SwitchDevice): self._duration = dev.get(CONF_TRIGGER_TIME) self._attributes = { "duration": self._duration, + "zone" : self._zone } @property @@ -78,11 +79,13 @@ class RainBirdSwitch(SwitchDevice): """Turn the switch on.""" self._state = True self._rainbird.start_irrigation(self._zone, self._duration) + self._rainbird.setstate(self._zone) def turn_off(self, **kwargs): """Turn the switch off.""" self._state = False self._rainbird.stop_irrigation() + self._rainbird.setstate(0) def get_device_status(self): """Get the status of the switch from Rain Bird Controller.""" From df1c3dfb67a6513e629678eddba489808b78251a Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Tue, 29 Aug 2017 13:47:47 +0200 Subject: [PATCH 15/33] Hound issue "whitespace" --- homeassistant/components/switch/rainbird.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index f341f1324f6..70072db65da 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -57,7 +57,7 @@ class RainBirdSwitch(SwitchDevice): self._duration = dev.get(CONF_TRIGGER_TIME) self._attributes = { "duration": self._duration, - "zone" : self._zone + "zone": self._zone } @property From 67007aed403a0325e1e82232c64e7e51cb498293 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Tue, 29 Aug 2017 14:08:55 +0200 Subject: [PATCH 16/33] Updated requirements_all.txt --- requirements_all.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_all.txt b/requirements_all.txt index e94ca4ce025..fecd4221cf1 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -687,7 +687,7 @@ pyowm==2.7.1 pyqwikswitch==0.4 # homeassistant.components.rainbird -pyrainbird==0.0.7 +pyrainbird==0.0.9 # homeassistant.components.climate.sensibo pysensibo==1.0.1 From d2d28fd419ba768794a11f554e2afdf8f87a5360 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 30 Aug 2017 16:11:40 +0200 Subject: [PATCH 17/33] Moved all code into the switch component Per request moved all the code inside the switch --- .coveragerc | 2 +- homeassistant/components/rainbird.py | 155 -------------------- homeassistant/components/switch/rainbird.py | 135 ++++++++++++++++- requirements_all.txt | 2 +- 4 files changed, 131 insertions(+), 163 deletions(-) delete mode 100644 homeassistant/components/rainbird.py diff --git a/.coveragerc b/.coveragerc index 8b7ffe2e966..9596b29534d 100644 --- a/.coveragerc +++ b/.coveragerc @@ -416,7 +416,6 @@ omit = homeassistant/components/notify/xmpp.py homeassistant/components/nuimo_controller.py homeassistant/components/prometheus.py - homeassistant/components/rainbird.py homeassistant/components/remote/harmony.py homeassistant/components/remote/itach.py homeassistant/components/scene/hunterdouglas_powerview.py @@ -551,6 +550,7 @@ omit = homeassistant/components/switch/orvibo.py homeassistant/components/switch/pilight.py homeassistant/components/switch/pulseaudio_loopback.py + homeassistant/components/switch/rainbird.py homeassistant/components/switch/rainmachine.py homeassistant/components/switch/rest.py homeassistant/components/switch/rpi_rf.py diff --git a/homeassistant/components/rainbird.py b/homeassistant/components/rainbird.py deleted file mode 100644 index 48a40cc30fe..00000000000 --- a/homeassistant/components/rainbird.py +++ /dev/null @@ -1,155 +0,0 @@ -""" -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.exceptions import PlatformNotReady -from homeassistant.helpers.entity_component import EntityComponent -from homeassistant.helpers.entity import Entity -from homeassistant.const import ( - CONF_HOST, CONF_PASSWORD) - -REQUIREMENTS = ['pyrainbird==0.0.9'] - -DOMAIN = 'rainbird' - -_LOGGER = logging.getLogger(__name__) - -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 component.""" - server = config[DOMAIN].get(CONF_HOST) - password = config[DOMAIN].get(CONF_PASSWORD) - component = EntityComponent(_LOGGER, DOMAIN, hass) - - from pyrainbird import RainbirdController - - controller = RainbirdController(_LOGGER) - controller.setConfig(server, password) - _LOGGER.info("Rain Bird Controller set to " + str(server)) - - rbdevice = RainbirdDevice(hass, controller) - hass.data["DATA_RAINBIRD"] = rbdevice - - initialstatus = rbdevice.update() - if initialstatus == -1: - _LOGGER.error("Error getting state. Possible configuration issues") - raise PlatformNotReady - else: - _LOGGER.info("Initialized Rain Bird Controller") - - entities = [] - entities.append(rbdevice) - component.add_entities(entities) - - return True - - -class RainbirdDevice(Entity): - """Rain Bird Device.""" - - _state = -1 - - def __init__(self, hass, controller): - """Initialize the device.""" - self.hass = hass - self.controller = controller - self._name = "Rainbird_Controller" - self._stations = {} - - # For automation purposes add 2 services - def start_irrigation_call(call): - """Start irrigation from service call.""" - station_id = call.data.get("station_id") - duration = call.data.get("duration") - if station_id and duration: - self.start_irrigation(station_id, duration) - else: - _LOGGER.warning("Error in start_irrigation call. \ - station_id and duration need to be set") - - def stop_irrigation_call(call): - """Start irrigation from service call.""" - self.stop_irrigation() - - hass.services.register(DOMAIN, 'start_irrigation', - start_irrigation_call) - hass.services.register(DOMAIN, 'stop_irrigation', - stop_irrigation_call) - - def should_poll(self): - """Return True if entity has to be polled for state.""" - return True - - @property - def name(self): - """Get the name of the device.""" - return self._name - - def available(self): - """Return True if entity is available.""" - return self._state != -1 - - def setstate(self, state): - """Force set the current state value.""" - self._state = state - - @property - def state(self): - """Return the state of the entity.""" - return self._state - - def start_irrigation(self, station_id, duration): - """ - Start Irrigation command towards Rain Bird LNK WiFi stick. - - @param call: should be a home assistant call object with data - station for Zone to sprinkle and duration for the time - """ - _LOGGER.info("Requesting irrigation for " + - str(station_id) + " duration " + str(duration)) - result = self.controller.startIrrigation( - int(station_id), int(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 stop_irrigation(self): - """Stop the irrigation (if one is running).""" - _LOGGER.info("Stop request irrigation") - result = self.controller.stopIrrigation() - if result == 1: - _LOGGER.info("Stopped irrigation") - elif result == 0: - _LOGGER.error("Error sending request") - else: - _LOGGER.error("Request was not acknowledged!") - - def update(self): - """ - Get current active station. - - @return: integer which station is active - """ - _LOGGER.info("Request irrigation state") - result = self.controller.currentIrrigation() - if result < 0: - _LOGGER.error("Error sending request") - return -1 - self._state = result diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 70072db65da..4a4016bd209 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -9,20 +9,24 @@ import logging import voluptuous as vol -from homeassistant.components import rainbird +from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity_component import EntityComponent from homeassistant.components.switch import SwitchDevice from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, CONF_FRIENDLY_NAME, CONF_TRIGGER_TIME, - CONF_SCAN_INTERVAL) + CONF_SCAN_INTERVAL, CONF_HOST, CONF_PASSWORD) from homeassistant.helpers import config_validation as cv +from homeassistant.exceptions import PlatformNotReady -DEPENDENCIES = ['rainbird'] +REQUIREMENTS = ['pyrainbird==0.0.9'] +DOMAIN = 'rainbird' _LOGGER = logging.getLogger(__name__) - PLATFORM_SCHEMA = vol.Schema({ - vol.Required(CONF_PLATFORM): rainbird.DOMAIN, + vol.Required(CONF_PLATFORM): DOMAIN, + vol.Required(CONF_HOST): cv.string, + vol.Required(CONF_PASSWORD): cv.string, vol.Required(CONF_SWITCHES, default={}): vol.Schema({ cv.string: { vol.Optional(CONF_FRIENDLY_NAME): cv.string, @@ -36,8 +40,29 @@ PLATFORM_SCHEMA = vol.Schema({ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up Rain Bird switches over a Rain Bird controller.""" + server = config.get(CONF_HOST) + password = config.get(CONF_PASSWORD) + component = EntityComponent(_LOGGER, DOMAIN, hass) + + from pyrainbird import RainbirdController + + controller = RainbirdController(_LOGGER) + controller.setConfig(server, password) + _LOGGER.info("Rain Bird Controller set to " + str(server)) + + rbdevice = RainbirdDevice(hass, controller) + initialstatus = rbdevice.update() + if initialstatus == -1: + _LOGGER.error("Error getting state. Possible configuration issues") + raise PlatformNotReady + else: + _LOGGER.info("Initialized Rain Bird Controller") + + entities = [] + entities.append(rbdevice) + component.add_entities(entities) + devices = [] - rbdevice = hass.data.get("DATA_RAINBIRD") for dev_id, switch in config.get(CONF_SWITCHES).items(): devices.append(RainBirdSwitch(rbdevice, switch, dev_id)) add_devices(devices) @@ -99,3 +124,101 @@ class RainBirdSwitch(SwitchDevice): def is_on(self): """Return true if switch is on.""" return self._state + + +class RainbirdDevice(Entity): + """Rain Bird Device.""" + + _state = -1 + + def __init__(self, hass, controller): + """Initialize the device.""" + self.hass = hass + self.controller = controller + self._name = "Rainbird_Controller" + self._stations = {} + + # For automation purposes add 2 services + def start_irrigation_call(call): + """Start irrigation from service call.""" + station_id = call.data.get("station_id") + duration = call.data.get("duration") + if station_id and duration: + self.start_irrigation(station_id, duration) + else: + _LOGGER.warning("Error in start_irrigation call. \ + station_id and duration need to be set") + + def stop_irrigation_call(call): + """Start irrigation from service call.""" + self.stop_irrigation() + + hass.services.register(DOMAIN, 'start_irrigation', + start_irrigation_call) + hass.services.register(DOMAIN, 'stop_irrigation', + stop_irrigation_call) + + def should_poll(self): + """Return True if entity has to be polled for state.""" + return True + + @property + def name(self): + """Get the name of the device.""" + return self._name + + def available(self): + """Return True if entity is available.""" + return self._state != -1 + + def setstate(self, state): + """Force set the current state value.""" + self._state = state + + @property + def state(self): + """Return the state of the entity.""" + return self._state + + def start_irrigation(self, station_id, duration): + """ + Start Irrigation command towards Rain Bird LNK WiFi stick. + + @param call: should be a home assistant call object with data + station for Zone to sprinkle and duration for the time + """ + _LOGGER.info("Requesting irrigation for " + + str(station_id) + " duration " + str(duration)) + result = self.controller.startIrrigation( + int(station_id), int(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 stop_irrigation(self): + """Stop the irrigation (if one is running).""" + _LOGGER.info("Stop request irrigation") + result = self.controller.stopIrrigation() + if result == 1: + _LOGGER.info("Stopped irrigation") + elif result == 0: + _LOGGER.error("Error sending request") + else: + _LOGGER.error("Request was not acknowledged!") + + def update(self): + """ + Get current active station. + + @return: integer which station is active + """ + _LOGGER.info("Request irrigation state") + result = self.controller.currentIrrigation() + if result < 0: + _LOGGER.error("Error sending request") + return -1 + self._state = result diff --git a/requirements_all.txt b/requirements_all.txt index fecd4221cf1..f94ccb389ff 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -686,7 +686,7 @@ pyowm==2.7.1 # homeassistant.components.qwikswitch pyqwikswitch==0.4 -# homeassistant.components.rainbird +# homeassistant.components.switch.rainbird pyrainbird==0.0.9 # homeassistant.components.climate.sensibo From f036bf935320685814fe6de42a88c3481557e256 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Fri, 6 Oct 2017 15:22:22 +0200 Subject: [PATCH 18/33] Limited to switch on/off Limited to switch on/off Lowered loglevel --- homeassistant/components/switch/rainbird.py | 126 ++------------------ requirements_all.txt | 2 +- 2 files changed, 10 insertions(+), 118 deletions(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 4a4016bd209..9678babaea5 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -9,8 +9,6 @@ import logging import voluptuous as vol -from homeassistant.helpers.entity import Entity -from homeassistant.helpers.entity_component import EntityComponent from homeassistant.components.switch import SwitchDevice from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, CONF_FRIENDLY_NAME, CONF_TRIGGER_TIME, @@ -18,7 +16,7 @@ from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, from homeassistant.helpers import config_validation as cv from homeassistant.exceptions import PlatformNotReady -REQUIREMENTS = ['pyrainbird==0.0.9'] +REQUIREMENTS = ['pyrainbird==0.1.0'] DOMAIN = 'rainbird' _LOGGER = logging.getLogger(__name__) @@ -42,29 +40,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up Rain Bird switches over a Rain Bird controller.""" server = config.get(CONF_HOST) password = config.get(CONF_PASSWORD) - component = EntityComponent(_LOGGER, DOMAIN, hass) from pyrainbird import RainbirdController - controller = RainbirdController(_LOGGER) controller.setConfig(server, password) - _LOGGER.info("Rain Bird Controller set to " + str(server)) - rbdevice = RainbirdDevice(hass, controller) - initialstatus = rbdevice.update() + _LOGGER.debug("Rain Bird Controller set to " + str(server)) + + initialstatus = controller.currentIrrigation() if initialstatus == -1: _LOGGER.error("Error getting state. Possible configuration issues") raise PlatformNotReady else: - _LOGGER.info("Initialized Rain Bird Controller") - - entities = [] - entities.append(rbdevice) - component.add_entities(entities) + _LOGGER.debug("Initialized Rain Bird Controller") devices = [] for dev_id, switch in config.get(CONF_SWITCHES).items(): - devices.append(RainBirdSwitch(rbdevice, switch, dev_id)) + devices.append(RainBirdSwitch(controller, switch, dev_id)) add_devices(devices) return True @@ -103,18 +95,16 @@ class RainBirdSwitch(SwitchDevice): def turn_on(self, **kwargs): """Turn the switch on.""" self._state = True - self._rainbird.start_irrigation(self._zone, self._duration) - self._rainbird.setstate(self._zone) + self._rainbird.startIrrigation(int(self._zone), int(self._duration)) def turn_off(self, **kwargs): """Turn the switch off.""" self._state = False - self._rainbird.stop_irrigation() - self._rainbird.setstate(0) + self._rainbird.stopIrrigation() def get_device_status(self): """Get the status of the switch from Rain Bird Controller.""" - return self._rainbird.state == self._zone + return self._rainbird.currentIrrigation() == self._zone def update(self): """Update switch status.""" @@ -124,101 +114,3 @@ class RainBirdSwitch(SwitchDevice): def is_on(self): """Return true if switch is on.""" return self._state - - -class RainbirdDevice(Entity): - """Rain Bird Device.""" - - _state = -1 - - def __init__(self, hass, controller): - """Initialize the device.""" - self.hass = hass - self.controller = controller - self._name = "Rainbird_Controller" - self._stations = {} - - # For automation purposes add 2 services - def start_irrigation_call(call): - """Start irrigation from service call.""" - station_id = call.data.get("station_id") - duration = call.data.get("duration") - if station_id and duration: - self.start_irrigation(station_id, duration) - else: - _LOGGER.warning("Error in start_irrigation call. \ - station_id and duration need to be set") - - def stop_irrigation_call(call): - """Start irrigation from service call.""" - self.stop_irrigation() - - hass.services.register(DOMAIN, 'start_irrigation', - start_irrigation_call) - hass.services.register(DOMAIN, 'stop_irrigation', - stop_irrigation_call) - - def should_poll(self): - """Return True if entity has to be polled for state.""" - return True - - @property - def name(self): - """Get the name of the device.""" - return self._name - - def available(self): - """Return True if entity is available.""" - return self._state != -1 - - def setstate(self, state): - """Force set the current state value.""" - self._state = state - - @property - def state(self): - """Return the state of the entity.""" - return self._state - - def start_irrigation(self, station_id, duration): - """ - Start Irrigation command towards Rain Bird LNK WiFi stick. - - @param call: should be a home assistant call object with data - station for Zone to sprinkle and duration for the time - """ - _LOGGER.info("Requesting irrigation for " + - str(station_id) + " duration " + str(duration)) - result = self.controller.startIrrigation( - int(station_id), int(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 stop_irrigation(self): - """Stop the irrigation (if one is running).""" - _LOGGER.info("Stop request irrigation") - result = self.controller.stopIrrigation() - if result == 1: - _LOGGER.info("Stopped irrigation") - elif result == 0: - _LOGGER.error("Error sending request") - else: - _LOGGER.error("Request was not acknowledged!") - - def update(self): - """ - Get current active station. - - @return: integer which station is active - """ - _LOGGER.info("Request irrigation state") - result = self.controller.currentIrrigation() - if result < 0: - _LOGGER.error("Error sending request") - return -1 - self._state = result diff --git a/requirements_all.txt b/requirements_all.txt index f94ccb389ff..002f5061765 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -687,7 +687,7 @@ pyowm==2.7.1 pyqwikswitch==0.4 # homeassistant.components.switch.rainbird -pyrainbird==0.0.9 +pyrainbird==0.1.0 # homeassistant.components.climate.sensibo pysensibo==1.0.1 From 7f97d166bf830eb8ad3169a3278d8f9e1fbbf06f Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 15:15:50 +0200 Subject: [PATCH 19/33] Added dependency on pycrypto Crypto Dependency missing found on virtualenv install. Added to dependecy rainbird.py --- homeassistant/components/switch/rainbird.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 9678babaea5..5ec5608830b 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -16,7 +16,7 @@ from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, from homeassistant.helpers import config_validation as cv from homeassistant.exceptions import PlatformNotReady -REQUIREMENTS = ['pyrainbird==0.1.0'] +REQUIREMENTS = ['pyrainbird==0.1.0','pycrypto>=2.6.0'] DOMAIN = 'rainbird' _LOGGER = logging.getLogger(__name__) From 0ace83216678be085d46d4a47b925efbb23b1c86 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 15:35:58 +0200 Subject: [PATCH 20/33] Requirements updated --- requirements_all.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements_all.txt b/requirements_all.txt index 002f5061765..1ad3ff54c8c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -688,6 +688,7 @@ pyqwikswitch==0.4 # homeassistant.components.switch.rainbird pyrainbird==0.1.0 +pycrypto>=2.6.0 # homeassistant.components.climate.sensibo pysensibo==1.0.1 From d0ff45500b32006559a70eac56c823266af6375d Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 15:45:07 +0200 Subject: [PATCH 21/33] Fixed dependency version --- homeassistant/components/switch/rainbird.py | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 5ec5608830b..a55a0f71948 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -16,7 +16,7 @@ from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, from homeassistant.helpers import config_validation as cv from homeassistant.exceptions import PlatformNotReady -REQUIREMENTS = ['pyrainbird==0.1.0','pycrypto>=2.6.0'] +REQUIREMENTS = ['pyrainbird==0.1.0','pycrypto==2.6.1'] DOMAIN = 'rainbird' _LOGGER = logging.getLogger(__name__) diff --git a/requirements_all.txt b/requirements_all.txt index 1ad3ff54c8c..206784e6477 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -688,7 +688,7 @@ pyqwikswitch==0.4 # homeassistant.components.switch.rainbird pyrainbird==0.1.0 -pycrypto>=2.6.0 +pycrypto==2.6.1 # homeassistant.components.climate.sensibo pysensibo==1.0.1 From 59fcef39ff03cbad107c64c34d8608f23129fe6f Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 15:56:18 +0200 Subject: [PATCH 22/33] Split requirements per line --- requirements_all.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements_all.txt b/requirements_all.txt index 206784e6477..10cdca2b1da 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -688,6 +688,8 @@ pyqwikswitch==0.4 # homeassistant.components.switch.rainbird pyrainbird==0.1.0 + +# homeassistant.components.switch.rainbird pycrypto==2.6.1 # homeassistant.components.climate.sensibo From c1aaed250ac686418f6af349694a7a3ce7a0ca5d Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 16:01:25 +0200 Subject: [PATCH 23/33] Dependency breaks build --- requirements_all.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index 10cdca2b1da..002f5061765 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -689,9 +689,6 @@ pyqwikswitch==0.4 # homeassistant.components.switch.rainbird pyrainbird==0.1.0 -# homeassistant.components.switch.rainbird -pycrypto==2.6.1 - # homeassistant.components.climate.sensibo pysensibo==1.0.1 From 24826c27701ac916abd77ad3ca83d668cfbd098b Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 16:02:32 +0200 Subject: [PATCH 24/33] Revert "Dependency breaks build" This reverts commit c1aaed250ac686418f6af349694a7a3ce7a0ca5d. --- requirements_all.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requirements_all.txt b/requirements_all.txt index 002f5061765..10cdca2b1da 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -689,6 +689,9 @@ pyqwikswitch==0.4 # homeassistant.components.switch.rainbird pyrainbird==0.1.0 +# homeassistant.components.switch.rainbird +pycrypto==2.6.1 + # homeassistant.components.climate.sensibo pysensibo==1.0.1 From cc4ec228b59c84c682b03d19a35a8cc36dfaf59e Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 16:12:01 +0200 Subject: [PATCH 25/33] Removed requirement --- requirements_all.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index b280f0fe5a6..abf0b130f24 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -721,9 +721,6 @@ pyqwikswitch==0.4 # homeassistant.components.switch.rainbird pyrainbird==0.1.0 -# homeassistant.components.switch.rainbird -pycrypto==2.6.1 - # homeassistant.components.climate.sensibo pysensibo==1.0.1 From 8db4b4f30331e3867e143cdee69cbdb6d1bebf91 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 16:54:08 +0200 Subject: [PATCH 26/33] typo --- homeassistant/components/switch/rainbird.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index a55a0f71948..7753c07e9ca 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -16,7 +16,7 @@ from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, from homeassistant.helpers import config_validation as cv from homeassistant.exceptions import PlatformNotReady -REQUIREMENTS = ['pyrainbird==0.1.0','pycrypto==2.6.1'] +REQUIREMENTS = ['pyrainbird==0.1.0', 'pycrypto==2.6.1'] DOMAIN = 'rainbird' _LOGGER = logging.getLogger(__name__) From bddb424b0dc40e7261d43624312c5ec1ca13b8a5 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 11 Oct 2017 17:01:14 +0200 Subject: [PATCH 27/33] Requirements updated --- requirements_all.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requirements_all.txt b/requirements_all.txt index abf0b130f24..b280f0fe5a6 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -721,6 +721,9 @@ pyqwikswitch==0.4 # homeassistant.components.switch.rainbird pyrainbird==0.1.0 +# homeassistant.components.switch.rainbird +pycrypto==2.6.1 + # homeassistant.components.climate.sensibo pysensibo==1.0.1 From fad9e607c38b892e6bb70642190adcc16de3d6a4 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Thu, 12 Oct 2017 10:22:22 +0200 Subject: [PATCH 28/33] Removed requirement --- homeassistant/components/switch/rainbird.py | 2 +- requirements_all.txt | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 7753c07e9ca..9678babaea5 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -16,7 +16,7 @@ from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, from homeassistant.helpers import config_validation as cv from homeassistant.exceptions import PlatformNotReady -REQUIREMENTS = ['pyrainbird==0.1.0', 'pycrypto==2.6.1'] +REQUIREMENTS = ['pyrainbird==0.1.0'] DOMAIN = 'rainbird' _LOGGER = logging.getLogger(__name__) diff --git a/requirements_all.txt b/requirements_all.txt index b280f0fe5a6..abf0b130f24 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -721,9 +721,6 @@ pyqwikswitch==0.4 # homeassistant.components.switch.rainbird pyrainbird==0.1.0 -# homeassistant.components.switch.rainbird -pycrypto==2.6.1 - # homeassistant.components.climate.sensibo pysensibo==1.0.1 From 02f8779de845d67e2840d90107828c1e6fc73cc4 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 18 Oct 2017 09:58:32 +0200 Subject: [PATCH 29/33] Fixed comments from @fabaff Fxied issues raides --- homeassistant/components/switch/rainbird.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 9678babaea5..d69dc14daf3 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -9,19 +9,19 @@ import logging import voluptuous as vol -from homeassistant.components.switch import SwitchDevice +from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA) from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, CONF_FRIENDLY_NAME, CONF_TRIGGER_TIME, CONF_SCAN_INTERVAL, CONF_HOST, CONF_PASSWORD) from homeassistant.helpers import config_validation as cv from homeassistant.exceptions import PlatformNotReady -REQUIREMENTS = ['pyrainbird==0.1.0'] +REQUIREMENTS = ['pyrainbird==0.1.0','pycrypto==2.6.1'] DOMAIN = 'rainbird' _LOGGER = logging.getLogger(__name__) -PLATFORM_SCHEMA = vol.Schema({ +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_PLATFORM): DOMAIN, vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PASSWORD): cv.string, @@ -57,8 +57,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): devices = [] for dev_id, switch in config.get(CONF_SWITCHES).items(): devices.append(RainBirdSwitch(controller, switch, dev_id)) - add_devices(devices) - return True + add_devices(devices, True) class RainBirdSwitch(SwitchDevice): @@ -69,8 +68,8 @@ class RainBirdSwitch(SwitchDevice): self._rainbird = rb self._devid = dev_id self._zone = int(dev.get(CONF_ZONE)) - self._name = dev.get(CONF_FRIENDLY_NAME, "Sprinker %s" % self._zone) - self._state = self.get_device_status() + self._name = dev.get(CONF_FRIENDLY_NAME, "Sprinker {}".format(self._zone)) + self._state = None self._duration = dev.get(CONF_TRIGGER_TIME) self._attributes = { "duration": self._duration, @@ -82,11 +81,6 @@ class RainBirdSwitch(SwitchDevice): """Return state attributes.""" return self._attributes - @property - def should_poll(self): - """Return the polling state.""" - return True - @property def name(self): """Get the name of the switch.""" From 76a3a4892d1baae1d4848a79c5bde6d1f33147b3 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 18 Oct 2017 10:18:37 +0200 Subject: [PATCH 30/33] Fix req --- homeassistant/components/switch/rainbird.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index d69dc14daf3..3f3a8cf6d5c 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -16,7 +16,7 @@ from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, from homeassistant.helpers import config_validation as cv from homeassistant.exceptions import PlatformNotReady -REQUIREMENTS = ['pyrainbird==0.1.0','pycrypto==2.6.1'] +REQUIREMENTS = ['pyrainbird==0.1.0'] DOMAIN = 'rainbird' _LOGGER = logging.getLogger(__name__) From 778761ebce72de47aac17803af79ebb7860bed9d Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 18 Oct 2017 10:40:38 +0200 Subject: [PATCH 31/33] lint error --- homeassistant/components/switch/rainbird.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 3f3a8cf6d5c..ac0b07a78f8 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -68,7 +68,8 @@ class RainBirdSwitch(SwitchDevice): self._rainbird = rb self._devid = dev_id self._zone = int(dev.get(CONF_ZONE)) - self._name = dev.get(CONF_FRIENDLY_NAME, "Sprinker {}".format(self._zone)) + self._name = dev.get(CONF_FRIENDLY_NAME, + "Sprinker {}".format(self._zone)) self._state = None self._duration = dev.get(CONF_TRIGGER_TIME) self._attributes = { From a628112e4c701ca1b4425d69ede48cb216835769 Mon Sep 17 00:00:00 2001 From: "J.J.Barrancos" Date: Wed, 18 Oct 2017 11:17:29 +0200 Subject: [PATCH 32/33] lint ws --- homeassistant/components/switch/rainbird.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index ac0b07a78f8..70397e53d09 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -68,7 +68,7 @@ class RainBirdSwitch(SwitchDevice): self._rainbird = rb self._devid = dev_id self._zone = int(dev.get(CONF_ZONE)) - self._name = dev.get(CONF_FRIENDLY_NAME, + self._name = dev.get(CONF_FRIENDLY_NAME, "Sprinker {}".format(self._zone)) self._state = None self._duration = dev.get(CONF_TRIGGER_TIME) From 7c69941f1384d90aad59fbe9f1f16abb5b8f3f0b Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 24 Oct 2017 12:25:12 +0200 Subject: [PATCH 33/33] cleanup --- homeassistant/components/switch/rainbird.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/homeassistant/components/switch/rainbird.py b/homeassistant/components/switch/rainbird.py index 70397e53d09..c1dbfbc4e72 100644 --- a/homeassistant/components/switch/rainbird.py +++ b/homeassistant/components/switch/rainbird.py @@ -47,8 +47,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.debug("Rain Bird Controller set to " + str(server)) - initialstatus = controller.currentIrrigation() - if initialstatus == -1: + if controller.currentIrrigation() == -1: _LOGGER.error("Error getting state. Possible configuration issues") raise PlatformNotReady else: @@ -89,12 +88,10 @@ class RainBirdSwitch(SwitchDevice): def turn_on(self, **kwargs): """Turn the switch on.""" - self._state = True self._rainbird.startIrrigation(int(self._zone), int(self._duration)) def turn_off(self, **kwargs): """Turn the switch off.""" - self._state = False self._rainbird.stopIrrigation() def get_device_status(self):