diff --git a/raincloudy/aio/core.py b/raincloudy/aio/core.py index 85fa878..e4aeb2f 100644 --- a/raincloudy/aio/core.py +++ b/raincloudy/aio/core.py @@ -136,9 +136,9 @@ async def login(self) -> None: # faucet serials if index > 0: data = {"select_controller": index} - resp = await self.post(data, url=SETUP_ENDPOINT, referer=SETUP_ENDPOINT) - if resp: - self.html["setup"] = generate_soup_html(await resp.text()) + resp_text = await self.post(data, url=SETUP_ENDPOINT, referer=SETUP_ENDPOINT) + if resp_text: + self.html["setup"] = generate_soup_html(resp_text) faucet_serials = faucet_serial_finder(self.html["setup"]) @@ -149,11 +149,12 @@ async def login(self) -> None: # zone names if faucet_index > 0: data = {"select_faucet": faucet_index} - resp = await self.post( + + resp_text = await self.post( data, url=SETUP_ENDPOINT, referer=SETUP_ENDPOINT ) - if resp: - self.html["setup"] = generate_soup_html(await resp.text()) + if resp_text: + self.html["setup"] = generate_soup_html(resp_text) zone_names = find_zone_names(self.html["setup"]) faucets.append({"serial": faucet_serial, "zones": zone_names}) @@ -192,8 +193,8 @@ def update_home(self, data: str) -> None: async def post( self, ddata: dict, url: str = SETUP_ENDPOINT, referer: str = SETUP_ENDPOINT - ) -> ClientResponse | None: - """Update some attributes on namespace.""" + ) -> str | None: + """Update some attributes on namespace and return the body.""" headers = HEADERS.copy() if referer is None: headers.pop("Referer") @@ -210,7 +211,7 @@ async def post( if not req.status == 200: return None - return req + return await req.text() async def logout(self) -> None: """Logout.""" diff --git a/tests/fixtures/home.html b/tests/fixtures/home.html index b9f8f59..80b8f00 100644 --- a/tests/fixtures/home.html +++ b/tests/fixtures/home.html @@ -1,55 +1,56 @@ + -Home - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + }, + failure: function (data) { + console.log('Got an error '); + } + }) + }, 15000) + }); + - + - + + - -
- + + + -
+
-
-
-melnor.com -
-
-melnor.com -
-
+
+
+ melnor.com +
+
+ melnor.com +
+
-
-
+ -
-
- + +
+
+
+
+ - - - +
- - + + + - + + + - + - + - + - - - + + + - + - + - + - + - -
+ + - TodayTodaySatSatSunSunMonMon

- 55 - 35°

+ 55 - 35°

- 66 - 34°

+ 66 - 34°

- 69 - 50°

+ 69 - 50°

- 55 - 42°

+ 55 - 42°
+
- - -
-
+
+
- -
+
- -
help
+ +
help
- -
-
- -
+ +
- -
-
+ +
+ +
-
- +
+ -
-
+
+
- -
-
- -
+
- -
-
-
- + +
+
+
+ - + -
-
-
+
+
+
- + - -
- - +
+ + - -
0
-
0
-
0
-
0
- -
 
- - -
-
-
- -
-
-
- -
-
-
- -
-
-
- - - Unit
- - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - -

Zone

1 - Front Yard234
-
- - - - - - - - - - - - - - - - - -

Manual

- - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Auto

-
- - -
-
-
- - -
-
-
- - -
-
-
- - -
-

Edit

- - - -

Rain Delay

- - - - - - - -

Next Cycle

- -
- -
- -
- -
-
- - - - +
0
+
0
+
0
+
0
+ +
 
+ + +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ + + Unit +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Zone

+
1 - + Front Yard234
+
+ + + + + + + + + + + + + + + + + + + +
+

Manual

+
+ + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Auto

+
+
+ + +
+
+
+ + +
+
+
+ + +
+
+
+ + +
+
+

Edit

+
+ + + +
+

Rain Delay

+
+ + + + + + + +
+

Next Cycle

+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ + + + -
- - - - -
- -Copyright © 2016 Melnor, Inc. All Rights Reserved. Forecast by OpenWeatherMap -
- - - - + + + + + +
+ + Copyright © 2016 Melnor, Inc. All Rights + Reserved. Forecast by OpenWeatherMap +
+ + + + - + + \ No newline at end of file diff --git a/tests/fixtures/setup.html b/tests/fixtures/setup.html index f2b1df4..7c9e661 100644 --- a/tests/fixtures/setup.html +++ b/tests/fixtures/setup.html @@ -1,5 +1,6 @@ + Setup @@ -17,200 +18,217 @@ -
- -
-
-melnor.com -
-
-melnor.com -
-
- -
-
- - -
-
- -
- - -
help
- -
-
- - - - - - - - - - - - - - - - - - - - - - - -
- - - - -
-
-
- - - - - -
-
-
- - - - - - - - -
-
-
- - - - + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + - - -
-
-
- - - - -
-
-
- - - + +
+
+
+ + + + + +
+
+
+ + + + + + + + +
+
+
+ + + + + + +
+
+
+ + + + +
+
+
+ + + + + +
+
+
+ + + + +
+
+
+

+ - + + - - - - - - - - - - - - - -
-
-
- - - - -
-
-
-

- - - - - - - - - - + + +
+ +
+
- +
- - - - -
- -Copyright © 2016 Melnor, Inc. All Rights Reserved. -
- - +
+ + Copyright © 2016 Melnor, Inc. All Rights Reserved. +
+ + - + \ No newline at end of file diff --git a/tests/test_base.py b/tests/test_base.py index cff73c7..487f731 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -33,6 +33,7 @@ def setUp(self, mock): mock.get(LOGIN_ENDPOINT, text=load_fixture("home.html")) mock.get(SETUP_ENDPOINT, text=load_fixture("setup.html")) + mock.post(SETUP_ENDPOINT, text=load_fixture("setup.html")) mock.get(STATUS_ENDPOINT, text=load_fixture("get_cu_and_fu_status.json")) mock.post(LOGIN_ENDPOINT, text=load_fixture("home.html")) diff --git a/tests/test_base_aio.py b/tests/test_base_aio.py index 96785b7..71ce1d4 100644 --- a/tests/test_base_aio.py +++ b/tests/test_base_aio.py @@ -34,29 +34,41 @@ def add_methods(self, mocked: aioresponses): status=200, body=load_fixture("setup.html"), content_type="text/html; charset=UTF-8", + repeat=True, ) mocked.get( LOGIN_ENDPOINT, status=200, body=load_fixture("home.html"), content_type="text/html; charset=UTF-8", + repeat=True, ) mocked.get( re.compile(rf"^{STATUS_ENDPOINT}*"), status=200, + repeat=True, body=load_fixture("get_cu_and_fu_status.json"), ) mocked.post( LOGIN_ENDPOINT, status=200, + repeat=True, body=load_fixture("home.html"), content_type="text/html; charset=UTF-8", ) mocked.get( HOME_ENDPOINT, status=200, + repeat=True, body=load_fixture("home.html"), content_type="text/html; charset=UTF-8", ) - mocked.get(LOGOUT_ENDPOINT, status=200) - mocked.post(SETUP_ENDPOINT) + mocked.get(LOGOUT_ENDPOINT, repeat=True, status=200) + mocked.post( + SETUP_ENDPOINT, + status=200, + repeat=True, + headers={"Referer": SETUP_ENDPOINT}, + body=load_fixture("setup.html"), + content_type="text/html; charset=UTF-8", + ) diff --git a/tests/test_core.py b/tests/test_core.py index 1817705..e1fe1a9 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -38,7 +38,7 @@ def test_attributes(self): objname = "".format(CONTROLLER_SERIAL) self.assertEquals(self.rdy.__repr__(), objname) - self.assertEqual(1, len(self.rdy.controllers)) + self.assertEqual(2, len(self.rdy.controllers)) self.assertIsInstance(self.rdy.controllers[0], RainCloudyController) self.assertIsInstance(self.rdy.html["home"], BeautifulSoup) diff --git a/tests/test_core_aio.py b/tests/test_core_aio.py index 01c8c2f..ecba43f 100644 --- a/tests/test_core_aio.py +++ b/tests/test_core_aio.py @@ -41,7 +41,7 @@ async def test_login(self, mocked): objname = "".format(CONTROLLER_SERIAL) self.assertEquals(self.rdy.__repr__(), objname) - self.assertEqual(1, len(self.rdy.controllers)) + self.assertEqual(2, len(self.rdy.controllers)) self.assertIsInstance(self.rdy.controllers[0], RainCloudyController) self.assertIsInstance(self.rdy.html["home"], BeautifulSoup)