|
4 | 4 |
|
5 | 5 | import asyncio
|
6 | 6 | import binascii
|
7 |
| -import collections |
8 | 7 | from collections.abc import Callable
|
9 |
| -import dataclasses |
10 | 8 | from dataclasses import dataclass
|
11 |
| -import datetime |
12 | 9 | import enum
|
13 | 10 | import logging
|
14 | 11 | import re
|
15 | 12 | from typing import TYPE_CHECKING, Any, ParamSpec, TypeVar
|
16 | 13 |
|
17 |
| -from aiohttp import ClientSession |
18 |
| -from pydantic import Field |
19 | 14 | import voluptuous as vol
|
20 | 15 | import zigpy.exceptions
|
21 | 16 | import zigpy.types
|
|
24 | 19 | from zigpy.zcl.foundation import CommandSchema
|
25 | 20 | import zigpy.zdo.types as zdo_types
|
26 | 21 |
|
27 |
| -from zha.application import Platform |
28 |
| -from zha.application.const import ( |
29 |
| - CLUSTER_TYPE_IN, |
30 |
| - CLUSTER_TYPE_OUT, |
31 |
| - CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY, |
32 |
| - CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS, |
33 |
| -) |
| 22 | +from zha.application.const import CLUSTER_TYPE_IN, CLUSTER_TYPE_OUT |
34 | 23 | from zha.async_ import gather_with_limited_concurrency
|
35 | 24 | from zha.decorators import periodic
|
36 |
| -from zha.model import BaseModel |
| 25 | +from zha.zigbee.cluster_handlers.registries import BINDABLE_CLUSTERS |
37 | 26 |
|
38 | 27 | if TYPE_CHECKING:
|
39 | 28 | from zha.application.gateway import Gateway
|
@@ -92,9 +81,6 @@ async def get_matched_clusters(
|
92 | 81 | source_zha_device: Device, target_zha_device: Device
|
93 | 82 | ) -> list[BindingPair]:
|
94 | 83 | """Get matched input/output cluster pairs for 2 devices."""
|
95 |
| - from zha.zigbee.cluster_handlers.registries import ( # pylint: disable=import-outside-toplevel |
96 |
| - BINDABLE_CLUSTERS, |
97 |
| - ) |
98 | 84 |
|
99 | 85 | source_clusters = source_zha_device.async_get_std_clusters()
|
100 | 86 | target_clusters = target_zha_device.async_get_std_clusters()
|
@@ -168,9 +154,6 @@ def convert_to_zcl_values(
|
168 | 154 |
|
169 | 155 | def async_is_bindable_target(source_zha_device: Device, target_zha_device: Device):
|
170 | 156 | """Determine if target is bindable to source."""
|
171 |
| - from zha.zigbee.cluster_handlers.registries import ( # pylint: disable=import-outside-toplevel |
172 |
| - BINDABLE_CLUSTERS, |
173 |
| - ) |
174 | 157 |
|
175 | 158 | if target_zha_device.nwk == 0x0000:
|
176 | 159 | return True
|
@@ -264,113 +247,6 @@ def qr_to_install_code(qr_code: str) -> tuple[zigpy.types.EUI64, zigpy.types.Key
|
264 | 247 | raise vol.Invalid(f"couldn't convert qr code: {qr_code}")
|
265 | 248 |
|
266 | 249 |
|
267 |
| -class LightOptions(BaseModel): |
268 |
| - """ZHA light options.""" |
269 |
| - |
270 |
| - default_light_transition: float = Field(default=0) |
271 |
| - enable_enhanced_light_transition: bool = Field(default=False) |
272 |
| - enable_light_transitioning_flag: bool = Field(default=True) |
273 |
| - always_prefer_xy_color_mode: bool = Field(default=True) |
274 |
| - group_members_assume_state: bool = Field(default=True) |
275 |
| - |
276 |
| - |
277 |
| -class DeviceOptions(BaseModel): |
278 |
| - """ZHA device options.""" |
279 |
| - |
280 |
| - enable_identify_on_join: bool = Field(default=True) |
281 |
| - consider_unavailable_mains: int = Field( |
282 |
| - default=CONF_DEFAULT_CONSIDER_UNAVAILABLE_MAINS |
283 |
| - ) |
284 |
| - consider_unavailable_battery: int = Field( |
285 |
| - default=CONF_DEFAULT_CONSIDER_UNAVAILABLE_BATTERY |
286 |
| - ) |
287 |
| - enable_mains_startup_polling: bool = Field(default=True) |
288 |
| - |
289 |
| - |
290 |
| -class AlarmControlPanelOptions(BaseModel): |
291 |
| - """ZHA alarm control panel options.""" |
292 |
| - |
293 |
| - master_code: str = Field(default="1234") |
294 |
| - failed_tries: int = Field(default=3) |
295 |
| - arm_requires_code: bool = Field(default=False) |
296 |
| - |
297 |
| - |
298 |
| -class CoordinatorConfiguration(BaseModel): |
299 |
| - """ZHA coordinator configuration.""" |
300 |
| - |
301 |
| - path: str |
302 |
| - baudrate: int = Field(default=115200) |
303 |
| - flow_control: str = Field(default="hardware") |
304 |
| - radio_type: str = Field(default="ezsp") |
305 |
| - |
306 |
| - |
307 |
| -class QuirksConfiguration(BaseModel): |
308 |
| - """ZHA quirks configuration.""" |
309 |
| - |
310 |
| - enabled: bool = Field(default=True) |
311 |
| - custom_quirks_path: str | None = Field(default=None) |
312 |
| - |
313 |
| - |
314 |
| -class DeviceOverridesConfiguration(BaseModel): |
315 |
| - """ZHA device overrides configuration.""" |
316 |
| - |
317 |
| - type: Platform |
318 |
| - |
319 |
| - |
320 |
| -class WebsocketServerConfiguration(BaseModel): |
321 |
| - """Websocket Server configuration for zha.""" |
322 |
| - |
323 |
| - host: str = "0.0.0.0" |
324 |
| - port: int = 8001 |
325 |
| - network_auto_start: bool = False |
326 |
| - |
327 |
| - |
328 |
| -class WebsocketClientConfiguration(BaseModel): |
329 |
| - """Websocket client configuration for zha.""" |
330 |
| - |
331 |
| - host: str = "0.0.0.0" |
332 |
| - port: int = 8001 |
333 |
| - aiohttp_session: ClientSession | None = None |
334 |
| - |
335 |
| - |
336 |
| -class ZHAConfiguration(BaseModel): |
337 |
| - """ZHA configuration.""" |
338 |
| - |
339 |
| - coordinator_configuration: CoordinatorConfiguration = Field( |
340 |
| - default_factory=CoordinatorConfiguration |
341 |
| - ) |
342 |
| - quirks_configuration: QuirksConfiguration = Field( |
343 |
| - default_factory=QuirksConfiguration |
344 |
| - ) |
345 |
| - device_overrides: dict[str, DeviceOverridesConfiguration] = Field( |
346 |
| - default_factory=dict |
347 |
| - ) |
348 |
| - light_options: LightOptions = Field(default_factory=LightOptions) |
349 |
| - device_options: DeviceOptions = Field(default_factory=DeviceOptions) |
350 |
| - alarm_control_panel_options: AlarmControlPanelOptions = Field( |
351 |
| - default_factory=AlarmControlPanelOptions |
352 |
| - ) |
353 |
| - |
354 |
| - |
355 |
| -@dataclasses.dataclass(kw_only=True, slots=True) |
356 |
| -class ZHAData: |
357 |
| - """ZHA data stored in `gateway.data`.""" |
358 |
| - |
359 |
| - config: ZHAConfiguration |
360 |
| - ws_server_config: WebsocketServerConfiguration | None = None |
361 |
| - ws_client_config: WebsocketClientConfiguration | None = None |
362 |
| - zigpy_config: dict[str, Any] = dataclasses.field(default_factory=dict) |
363 |
| - platforms: collections.defaultdict[Platform, list] = dataclasses.field( |
364 |
| - default_factory=lambda: collections.defaultdict(list) |
365 |
| - ) |
366 |
| - gateway: Gateway | None = dataclasses.field(default=None) |
367 |
| - device_trigger_cache: dict[str, tuple[str, dict]] = dataclasses.field( |
368 |
| - default_factory=dict |
369 |
| - ) |
370 |
| - allow_polling: bool = dataclasses.field(default=False) |
371 |
| - local_timezone: datetime.tzinfo = dataclasses.field(default=datetime.UTC) |
372 |
| - |
373 |
| - |
374 | 250 | class GlobalUpdater:
|
375 | 251 | """Global updater for ZHA.
|
376 | 252 |
|
|
0 commit comments