Skip to content

Commit 510dcaf

Browse files
authored
Merge pull request #990 from plugwise/test-alt
Revert exception-changes, line up with Core Plugwise, missed snapshot-update
2 parents 64e5a25 + f4f370e commit 510dcaf

File tree

8 files changed

+72
-66
lines changed

8 files changed

+72
-66
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Versions from 0.40 and up
44

5+
## Ongoing
6+
7+
- Revert exceptions-move in coordinator.py, line up with Core Plugwise via PR [#990](https://github.com/plugwise/plugwise-beta/pull/990)
8+
59
## v0.62.1
610

711
- Implement Core PR's [#158901](https://github.com/home-assistant/core/pull/158901) and [#158094](https://github.com/home-assistant/core/pull/158094)

custom_components/plugwise/coordinator.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -87,34 +87,7 @@ async def _connect(self) -> None:
8787
8888
A Version object is received when the connection succeeds.
8989
"""
90-
try:
91-
version = await self.api.connect()
92-
except ConnectionFailedError as err:
93-
raise UpdateFailed(
94-
translation_domain=DOMAIN,
95-
translation_key="failed_to_connect",
96-
) from err
97-
except InvalidAuthentication as err:
98-
raise ConfigEntryError(
99-
translation_domain=DOMAIN,
100-
translation_key="authentication_failed",
101-
) from err
102-
except InvalidSetupError as err:
103-
raise ConfigEntryError(
104-
translation_domain=DOMAIN,
105-
translation_key="invalid_setup",
106-
) from err
107-
except (InvalidXMLError, ResponseError) as err:
108-
raise UpdateFailed(
109-
translation_domain=DOMAIN,
110-
translation_key="invalid_xml_data",
111-
) from err
112-
except UnsupportedDeviceError as err:
113-
raise ConfigEntryError(
114-
translation_domain=DOMAIN,
115-
translation_key="unsupported_firmware",
116-
) from err
117-
90+
version = await self.api.connect()
11891
self._connected = isinstance(version, Version)
11992
if self._connected:
12093
self.update_interval = DEFAULT_SCAN_INTERVAL.get(
@@ -125,7 +98,7 @@ async def _connect(self) -> None:
12598
seconds=int(custom_time)
12699
) # pragma: no cover # pw-beta options
127100

128-
LOGGER.debug("DUC update interval: %s", self.update_interval) # pw-beta options
101+
LOGGER.debug("DUC update interval: %s", self.update_interval) # pw-beta options
129102

130103
async def _async_setup(self) -> None:
131104
"""Initialize the update_data process."""
@@ -142,15 +115,40 @@ async def _async_setup(self) -> None:
142115

143116
async def _async_update_data(self) -> dict[str, GwEntityData]:
144117
"""Fetch data from Plugwise."""
145-
if not self._connected:
146-
await self._connect()
147118
try:
119+
if not self._connected:
120+
await self._connect()
148121
data = await self.api.async_update()
122+
except ConnectionFailedError as err:
123+
raise UpdateFailed(
124+
translation_domain=DOMAIN,
125+
translation_key="failed_to_connect",
126+
) from err
127+
except InvalidAuthentication as err:
128+
raise ConfigEntryError(
129+
translation_domain=DOMAIN,
130+
translation_key="authentication_failed",
131+
) from err
132+
except InvalidSetupError as err:
133+
raise ConfigEntryError(
134+
translation_domain=DOMAIN,
135+
translation_key="invalid_setup",
136+
) from err
137+
except (InvalidXMLError, ResponseError) as err:
138+
raise UpdateFailed(
139+
translation_domain=DOMAIN,
140+
translation_key="response_error",
141+
) from err
149142
except PlugwiseError as err:
150143
raise UpdateFailed(
151144
translation_domain=DOMAIN,
152145
translation_key="data_incomplete_or_missing",
153146
) from err
147+
except UnsupportedDeviceError as err:
148+
raise ConfigEntryError(
149+
translation_domain=DOMAIN,
150+
translation_key="unsupported_firmware",
151+
) from err
154152

155153
await self._async_add_remove_devices(data)
156154
LOGGER.debug("%s data: %s", self.api.smile.name, data)

custom_components/plugwise/strings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"invalid_setup": "Add your Adam instead of your Anna, see the documentation",
4343
"network_down": "Plugwise Zigbee network is down",
4444
"network_timeout": "Network communication timeout",
45-
"response_error": "Invalid XML data, or error indication received",
45+
"response_error": "Invalid XML data, or error indication received from the Plugwise Adam/Smile/Stretch",
4646
"stick_init": "Initialization of Plugwise USB-stick failed",
4747
"unknown": "Unknown error!",
4848
"unsupported": "Device with unsupported firmware"
@@ -323,7 +323,10 @@
323323
"failed_to_connect": {
324324
"message": "Failed to connect"
325325
},
326-
"invalid_xml_data": {
326+
"invalid_setup": {
327+
"message": "Add your Adam instead of your Anna, see the documentation"
328+
},
329+
"response_error": {
327330
"message": "Invalid XML data, or error indication received from the Plugwise Adam/Smile/Stretch"
328331
},
329332
"set_schedule_first": {

custom_components/plugwise/translations/en.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"invalid_setup": "Add your Adam instead of your Anna, see the documentation",
1313
"network_down": "Plugwise Zigbee network is down",
1414
"network_timeout": "Network communication timeout",
15-
"response_error": "Invalid XML data, or error indication received",
15+
"response_error": "Invalid XML data, or error indication received from the Plugwise Adam/Smile/Stretch",
1616
"stick_init": "Initialization of Plugwise USB-stick failed",
1717
"unknown": "Unknown error!",
1818
"unsupported": "Device with unsupported firmware"
@@ -306,7 +306,10 @@
306306
"failed_to_connect": {
307307
"message": "Failed to connect"
308308
},
309-
"invalid_xml_data": {
309+
"invalid_setup": {
310+
"message": "Add your Adam instead of your Anna, see the documentation"
311+
},
312+
"response_error": {
310313
"message": "Invalid XML data, or error indication received from the Plugwise Adam/Smile/Stretch"
311314
},
312315
"set_schedule_first": {

custom_components/plugwise/translations/nl.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"invalid_setup": "Voeg je Adam toe in plaats van je Anna, lees de documentatie",
4343
"network_down": "Plugwise Zigbee netwerk is onbereikbaar",
4444
"network_timeout": "Network communicatie timeout",
45-
"response_error": "Ongeldige XML data, of error-indicatie ontvangen",
45+
"response_error": "Ongeldige XML data, of foutmelding ontvangen van de Plugwise Adam/Smile/Stretch",
4646
"stick_init": "Initaliseren van USB-stick mislukt",
4747
"unknown": "Onbekende fout!",
4848
"unsupported": "Apparaat met onbekende firmware"
@@ -321,7 +321,10 @@
321321
"failed_to_connect": {
322322
"message": "Verbinden mislukt"
323323
},
324-
"invalid_xml_data": {
324+
"invalid_setup": {
325+
"message": "Voeg je Adam toe in plaats van je Anna, lees de documentatie"
326+
},
327+
"response_error": {
325328
"message": "Ongeldige XML data, of foutmelding ontvangen van de Plugwise Adam/Smile/Stretch"
326329
},
327330
"set_schedule_first": {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "plugwise-beta"
3-
version = "0.62.1"
3+
version = "0.62.2"
44
description = "Plugwise beta custom-component"
55
readme = "README.md"
66
requires-python = ">=3.13"

tests/components/plugwise/snapshots/test_select.ambr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
'device_id': <ANY>,
142142
'disabled_by': None,
143143
'domain': 'select',
144-
'entity_category': <EntityCategory.CONFIG: 'config'>,
144+
'entity_category': None,
145145
'entity_id': 'select.bathroom_thermostat_schedule',
146146
'has_entity_name': True,
147147
'hidden_by': None,
@@ -263,7 +263,7 @@
263263
'device_id': <ANY>,
264264
'disabled_by': None,
265265
'domain': 'select',
266-
'entity_category': <EntityCategory.CONFIG: 'config'>,
266+
'entity_category': None,
267267
'entity_id': 'select.living_room_thermostat_schedule',
268268
'has_entity_name': True,
269269
'hidden_by': None,
@@ -386,7 +386,7 @@
386386
'device_id': <ANY>,
387387
'disabled_by': None,
388388
'domain': 'select',
389-
'entity_category': <EntityCategory.CONFIG: 'config'>,
389+
'entity_category': None,
390390
'entity_id': 'select.badkamer_thermostat_schedule',
391391
'has_entity_name': True,
392392
'hidden_by': None,
@@ -451,7 +451,7 @@
451451
'device_id': <ANY>,
452452
'disabled_by': None,
453453
'domain': 'select',
454-
'entity_category': <EntityCategory.CONFIG: 'config'>,
454+
'entity_category': None,
455455
'entity_id': 'select.bios_thermostat_schedule',
456456
'has_entity_name': True,
457457
'hidden_by': None,
@@ -516,7 +516,7 @@
516516
'device_id': <ANY>,
517517
'disabled_by': None,
518518
'domain': 'select',
519-
'entity_category': <EntityCategory.CONFIG: 'config'>,
519+
'entity_category': None,
520520
'entity_id': 'select.jessie_thermostat_schedule',
521521
'has_entity_name': True,
522522
'hidden_by': None,
@@ -581,7 +581,7 @@
581581
'device_id': <ANY>,
582582
'disabled_by': None,
583583
'domain': 'select',
584-
'entity_category': <EntityCategory.CONFIG: 'config'>,
584+
'entity_category': None,
585585
'entity_id': 'select.woonkamer_thermostat_schedule',
586586
'has_entity_name': True,
587587
'hidden_by': None,

tests/components/plugwise/test_init.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from freezegun.api import FrozenDateTimeFactory
1717
from homeassistant.components.plugwise.const import DOMAIN
18-
from homeassistant.components.plugwise.coordinator import PlugwiseDataUpdateCoordinator
1918
from homeassistant.config_entries import ConfigEntryState
2019
from homeassistant.const import (
2120
CONF_HOST,
@@ -27,9 +26,7 @@
2726
Platform,
2827
)
2928
from homeassistant.core import HomeAssistant
30-
from homeassistant.exceptions import ConfigEntryError
3129
from homeassistant.helpers import device_registry as dr, entity_registry as er
32-
from homeassistant.helpers.update_coordinator import UpdateFailed
3330
from homeassistant.setup import async_setup_component
3431

3532
from tests.common import MockConfigEntry, async_fire_time_changed
@@ -104,7 +101,7 @@ async def test_gateway_config_entry_not_ready(
104101
mock_smile_anna: MagicMock,
105102
side_effect: Exception,
106103
) -> None:
107-
"""Test the Plugwise configuration entry not ready."""
104+
"""Test the Plugwise config-entry not being ready."""
108105
mock_smile_anna.async_update.side_effect = side_effect
109106

110107
mock_config_entry.add_to_hass(hass)
@@ -118,32 +115,33 @@ async def test_gateway_config_entry_not_ready(
118115
@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True)
119116
@pytest.mark.parametrize("cooling_present", [True], indirect=True)
120117
@pytest.mark.parametrize(
121-
("side_effect", "expected_raise"),
118+
("side_effect", "entry_state"),
122119
[
123-
(ConnectionFailedError, UpdateFailed),
124-
(InvalidAuthentication, ConfigEntryError),
125-
(InvalidSetupError, ConfigEntryError),
126-
(InvalidXMLError, UpdateFailed),
127-
(ResponseError, UpdateFailed),
128-
(UnsupportedDeviceError, ConfigEntryError),
120+
(ConnectionFailedError, ConfigEntryState.SETUP_RETRY),
121+
(InvalidAuthentication, ConfigEntryState.SETUP_ERROR),
122+
(InvalidSetupError, ConfigEntryState.SETUP_ERROR),
123+
(InvalidXMLError, ConfigEntryState.SETUP_RETRY),
124+
(ResponseError, ConfigEntryState.SETUP_RETRY),
125+
(PlugwiseError, ConfigEntryState.SETUP_RETRY),
126+
(UnsupportedDeviceError, ConfigEntryState.SETUP_ERROR),
129127
],
130128
)
131129
async def test_coordinator_connect_exceptions(
132130
hass: HomeAssistant,
133131
mock_config_entry: MockConfigEntry,
134132
mock_smile_anna: MagicMock,
135133
side_effect: Exception,
136-
expected_raise: Exception,
134+
entry_state: ConfigEntryState,
137135
) -> None:
138136
"""Ensure _connect raises translated errors."""
139137
mock_smile_anna.connect.side_effect = side_effect
140-
coordinator = PlugwiseDataUpdateCoordinator(
141-
hass,
142-
cooldown=0,
143-
config_entry=mock_config_entry,
144-
)
145-
with pytest.raises(expected_raise):
146-
await coordinator._connect()
138+
139+
mock_config_entry.add_to_hass(hass)
140+
await hass.config_entries.async_setup(mock_config_entry.entry_id)
141+
await hass.async_block_till_done()
142+
143+
assert len(mock_smile_anna.connect.mock_calls) == 1
144+
assert mock_config_entry.state is entry_state
147145

148146

149147
@pytest.mark.parametrize("chosen_env", ["p1v4_442_single"], indirect=True)
@@ -360,9 +358,6 @@ async def test_delete_removed_device(
360358
) -> None:
361359
"""Test device removal at integration init."""
362360
data = mock_smile_adam_heat_cool.async_update.return_value
363-
mock_config_entry.add_to_hass(hass)
364-
assert await async_setup_component(hass, DOMAIN, {})
365-
await hass.async_block_till_done()
366361

367362
item_list: list[str] = []
368363
for device_entry in device_registry.devices.values():

0 commit comments

Comments
 (0)