Skip to content

Commit

Permalink
Less code = better
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldotnl committed May 25, 2021
1 parent 01aeed2 commit cefc000
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions custom_components/multiscrape/scraped_rest_data.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import logging

import httpx
from bs4 import BeautifulSoup
from homeassistant.components.rest.data import RestData
from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_VALUE_TEMPLATE
from homeassistant.helpers.httpx_client import get_async_client

from .const import CONF_ATTR
from .const import CONF_INDEX
Expand Down Expand Up @@ -96,37 +94,6 @@ def scrape_data(self):
else:
self.values[key] = value

# async def async_update(self, log_errors=True):
# super().async_update(log_errors)
# self.scrape_data()

async def async_update(self, log_errors=True):
"""Get the latest data from REST service with provided method."""
if not self._async_client:
self._async_client = get_async_client(
self._hass, verify_ssl=self._verify_ssl
)

_LOGGER.debug("Updating from %s", self._resource)
try:
response = await self._async_client.request(
self._method,
self._resource,
headers=self._headers,
params=self._params,
auth=self._auth,
data=self._request_data,
timeout=self._timeout,
)
self.data = response.text
self.headers = response.headers
except httpx.RequestError as ex:
if log_errors:
_LOGGER.error(
"Error fetching data: %s failed with %s", self._resource, ex
)
self.last_exception = ex
self.data = None
self.headers = None

await super().async_update(log_errors)
self.scrape_data()

0 comments on commit cefc000

Please sign in to comment.