From a5104fca901d2d6c162e150b59dd42a17154930f Mon Sep 17 00:00:00 2001 From: Yordan Suarez Date: Mon, 13 Dec 2021 12:03:21 -0500 Subject: [PATCH 1/2] remove loop keyword argument. Issue #18 --- custom_components/fpl/fplapi.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/custom_components/fpl/fplapi.py b/custom_components/fpl/fplapi.py index 54cbd11..0e2b778 100644 --- a/custom_components/fpl/fplapi.py +++ b/custom_components/fpl/fplapi.py @@ -60,7 +60,7 @@ class FplApi(object): """login and get account information""" result = LOGIN_RESULT_OK try: - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): response = await self._session.get( URL_LOGIN, auth=aiohttp.BasicAuth(self._username, self._password) ) @@ -84,15 +84,16 @@ class FplApi(object): async def logout(self): _LOGGER.info("Logging out") - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): - await self._session.get("https://www.fpl.com/api/resources/logout") + URL = "https://www.fpl.com/api/resources/logout" + async with async_timeout.timeout(TIMEOUT): + await self._session.get(URL) async def async_get_open_accounts(self): _LOGGER.info(f"Getting accounts") result = [] try: - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): response = await self._session.get(URL_RESOURCES_HEADER) js = await response.json() @@ -112,7 +113,7 @@ class FplApi(object): _LOGGER.info(f"Getting Data") data = {} - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): response = await self._session.get( URL_RESOURCES_ACCOUNT.format(account=account) ) @@ -175,7 +176,7 @@ class FplApi(object): data = {} try: - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): response = await self._session.get( URL_RESOURCES_PROJECTED_BILL.format( account=account, @@ -208,7 +209,7 @@ class FplApi(object): URL = "https://www.fpl.com/api/resources/account/{account}/budgetBillingGraph/premiseDetails" try: - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): response = await self._session.get(URL.format(account=account)) if response.status == 200: r = (await response.json())["data"] @@ -242,7 +243,7 @@ class FplApi(object): URL = "https://www.fpl.com/api/resources/account/{account}/budgetBillingGraph" try: - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): response = await self._session.get(URL.format(account=account)) if response.status == 200: r = (await response.json())["data"] @@ -278,7 +279,7 @@ class FplApi(object): data = {} - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): response = await self._session.post(URL.format(account=account), json=JSON) if response.status == 200: r = (await response.json())["data"] @@ -317,7 +318,7 @@ class FplApi(object): JSON = {"startDate": str(lastBilledDate.strftime("%m%d%Y"))} data = {} try: - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): response = await self._session.post( URL.format(account=account), json=JSON ) From ae79732f75afb2cecefbddef8e408efffe478a12 Mon Sep 17 00:00:00 2001 From: Yordan Suarez Date: Mon, 13 Dec 2021 12:04:03 -0500 Subject: [PATCH 2/2] replace device_state_attributes. Issue #19 --- custom_components/fpl/fplEntity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/fpl/fplEntity.py b/custom_components/fpl/fplEntity.py index fa7ba8c..7b30d27 100644 --- a/custom_components/fpl/fplEntity.py +++ b/custom_components/fpl/fplEntity.py @@ -36,7 +36,7 @@ class FplEntity(CoordinatorEntity): return {} @property - def device_state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" attributes = { "attribution": ATTRIBUTION,