Skip to content

Commit 320184b

Browse files
authored
Fix exception handling for channel errors (#16)
* Exception handling for channel errors * Update readme * Bump to 1.0.12
1 parent 14359e8 commit 320184b

6 files changed

Lines changed: 44 additions & 26 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ You probably **do not** want to do this! Use one of the HACS methods above unles
4242

4343
### Configuration
4444

45+
**Attention**: To be able to use all entities, an installer or administrator account (as defined in the SMA EV Charger web UI) must be used!
46+
4547
1. [Click Here](https://my.home-assistant.io/redirect/config_flow_start/?domain=smaev) to directly add a `SMA EV Charger` integration **or**<br/>
4648
a. In Home Assistant, go to Settings -> [Integrations](https://my.home-assistant.io/redirect/integrations/)<br/>
4749
b. Click `+ Add Integrations` and select `SMA EV Charger`<br/>

custom_components/smaev/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"homekit": {},
99
"iot_class": "local_polling",
1010
"issue_tracker": "https://github.com/alengwenus/ha-sma-ev-charger/issues",
11-
"requirements": ["pysmaev==0.1.5"],
11+
"requirements": ["pysmaev==0.1.6"],
1212
"ssdp": [],
13-
"version": "1.0.11",
13+
"version": "1.0.12",
1414
"zeroconf": []
1515
}

custom_components/smaev/number.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
from typing import TYPE_CHECKING
88

9+
from pysmaev.exceptions import SmaEvChargerChannelError
910
from pysmaev.helpers import get_parameters_channel
1011

1112
from homeassistant.components.number import (
@@ -159,10 +160,13 @@ def __init__(
159160
@callback
160161
def _handle_coordinator_update(self) -> None:
161162
"""Handle updated data from the coordinator."""
162-
channel = get_parameters_channel(
163-
self.coordinator.data[SMAEV_PARAMETER],
164-
self.entity_description.channel,
165-
)
163+
try:
164+
channel = get_parameters_channel(
165+
self.coordinator.data[SMAEV_PARAMETER],
166+
self.entity_description.channel,
167+
)
168+
except SmaEvChargerChannelError:
169+
return
166170

167171
min_value = channel.get(SMAEV_MIN_VALUE)
168172
max_value = channel.get(SMAEV_MAX_VALUE)

custom_components/smaev/select.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import TYPE_CHECKING
88

99
from pysmaev.const import SmaEvChargerParameters
10+
from pysmaev.exceptions import SmaEvChargerChannelError
1011
from pysmaev.helpers import get_parameters_channel
1112

1213
from homeassistant.components.select import SelectEntity, SelectEntityDescription
@@ -127,10 +128,13 @@ def __init__(
127128
@callback
128129
def _handle_coordinator_update(self) -> None:
129130
"""Handle updated data from the coordinator."""
130-
channel = get_parameters_channel(
131-
self.coordinator.data[SMAEV_PARAMETER],
132-
self.entity_description.channel,
133-
)
131+
try:
132+
channel = get_parameters_channel(
133+
self.coordinator.data[SMAEV_PARAMETER],
134+
self.entity_description.channel,
135+
)
136+
except SmaEvChargerChannelError:
137+
return
134138

135139
possible_values = channel[SMAEV_POSSIBLE_VALUES]
136140
value = channel[SMAEV_VALUE]

custom_components/smaev/sensor.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import TYPE_CHECKING
77

88
from pysmaev.const import SmaEvChargerMeasurements
9+
from pysmaev.exceptions import SmaEvChargerChannelError
910
from pysmaev.helpers import get_measurements_channel, get_parameters_channel
1011

1112
from homeassistant.components.sensor import (
@@ -237,18 +238,21 @@ def __init__(
237238
@callback
238239
def _handle_coordinator_update(self) -> None:
239240
"""Handle updated data from the coordinator."""
240-
if self.entity_description.type == SMAEV_MEASUREMENT:
241-
channel = get_measurements_channel(
242-
self.coordinator.data[SMAEV_MEASUREMENT],
243-
self.entity_description.channel,
244-
)
245-
value = channel[0][SMAEV_VALUE]
246-
else: # SMAEV_PARAMETER
247-
channel = get_parameters_channel(
248-
self.coordinator.data[SMAEV_PARAMETER],
249-
self.entity_description.channel,
250-
)
251-
value = channel[SMAEV_VALUE]
241+
try:
242+
if self.entity_description.type == SMAEV_MEASUREMENT:
243+
channel = get_measurements_channel(
244+
self.coordinator.data[SMAEV_MEASUREMENT],
245+
self.entity_description.channel,
246+
)
247+
value = channel[0][SMAEV_VALUE]
248+
else: # SMAEV_PARAMETER
249+
channel = get_parameters_channel(
250+
self.coordinator.data[SMAEV_PARAMETER],
251+
self.entity_description.channel,
252+
)
253+
value = channel[SMAEV_VALUE]
254+
except SmaEvChargerChannelError:
255+
return
252256

253257
value = self.entity_description.value_mapping.get(value, value)
254258

custom_components/smaev/switch.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import TYPE_CHECKING, Any
77

88
from pysmaev.const import SmaEvChargerParameters
9+
from pysmaev.exceptions import SmaEvChargerChannelError
910
from pysmaev.helpers import get_parameters_channel
1011

1112
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
@@ -120,10 +121,13 @@ def __init__(
120121
@callback
121122
def _handle_coordinator_update(self) -> None:
122123
"""Handle updated data from the coordinator."""
123-
channel = get_parameters_channel(
124-
self.coordinator.data[SMAEV_PARAMETER],
125-
self.entity_description.channel,
126-
)
124+
try:
125+
channel = get_parameters_channel(
126+
self.coordinator.data[SMAEV_PARAMETER],
127+
self.entity_description.channel,
128+
)
129+
except SmaEvChargerChannelError:
130+
return
127131

128132
value = channel[SMAEV_VALUE]
129133
self._attr_is_on = self.entity_description.value_mapping.get(value, value)

0 commit comments

Comments
 (0)