diff --git a/homeassistant/components/rainbird/__init__.py b/homeassistant/components/rainbird/__init__.py index 3ae1c8bf585..1d8ed8e37b1 100644 --- a/homeassistant/components/rainbird/__init__.py +++ b/homeassistant/components/rainbird/__init__.py @@ -29,13 +29,12 @@ def setup(hass, config): from pyrainbird import RainbirdController - controller = RainbirdController() - controller.setConfig(server, password) + controller = RainbirdController(server, password) _LOGGER.debug("Rain Bird Controller set to: %s", server) initial_status = controller.currentIrrigation() - if initial_status == -1: + if initial_status and initial_status["type"] != "CurrentStationsActiveResponse": _LOGGER.error("Error getting state. Possible configuration issues") return False diff --git a/homeassistant/components/rainbird/manifest.json b/homeassistant/components/rainbird/manifest.json index 24113d62534..584ea22afe2 100644 --- a/homeassistant/components/rainbird/manifest.json +++ b/homeassistant/components/rainbird/manifest.json @@ -3,7 +3,7 @@ "name": "Rainbird", "documentation": "https://www.home-assistant.io/components/rainbird", "requirements": [ - "pyrainbird==0.1.6" + "pyrainbird==0.2.1" ], "dependencies": [], "codeowners": [] diff --git a/homeassistant/components/rainbird/sensor.py b/homeassistant/components/rainbird/sensor.py index d59ea3b0fec..2d4549a21d5 100644 --- a/homeassistant/components/rainbird/sensor.py +++ b/homeassistant/components/rainbird/sensor.py @@ -56,7 +56,11 @@ class RainBirdSensor(Entity): """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() + result = self._controller.currentRainSensorState() + if result and result["type"] == "CurrentRainSensorStateResponse": + self._state = result["sensorState"] + else: + self._state = None @property def name(self): diff --git a/homeassistant/components/rainbird/switch.py b/homeassistant/components/rainbird/switch.py index 94b37c52fb7..a1b82bc1af7 100644 --- a/homeassistant/components/rainbird/switch.py +++ b/homeassistant/components/rainbird/switch.py @@ -70,15 +70,23 @@ class RainBirdSwitch(SwitchDevice): def turn_on(self, **kwargs): """Turn the switch on.""" - self._rainbird.startIrrigation(int(self._zone), int(self._duration)) + response = self._rainbird.startIrrigation(int(self._zone), int(self._duration)) + if response and response["type"] == "AcknowledgeResponse": + self._state = True def turn_off(self, **kwargs): """Turn the switch off.""" - self._rainbird.stopIrrigation() + response = self._rainbird.stopIrrigation() + if response and response["type"] == "AcknowledgeResponse": + self._state = False def get_device_status(self): """Get the status of the switch from Rain Bird Controller.""" - return self._rainbird.currentIrrigation() == self._zone + response = self._rainbird.currentIrrigation() + if response is None: + return None + if isinstance(response, dict) and "sprinklers" in response: + return response["sprinklers"][self._zone] def update(self): """Update switch status.""" diff --git a/requirements_all.txt b/requirements_all.txt index 6cd7f5d2822..0b7346031d4 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1359,7 +1359,7 @@ pyqwikswitch==0.93 pyrail==0.0.3 # homeassistant.components.rainbird -pyrainbird==0.1.6 +pyrainbird==0.2.1 # homeassistant.components.recswitch pyrecswitch==1.0.2