Skip to content

Commit c6a57bc

Browse files
authored
Bump pyOverkiz to 2.0.0 in Overkiz (home-assistant#173212)
1 parent 4171f56 commit c6a57bc

50 files changed

Lines changed: 1273 additions & 1182 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

homeassistant/components/overkiz/__init__.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
from dataclasses import dataclass
55

66
from aiohttp import ClientError
7+
from pyoverkiz.auth.credentials import (
8+
LocalTokenCredentials,
9+
UsernamePasswordCredentials,
10+
)
711
from pyoverkiz.client import OverkizClient
8-
from pyoverkiz.const import SUPPORTED_SERVERS
9-
from pyoverkiz.enums import APIType, OverkizState, UIClass, UIWidget
12+
from pyoverkiz.enums import APIType, OverkizState, Server, UIClass, UIWidget
1013
from pyoverkiz.exceptions import (
11-
BadCredentialsException,
12-
MaintenanceException,
13-
NotAuthenticatedException,
14-
NotSuchTokenException,
15-
TooManyRequestsException,
14+
BadCredentialsError,
15+
MaintenanceError,
16+
NoSuchTokenError,
17+
NotAuthenticatedError,
18+
TooManyRequestsError,
1619
)
17-
from pyoverkiz.models import Device, OverkizServer, Scenario
18-
from pyoverkiz.utils import generate_local_server
20+
from pyoverkiz.models import Device, PersistedActionGroup
21+
from pyoverkiz.utils import create_local_server_config
1922

2023
from homeassistant.config_entries import ConfigEntry
2124
from homeassistant.const import (
@@ -58,7 +61,7 @@ class HomeAssistantOverkizData:
5861

5962
coordinator: OverkizDataUpdateCoordinator
6063
platforms: defaultdict[Platform, list[Device]]
61-
scenarios: list[Scenario]
64+
scenarios: list[PersistedActionGroup]
6265

6366

6467
type OverkizDataConfigEntry = ConfigEntry[HomeAssistantOverkizData]
@@ -90,7 +93,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OverkizDataConfigEntry)
9093
hass,
9194
username=entry.data[CONF_USERNAME],
9295
password=entry.data[CONF_PASSWORD],
93-
server=SUPPORTED_SERVERS[entry.data[CONF_HUB]],
96+
server=entry.data[CONF_HUB],
9497
)
9598

9699
try:
@@ -100,20 +103,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: OverkizDataConfigEntry)
100103
# Local API does expose scenarios, but they are not functional.
101104
# Tracked in https://github.com/Somfy-Developer/Somfy-TaHoma-Developer-Mode/issues/21
102105
if api_type == APIType.CLOUD:
103-
scenarios = await client.get_scenarios()
106+
scenarios = await client.get_action_groups()
104107
else:
105108
scenarios = []
106109
except (
107-
BadCredentialsException,
108-
NotSuchTokenException,
109-
NotAuthenticatedException,
110+
BadCredentialsError,
111+
NoSuchTokenError,
112+
NotAuthenticatedError,
110113
) as exception:
111114
raise ConfigEntryAuthFailed("Invalid authentication") from exception
112-
except TooManyRequestsException as exception:
115+
except TooManyRequestsError as exception:
113116
raise ConfigEntryNotReady("Too many requests, try again later") from exception
114117
except (TimeoutError, ClientError) as exception:
115118
raise ConfigEntryNotReady("Failed to connect") from exception
116-
except MaintenanceException as exception:
119+
except MaintenanceError as exception:
117120
raise ConfigEntryNotReady("Server is down for maintenance") from exception
118121

119122
coordinator = OverkizDataUpdateCoordinator(
@@ -173,13 +176,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: OverkizDataConfigEntry)
173176
identifiers={(DOMAIN, gateway.id)},
174177
model=gateway.type.beautify_name if gateway.type else None,
175178
model_id=str(gateway.type),
176-
manufacturer=client.server.manufacturer,
179+
manufacturer=client.server_config.manufacturer,
177180
name=gateway.type.beautify_name if gateway.type else gateway.id,
178181
sw_version=gateway.connectivity.protocol_version,
179182
hw_version=f"{gateway.type}:{gateway.sub_type}"
180183
if gateway.type and gateway.sub_type
181184
else None,
182-
configuration_url=client.server.configuration_url,
185+
configuration_url=client.server_config.configuration_url,
183186
)
184187

185188
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
@@ -214,6 +217,9 @@ async def _async_migrate_strenum_unique_ids(
214217
"""Migrate entities to the StrEnum-style unique IDs."""
215218
entity_registry = er.async_get(hass)
216219

220+
# Map enum members renamed in pyoverkiz 2.0 to their current names.
221+
renamed_enum_members = {"TSKALARM_CONTROLLER": "TSK_ALARM_CONTROLLER"}
222+
217223
@callback
218224
def update_unique_id(entry: er.RegistryEntry) -> dict[str, str] | None:
219225
# Python 3.11 treats (str, Enum) and StrEnum
@@ -229,6 +235,7 @@ def update_unique_id(entry: er.RegistryEntry) -> dict[str, str] | None:
229235
("OverkizState", "UIWidget", "UIClass")
230236
):
231237
state = key.split(".")[1]
238+
state = renamed_enum_members.get(state, state)
232239
new_key = ""
233240

234241
if key.startswith("UIClass"):
@@ -276,23 +283,23 @@ def create_local_client(
276283
session = async_create_clientsession(hass, verify_ssl=verify_ssl)
277284

278285
return OverkizClient(
279-
username="",
280-
password="",
281-
token=token,
286+
server=create_local_server_config(host=host),
287+
credentials=LocalTokenCredentials(token),
282288
session=session,
283-
server=generate_local_server(host=host),
284289
verify_ssl=verify_ssl,
285290
)
286291

287292

288293
def create_cloud_client(
289-
hass: HomeAssistant, username: str, password: str, server: OverkizServer
294+
hass: HomeAssistant, username: str, password: str, server: Server
290295
) -> OverkizClient:
291296
"""Create Overkiz cloud client."""
292297
# To allow users with multiple accounts/hubs, we create a
293298
# new session so they have separate cookies
294299
session = async_create_clientsession(hass)
295300

296301
return OverkizClient(
297-
username=username, password=password, session=session, server=server
302+
server=server,
303+
credentials=UsernamePasswordCredentials(username, password),
304+
session=session,
298305
)

homeassistant/components/overkiz/alarm_control_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _state_alarm_panel_controller(
144144
# Disabled by default since all Overkiz hubs have this
145145
# virtual device, but only a few users actually use this.
146146
OverkizAlarmDescription(
147-
key=UIWidget.TSKALARM_CONTROLLER,
147+
key=UIWidget.TSK_ALARM_CONTROLLER,
148148
entity_registry_enabled_default=False,
149149
supported_features=(
150150
AlarmControlPanelEntityFeature.ARM_AWAY

homeassistant/components/overkiz/binary_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ async def async_setup_entry(
165165
description,
166166
)
167167
for state in device.definition.states
168-
if (description := SUPPORTED_STATES.get(state.qualified_name))
168+
if (description := SUPPORTED_STATES.get(state))
169169
)
170170

171171
async_add_entities(entities)

homeassistant/components/overkiz/button.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async def async_setup_entry(
120120
description,
121121
)
122122
for command in device.definition.commands
123-
if (description := SUPPORTED_COMMANDS.get(command.command_name))
123+
if (description := SUPPORTED_COMMANDS.get(command))
124124
)
125125

126126
async_add_entities(entities)

homeassistant/components/overkiz/climate/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@ async def async_setup_entry(
115115
# Match devices based on the widget and protocol.
116116
# #ie Hitachi Air To Air Heat Pumps
117117
entities_based_on_widget_and_protocol: list[Entity] = [
118-
WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY[device.widget][device.protocol](
119-
device.device_url, data.coordinator
120-
)
118+
WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY[device.widget][
119+
device.identifier.protocol
120+
](device.device_url, data.coordinator)
121121
for device in data.platforms[Platform.CLIMATE]
122122
if device.widget in WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY
123-
and device.protocol in WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY[device.widget]
123+
and device.identifier.protocol
124+
in WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY[device.widget]
124125
]
125126

126127
async_add_entities(

homeassistant/components/overkiz/climate/atlantic_electrical_heater_with_adjustable_temperature_setpoint.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,17 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
157157
@property
158158
def target_temperature(self) -> float | None:
159159
"""Return the temperature."""
160-
if state := self.device.states[OverkizState.CORE_TARGET_TEMPERATURE]:
160+
if state := self.device.states.get(OverkizState.CORE_TARGET_TEMPERATURE):
161161
return state.value_as_float
162162
return None
163163

164164
@property
165165
def current_temperature(self) -> float | None:
166166
"""Return the current temperature."""
167167
if self.temperature_device is not None and (
168-
temperature := self.temperature_device.states[OverkizState.CORE_TEMPERATURE]
168+
temperature := self.temperature_device.states.get(
169+
OverkizState.CORE_TEMPERATURE
170+
)
169171
):
170172
return temperature.value_as_float
171173
return None

homeassistant/components/overkiz/climate/atlantic_electrical_towel_dryer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def target_temperature(self) -> float | None:
104104
def current_temperature(self) -> float | None:
105105
"""Return the current temperature."""
106106
if self.temperature_device is not None and (
107-
temperature := self.temperature_device.states[OverkizState.CORE_TEMPERATURE]
107+
temperature := self.temperature_device.states.get(
108+
OverkizState.CORE_TEMPERATURE
109+
)
108110
):
109111
return cast(float, temperature.value)
110112

homeassistant/components/overkiz/climate/atlantic_heat_recovery_ventilation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def __init__(
6767
def current_temperature(self) -> float | None:
6868
"""Return the current temperature."""
6969
if self.temperature_device is not None and (
70-
temperature := self.temperature_device.states[OverkizState.CORE_TEMPERATURE]
70+
temperature := self.temperature_device.states.get(
71+
OverkizState.CORE_TEMPERATURE
72+
)
7173
):
7274
return cast(float, temperature.value)
7375

homeassistant/components/overkiz/climate/atlantic_pass_apc_heating_zone.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ def __init__(
106106
def current_temperature(self) -> float | None:
107107
"""Return the current temperature."""
108108
if self.temperature_device is not None and (
109-
temperature := self.temperature_device.states[OverkizState.CORE_TEMPERATURE]
109+
temperature := self.temperature_device.states.get(
110+
OverkizState.CORE_TEMPERATURE
111+
)
110112
):
111113
return cast(float, temperature.value)
112114

homeassistant/components/overkiz/climate/evo_home_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
7474
def preset_mode(self) -> str | None:
7575
"""Return the current preset mode, e.g., home, away, temp."""
7676
if (
77-
state := self.device.states[OverkizState.RAMSES_RAMSES_OPERATING_MODE]
77+
state := self.device.states.get(OverkizState.RAMSES_RAMSES_OPERATING_MODE)
7878
) and state.value_as_str in OVERKIZ_TO_PRESET_MODES:
7979
return OVERKIZ_TO_PRESET_MODES[state.value_as_str]
8080

0 commit comments

Comments
 (0)