Skip to content

Commit

Permalink
Merge pull request #75 from erikkastelec/dev
Browse files Browse the repository at this point in the history
Bug fix for issue #74
  • Loading branch information
erikkastelec authored Jun 1, 2023
2 parents 4d3c89b + b22fd65 commit 9ae02d7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 65 deletions.
2 changes: 1 addition & 1 deletion custom_components/wemportal/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"documentation": "https://github.com/erikkastelec/hass-WEM-Portal",
"issue_tracker": "https://github.com/erikkastelec/hass-WEM-Portal/issues",
"dependencies": [],
"version": "1.5.7",
"version": "1.5.9",
"codeowners": [
"@erikkastelec"
],
Expand Down
117 changes: 53 additions & 64 deletions custom_components/wemportal/wemportalapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,19 +796,9 @@ def scrape_pages(self, response):
# if self.authErrorFlag != 0:
# yield {"authErrorFlag": self.authErrorFlag}
output = {}
for i, div in enumerate(
response.xpath(
'//div[@class="RadPanelBar RadPanelBar_Default rpbSimpleData"]'
)
):
header_query = (
"//span[@id='ctl00_rdMain_C_controlExtension_rptDisplayContent_ctl0"
+ str(i)
+ "_ctl00_rpbGroupData_i0_HeaderTemplate_lblHeaderText']/text() "
)
# Catch heading not starting at 0
try:
header = div.xpath(header_query).extract()[0]
for div in response.xpath('//div[contains(@class, "RadPanelBar RadPanelBar_Default rpbSimpleData")]'):
header = div.xpath('.//th[contains(@class, "simpleDataHeaderTextCell")]/span/text()').get()
if header is not None:
header = (
header.replace("/#", "")
.replace(" ", "")
Expand All @@ -817,63 +807,62 @@ def scrape_pages(self, response):
.replace(" ", "_")
.casefold()
)
except IndexError:
else:
header = "unknown"
continue
for td in div.xpath('.//table[@class="simpleDataTable"]//tr'):
for td in div.xpath('.//div[contains(@class, "rpTemplate")]/table[contains(@class, "simpleDataTable")]/tbody/tr'):
try:
name = td.xpath(
'.//td//span[@class="simpleDataName"]/text()'
).extract()[0]
value = td.xpath(
'.//td//span[@class="simpleDataValue"]/text()'
).extract()[0]
name = name.replace(" ", "").replace(" ", "_").casefold()
name = header + "-" + name
split_value = value.split(" ")
unit = ""
if len(split_value) >= 2:
value = split_value[0]
unit = split_value[1]
else:
value = split_value[0]
try:
value = ".".join(value.split(","))
value = float(value)
except ValueError:
if value in [
"off",
"Aus",
"--",
"Label ist null",
"Label ist null ",
]:
value = 0.0
elif value in [
"Ein"
]:
value = 1.0
name = td.xpath('.//td[contains(@class, "simpleDataNameCell")]/span/text()').get()
value = td.xpath('.//td[contains(@class, "simpleDataValueCell") or contains(@class, "simpleDataValueEnumCell")]/span/text()').get()
if name is not None and value is not None:
name = name.replace(" ", "").replace(" ", "_").casefold()
name = header + "-" + name
split_value = value.split(" ")
unit = ""
if len(split_value) >= 2:
value = split_value[0]
unit = split_value[1]
else:
unit = None

if(name.endswith('leistungsanforderung')):
unit = '%'

icon_mapper = defaultdict(lambda: "mdi:flash")
icon_mapper["°C"] = "mdi:thermometer"

output[name] = {
"value": value,
"name": name,
"icon": icon_mapper[unit],
"unit": unit,
"platform": "sensor",
"friendlyName": name,
"ParameterID": name,
}
except IndexError:
value = split_value[0]
try:
value = ".".join(value.split(","))
value = float(value)
except ValueError:
if value in [
"off",
"Aus",
"--",
"Label ist null",
"Label ist null ",
]:
value = 0.0
elif value in [
"Ein"
]:
value = 1.0
else:
unit = None

if(name.endswith('leistungsanforderung')):
unit = '%'

icon_mapper = defaultdict(lambda: "mdi:flash")
icon_mapper["°C"] = "mdi:thermometer"

output[name] = {
"value": value,
"name": name,
"icon": icon_mapper[unit],
"unit": unit,
"platform": "sensor",
"friendlyName": name,
"ParameterID": name,
}
except (IndexError, ValueError):
continue


output["cookie"] = self.cookie

yield output

0 comments on commit 9ae02d7

Please sign in to comment.