Update pyrainbird to version 0.2.1 to fix zone number (#26064)

* Update pyrainbird to version 0.2.0 to fix zone number issue:

- home-assistant/home-assistant/issues/24519
- jbarrancos/pyrainbird/issues/5
- https://community.home-assistant.io/t/rainbird-zone-switches-5-8-dont-correspond/104705

* requirements_all.txt regenerated

* code formatting

* code formatting

* response checking

* fixed switch state

* pyrainbird version bump

* formatting

* version bump

* if instead elif
This commit is contained in:
Petr Vraník 2019-08-20 18:26:15 +02:00 committed by Martin Hjelmare
parent a347a41d3c
commit 0e4504296e
5 changed files with 20 additions and 9 deletions

View file

@ -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

View file

@ -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": []

View file

@ -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):

View file

@ -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."""

View file

@ -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