Skip to content

Commit

Permalink
make sure that sensors never return dict's as value
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Jan 14, 2025
1 parent 6e7edda commit fe3e9a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
9 changes: 3 additions & 6 deletions .github/ISSUE_TEMPLATE/1-report-an-issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ body:
- type: markdown
attributes:
value: |
## Issue with `chargerPhases1p3p` is already fixed! - Update your integration via HACS to get the latest version!
## HACs does not always notify you about new version's - you must check do this manually!
Please follow this routine:
1. In Home Assistant go to `HACS`
2. In the list of installed integrations search for `evcc`
3. Click on the 3-dot menu on the right side of the `evcc` integration list entry
Expand All @@ -30,11 +31,7 @@ body:
required: true
- label: I confirm it's really an issue | In the case that you want to understand the functionality of a certain feature/sensor Please be so kind and make use if the discussion feature of this repo (and do not create an issue) - TIA
- label: |
I confirm, that I did not read any of the previous bulletin-points and just checked them all.
I don't wanted to waste my time with details, I don't read or follow any existing instructions.
Instead, I want that the maintainers of this repro will spend time explaining the world to me - that's their job!.
I live by the motto: Better to ask than to think about it once.
It's the maintainers' own fault that they provide open-source software and are willing to offer free support.
I confirm, that I did not read any of the previous bulletin-points and just checked them all. | I don't wanted to waste my time with details, I don't read or follow any existing instructions. | Instead, I want that the maintainers of this repro will spend time explaining the world to me - that's their job!. | I live by the motto: Better to ask than to think about it once. | It's the maintainers' own fault that they provide open-source software and are willing to offer free support.
- type: textarea
id: content
attributes:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/evcc_intg/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-evcc/issues",
"requirements": [],
"version": "2025.1.4"
"version": "2025.1.5"
}
35 changes: 17 additions & 18 deletions custom_components/evcc_intg/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,23 @@ def native_value(self):
"""Return the state of the sensor."""
try:
value = self.coordinator.read_tag(self.tag, self.idx)
if isinstance(value, list):
if self.entity_description.tuple_idx is not None and len(self.entity_description.tuple_idx) > 1:
array_idx1 = self.entity_description.tuple_idx[0]
array_idx2 = self.entity_description.tuple_idx[1]
if len(value) > array_idx1 or array_idx1 in value:
value = value[array_idx1]
if isinstance(value, list) and len(value) > array_idx2 or array_idx2 in value:
value = value[array_idx2]

elif self.entity_description.array_idx is not None:
array_idx = self.entity_description.array_idx
if len(value) > array_idx or array_idx in value:
value = value[array_idx]

if isinstance(value, list):
# if the value is a list, but could not be extracted (cause of none matching indices) we need
# to purge the value to None!
value = None
if hasattr(self.entity_description, "tuple_idx") and self.entity_description.tuple_idx is not None and len(self.entity_description.tuple_idx) > 1:
array_idx1 = self.entity_description.tuple_idx[0]
array_idx2 = self.entity_description.tuple_idx[1]
if len(value) > array_idx1 or array_idx1 in value:
value = value[array_idx1]
if len(value) > array_idx2 or array_idx2 in value:
value = value[array_idx2]

elif hasattr(self.entity_description, "array_idx") and self.entity_description.array_idx is not None:
array_idx = self.entity_description.array_idx
if len(value) > array_idx or array_idx in value:
value = value[array_idx]

if isinstance(value, (dict, list)):
# if the value is a list (or dict), but could not be extracted (cause of none matching indices) we need
# to purge the value to None!
value = None

if value is None or len(str(value)) == 0:
value = None
Expand Down

0 comments on commit fe3e9a1

Please sign in to comment.