Skip to content

Commit

Permalink
Fixed combining data from both sources #24
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkastelec committed Apr 21, 2022
1 parent 3fdb5d8 commit 32a213b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
1 change: 0 additions & 1 deletion custom_components/wemportal/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async def async_setup_platform(
entities: list[WemPortalNumber] = []
for unique_id, values in coordinator.data.items():
if values["platform"] == "number":
_LOGGER.warning(unique_id)
entities.append(WemPortalNumber(coordinator, unique_id, values))

async_add_entities(entities)
Expand Down
19 changes: 6 additions & 13 deletions custom_components/wemportal/wemportalapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import requests as reqs
import scrapyscript
from fuzzywuzzy import fuzz
from homeassistant.const import (CONF_PASSWORD, CONF_SCAN_INTERVAL,
CONF_USERNAME)
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from scrapy import FormRequest, Spider

from .const import (_LOGGER, CONF_LANGUAGE, CONF_MODE, CONF_SCAN_INTERVAL_API,
START_URLS)
from .const import _LOGGER, CONF_LANGUAGE, CONF_MODE, CONF_SCAN_INTERVAL_API, START_URLS


class WemPortalApi:
Expand Down Expand Up @@ -49,13 +47,7 @@ def __init__(self, config):
def fetch_data(self):

if self.mode == "web":
if (
self.last_scraping_update is None
or (datetime.now() - self.last_scraping_update + timedelta(seconds=5))
> self.update_interval
):
self.fetch_webscraping_data()
self.last_scraping_update = datetime.now()
self.fetch_webscraping_data()
elif self.mode == "api":
self.fetch_api_data()
else:
Expand Down Expand Up @@ -396,7 +388,7 @@ def get_data(self):
data[key]["friendlyName"],
scraped_entity.split("-")[1],
)
>= 85
>= 90
):
try:
self.scrapingMapper[key].append(
Expand All @@ -419,7 +411,7 @@ def get_data(self):
for scraped_entity in self.scrapingMapper[key]:
try:
self.data[scraped_entity] = {
"value": self.data[scraped_entity]["value"],
"value": data[key]["value"],
"name": self.data[scraped_entity]["name"],
"unit": self.data[scraped_entity]["unit"],
"icon": self.data[scraped_entity]["icon"],
Expand Down Expand Up @@ -476,6 +468,7 @@ def friendly_name_mapper(self, value):

def translate(self, language, value):
# TODO: Implement support for other languages.
value = value.lower()
translationDict = {
"en": {
"außsentemperatur": "outside_temperature",
Expand Down

0 comments on commit 32a213b

Please sign in to comment.