Skip to content

Commit 8994312

Browse files
authored
Bump rachiopy to 1.0.3 and update methods to handle changes (home-assistant#41398)
1 parent 80522f1 commit 8994312

File tree

9 files changed

+28
-40
lines changed

9 files changed

+28
-40
lines changed

homeassistant/components/rachio/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import secrets
55

66
from rachiopy import Rachio
7+
from requests.exceptions import ConnectTimeout
78
import voluptuous as vol
89

910
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
@@ -18,7 +19,6 @@
1819
CONF_WEBHOOK_ID,
1920
DEFAULT_MANUAL_RUN_MINS,
2021
DOMAIN,
21-
RACHIO_API_EXCEPTIONS,
2222
)
2323
from .device import RachioPerson
2424
from .webhooks import (
@@ -113,9 +113,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
113113
# Get the API user
114114
try:
115115
await hass.async_add_executor_job(person.setup, hass)
116-
# Yes we really do get all these exceptions (hopefully rachiopy switches to requests)
117-
# and there is not a reasonable timeout here so it can block for a long time
118-
except RACHIO_API_EXCEPTIONS as error:
116+
except ConnectTimeout as error:
119117
_LOGGER.error("Could not reach the Rachio API: %s", error)
120118
raise ConfigEntryNotReady from error
121119

homeassistant/components/rachio/config_flow.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from rachiopy import Rachio
5+
from requests.exceptions import ConnectTimeout
56
import voluptuous as vol
67

78
from homeassistant import config_entries, core, exceptions
@@ -14,7 +15,6 @@
1415
KEY_ID,
1516
KEY_STATUS,
1617
KEY_USERNAME,
17-
RACHIO_API_EXCEPTIONS,
1818
)
1919
from .const import DOMAIN # pylint:disable=unused-import
2020

@@ -31,7 +31,7 @@ async def validate_input(hass: core.HomeAssistant, data):
3131
rachio = Rachio(data[CONF_API_KEY])
3232
username = None
3333
try:
34-
data = await hass.async_add_executor_job(rachio.person.getInfo)
34+
data = await hass.async_add_executor_job(rachio.person.info)
3535
_LOGGER.debug("rachio.person.getInfo: %s", data)
3636
if int(data[0][KEY_STATUS]) != HTTP_OK:
3737
raise InvalidAuth
@@ -43,8 +43,7 @@ async def validate_input(hass: core.HomeAssistant, data):
4343
raise CannotConnect
4444

4545
username = data[1][KEY_USERNAME]
46-
# Yes we really do get all these exceptions (hopefully rachiopy switches to requests)
47-
except RACHIO_API_EXCEPTIONS as error:
46+
except ConnectTimeout as error:
4847
_LOGGER.error("Could not reach the Rachio API: %s", error)
4948
raise CannotConnect from error
5049

homeassistant/components/rachio/const.py

-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"""Constants for rachio."""
22

3-
import http.client
4-
import ssl
5-
63
DEFAULT_NAME = "Rachio"
74

85
DOMAIN = "rachio"
@@ -50,14 +47,6 @@
5047
KEY_CUSTOM_CROP = "customCrop"
5148
KEY_CUSTOM_SLOPE = "customSlope"
5249

53-
# Yes we really do get all these exceptions (hopefully rachiopy switches to requests)
54-
RACHIO_API_EXCEPTIONS = (
55-
http.client.HTTPException,
56-
ssl.SSLError,
57-
OSError,
58-
AssertionError,
59-
)
60-
6150
STATUS_ONLINE = "ONLINE"
6251

6352
SCHEDULE_TYPE_FIXED = "FIXED"

homeassistant/components/rachio/device.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, rachio, config_entry):
3939

4040
def setup(self, hass):
4141
"""Rachio device setup."""
42-
response = self.rachio.person.getInfo()
42+
response = self.rachio.person.info()
4343
assert int(response[0][KEY_STATUS]) == HTTP_OK, "API key error"
4444
self._id = response[1][KEY_ID]
4545

@@ -49,7 +49,9 @@ def setup(self, hass):
4949
self.username = data[1][KEY_USERNAME]
5050
devices = data[1][KEY_DEVICES]
5151
for controller in devices:
52-
webhooks = self.rachio.notification.getDeviceWebhook(controller[KEY_ID])[1]
52+
webhooks = self.rachio.notification.get_device_webhook(controller[KEY_ID])[
53+
1
54+
]
5355
# The API does not provide a way to tell if a controller is shared
5456
# or if they are the owner. To work around this problem we fetch the webooks
5557
# before we setup the device so we can skip it instead of failing.
@@ -113,29 +115,29 @@ def _deinit_webhooks(_) -> None:
113115
if not self._webhooks:
114116
# We fetched webhooks when we created the device, however if we call _init_webhooks
115117
# again we need to fetch again
116-
self._webhooks = self.rachio.notification.getDeviceWebhook(
118+
self._webhooks = self.rachio.notification.get_device_webhook(
117119
self.controller_id
118120
)[1]
119121
for webhook in self._webhooks:
120122
if (
121123
webhook[KEY_EXTERNAL_ID].startswith(WEBHOOK_CONST_ID)
122124
or webhook[KEY_ID] == current_webhook_id
123125
):
124-
self.rachio.notification.deleteWebhook(webhook[KEY_ID])
126+
self.rachio.notification.delete(webhook[KEY_ID])
125127
self._webhooks = None
126128

127129
_deinit_webhooks(None)
128130

129131
# Choose which events to listen for and get their IDs
130132
event_types = []
131-
for event_type in self.rachio.notification.getWebhookEventType()[1]:
133+
for event_type in self.rachio.notification.get_webhook_event_type()[1]:
132134
if event_type[KEY_NAME] in LISTEN_EVENT_TYPES:
133135
event_types.append({"id": event_type[KEY_ID]})
134136

135137
# Register to listen to these events from the device
136138
url = self.rachio.webhook_url
137139
auth = WEBHOOK_CONST_ID + self.rachio.webhook_auth
138-
new_webhook = self.rachio.notification.postWebhook(
140+
new_webhook = self.rachio.notification.add(
139141
self.controller_id, auth, url, event_types
140142
)
141143
# Save ID for deletion at shutdown
@@ -154,7 +156,7 @@ def controller_id(self) -> str:
154156
@property
155157
def current_schedule(self) -> str:
156158
"""Return the schedule that the device is running right now."""
157-
return self.rachio.device.getCurrentSchedule(self.controller_id)[1]
159+
return self.rachio.device.current_schedule(self.controller_id)[1]
158160

159161
@property
160162
def init_data(self) -> dict:
@@ -188,5 +190,5 @@ def list_flex_schedules(self) -> list:
188190

189191
def stop_watering(self) -> None:
190192
"""Stop watering all zones connected to this controller."""
191-
self.rachio.device.stopWater(self.controller_id)
193+
self.rachio.device.stop_water(self.controller_id)
192194
_LOGGER.info("Stopped watering of all zones on %s", str(self))

homeassistant/components/rachio/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"domain": "rachio",
33
"name": "Rachio",
44
"documentation": "https://www.home-assistant.io/integrations/rachio",
5-
"requirements": ["rachiopy==0.1.4"],
5+
"requirements": ["rachiopy==1.0.3"],
66
"dependencies": ["http"],
77
"after_dependencies": ["cloud"],
88
"codeowners": ["@bdraco"],

homeassistant/components/rachio/switch.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ def _async_handle_update(self, *args, **kwargs) -> None:
179179

180180
def turn_on(self, **kwargs) -> None:
181181
"""Put the controller in standby mode."""
182-
self._controller.rachio.device.off(self._controller.controller_id)
182+
self._controller.rachio.device.turn_off(self._controller.controller_id)
183183

184184
def turn_off(self, **kwargs) -> None:
185185
"""Resume controller functionality."""
186-
self._controller.rachio.device.on(self._controller.controller_id)
186+
self._controller.rachio.device.turn_on(self._controller.controller_id)
187187

188188
async def async_added_to_hass(self):
189189
"""Subscribe to updates."""
@@ -250,12 +250,12 @@ def _delay_expiration(self, *args) -> None:
250250

251251
def turn_on(self, **kwargs) -> None:
252252
"""Activate a 24 hour rain delay on the controller."""
253-
self._controller.rachio.device.rainDelay(self._controller.controller_id, 86400)
253+
self._controller.rachio.device.rain_delay(self._controller.controller_id, 86400)
254254
_LOGGER.debug("Starting rain delay for 24 hours")
255255

256256
def turn_off(self, **kwargs) -> None:
257257
"""Resume controller functionality."""
258-
self._controller.rachio.device.rainDelay(self._controller.controller_id, 0)
258+
self._controller.rachio.device.rain_delay(self._controller.controller_id, 0)
259259
_LOGGER.debug("Canceling rain delay")
260260

261261
async def async_added_to_hass(self):
@@ -381,7 +381,7 @@ def turn_off(self, **kwargs) -> None:
381381
def set_moisture_percent(self, percent) -> None:
382382
"""Set the zone moisture percent."""
383383
_LOGGER.debug("Setting %s moisture to %s percent", self._zone_name, percent)
384-
self._controller.rachio.zone.setMoisturePercent(self._id, percent / 100)
384+
self._controller.rachio.zone.set_moisture_percent(self._id, percent / 100)
385385

386386
@callback
387387
def _async_handle_update(self, *args, **kwargs) -> None:

requirements_all.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ qnapstats==0.3.0
18991899
quantum-gateway==0.0.5
19001900

19011901
# homeassistant.components.rachio
1902-
rachiopy==0.1.4
1902+
rachiopy==1.0.3
19031903

19041904
# homeassistant.components.radiotherm
19051905
radiotherm==2.0.0

requirements_test_all.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ pywilight==0.0.65
901901
pyzerproc==0.2.5
902902

903903
# homeassistant.components.rachio
904-
rachiopy==0.1.4
904+
rachiopy==1.0.3
905905

906906
# homeassistant.components.rainmachine
907907
regenmaschine==2.1.0

tests/components/rachio/test_config_flow.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
from tests.common import MockConfigEntry
1212

1313

14-
def _mock_rachio_return_value(get=None, getInfo=None):
14+
def _mock_rachio_return_value(get=None, info=None):
1515
rachio_mock = MagicMock()
1616
person_mock = MagicMock()
1717
type(person_mock).get = MagicMock(return_value=get)
18-
type(person_mock).getInfo = MagicMock(return_value=getInfo)
18+
type(person_mock).info = MagicMock(return_value=info)
1919
type(rachio_mock).person = person_mock
2020
return rachio_mock
2121

@@ -31,7 +31,7 @@ async def test_form(hass):
3131

3232
rachio_mock = _mock_rachio_return_value(
3333
get=({"status": 200}, {"username": "myusername"}),
34-
getInfo=({"status": 200}, {"id": "myid"}),
34+
info=({"status": 200}, {"id": "myid"}),
3535
)
3636

3737
with patch(
@@ -71,7 +71,7 @@ async def test_form_invalid_auth(hass):
7171

7272
rachio_mock = _mock_rachio_return_value(
7373
get=({"status": 200}, {"username": "myusername"}),
74-
getInfo=({"status": 412}, {"error": "auth fail"}),
74+
info=({"status": 412}, {"error": "auth fail"}),
7575
)
7676
with patch(
7777
"homeassistant.components.rachio.config_flow.Rachio", return_value=rachio_mock
@@ -93,7 +93,7 @@ async def test_form_cannot_connect(hass):
9393

9494
rachio_mock = _mock_rachio_return_value(
9595
get=({"status": 599}, {"username": "myusername"}),
96-
getInfo=({"status": 200}, {"id": "myid"}),
96+
info=({"status": 200}, {"id": "myid"}),
9797
)
9898
with patch(
9999
"homeassistant.components.rachio.config_flow.Rachio", return_value=rachio_mock

0 commit comments

Comments
 (0)