6
6
import math
7
7
import pathlib
8
8
from types import FrameType
9
- from typing import Any
9
+ from typing import Any , Self
10
10
11
11
from zigpy .quirks import _DEVICE_REGISTRY
12
12
from zigpy .quirks .registry import DeviceRegistry
@@ -217,7 +217,7 @@ def _tuya_battery(
217
217
dp_id : int ,
218
218
power_cfg : PowerConfiguration ,
219
219
scale : float ,
220
- ) -> QuirkBuilder :
220
+ ) -> Self :
221
221
"""Add a Tuya Battery Power Configuration."""
222
222
self .tuya_dp (
223
223
dp_id ,
@@ -236,7 +236,7 @@ def tuya_battery(
236
236
battery_qty : int | None = 2 ,
237
237
battery_voltage : int | None = None ,
238
238
scale : float = 2 ,
239
- ) -> QuirkBuilder :
239
+ ) -> Self :
240
240
"""Add a Tuya Battery Power Configuration."""
241
241
242
242
if power_cfg :
@@ -265,7 +265,7 @@ def tuya_illuminance(
265
265
converter : Callable [[Any ], Any ] | None = (
266
266
lambda x : 10000 * math .log10 (x ) + 1 if x != 0 else 0
267
267
),
268
- ) -> QuirkBuilder :
268
+ ) -> Self :
269
269
"""Add a Tuya Illuminance Configuration."""
270
270
self .tuya_dp (
271
271
dp_id ,
@@ -276,7 +276,7 @@ def tuya_illuminance(
276
276
self .adds (illuminance_cfg )
277
277
return self
278
278
279
- def tuya_contact (self , dp_id : int ):
279
+ def tuya_contact (self , dp_id : int ) -> Self :
280
280
"""Add a Tuya IAS contact sensor."""
281
281
self .tuya_ias (
282
282
dp_id = dp_id ,
@@ -290,7 +290,7 @@ def tuya_co2(
290
290
dp_id : int ,
291
291
co2_cfg : TuyaLocalCluster = TuyaCO2Concentration ,
292
292
scale : float = 1e-6 ,
293
- ) -> QuirkBuilder :
293
+ ) -> Self :
294
294
"""Add a Tuya CO2 Configuration."""
295
295
self .tuya_dp (
296
296
dp_id ,
@@ -306,7 +306,7 @@ def tuya_electrical_conductivity(
306
306
dp_id : int ,
307
307
ec_cfg : TuyaLocalCluster = TuyaElectricalConductivity ,
308
308
scale : float = 1 ,
309
- ) -> QuirkBuilder :
309
+ ) -> Self :
310
310
"""Add a Tuya Electrical Conductivity Configuration."""
311
311
self .tuya_dp (
312
312
dp_id ,
@@ -326,7 +326,7 @@ def tuya_formaldehyde(
326
326
((MOL_VOL_AIR_NTP * x ) / TuyaFormaldehydeConcentration .MOLECULAR_MASS ), 2
327
327
)
328
328
* 1e-6 ,
329
- ) -> QuirkBuilder :
329
+ ) -> Self :
330
330
"""Add a Tuya Formaldehyde Configuration."""
331
331
self .tuya_dp (
332
332
dp_id ,
@@ -342,7 +342,7 @@ def tuya_pm25(
342
342
dp_id : int ,
343
343
pm25_cfg : TuyaLocalCluster = TuyaPM25Concentration ,
344
344
scale : float = 1 ,
345
- ) -> QuirkBuilder :
345
+ ) -> Self :
346
346
"""Add a Tuya PM25 Configuration."""
347
347
self .tuya_dp (
348
348
dp_id ,
@@ -353,7 +353,7 @@ def tuya_pm25(
353
353
self .adds (pm25_cfg )
354
354
return self
355
355
356
- def tuya_gas (self , dp_id : int ):
356
+ def tuya_gas (self , dp_id : int ) -> Self :
357
357
"""Add a Tuya IAS gas sensor."""
358
358
self .tuya_ias (
359
359
dp_id = dp_id ,
@@ -362,7 +362,7 @@ def tuya_gas(self, dp_id: int):
362
362
)
363
363
return self
364
364
365
- def tuya_smoke (self , dp_id : int ):
365
+ def tuya_smoke (self , dp_id : int ) -> Self :
366
366
"""Add a Tuya IAS smoke/fire sensor."""
367
367
self .tuya_ias (
368
368
dp_id = dp_id ,
@@ -376,7 +376,7 @@ def tuya_ias(
376
376
dp_id : int ,
377
377
ias_cfg : TuyaLocalCluster ,
378
378
converter : Callable [[Any ], Any ] | None = None ,
379
- ) -> QuirkBuilder :
379
+ ) -> Self :
380
380
"""Add a Tuya IAS Configuration."""
381
381
self .tuya_dp (
382
382
dp_id ,
@@ -392,7 +392,7 @@ def tuya_metering(
392
392
dp_id : int ,
393
393
metering_cfg : TuyaLocalCluster = TuyaValveWaterConsumedNoInstDemand ,
394
394
scale : float = 1 ,
395
- ) -> QuirkBuilder :
395
+ ) -> Self :
396
396
"""Add a Tuya Metering Configuration."""
397
397
self .tuya_dp (
398
398
dp_id ,
@@ -407,7 +407,7 @@ def tuya_onoff(
407
407
self ,
408
408
dp_id : int ,
409
409
onoff_cfg : TuyaLocalCluster = TuyaOnOffNM ,
410
- ) -> QuirkBuilder :
410
+ ) -> Self :
411
411
"""Add a Tuya OnOff Configuration."""
412
412
self .tuya_dp (
413
413
dp_id ,
@@ -422,7 +422,7 @@ def tuya_humidity(
422
422
dp_id : int ,
423
423
rh_cfg : TuyaLocalCluster = TuyaRelativeHumidity ,
424
424
scale : float = 100 ,
425
- ) -> QuirkBuilder :
425
+ ) -> Self :
426
426
"""Add a Tuya Relative Humidity Configuration."""
427
427
self .tuya_dp (
428
428
dp_id ,
@@ -438,7 +438,7 @@ def tuya_soil_moisture(
438
438
dp_id : int ,
439
439
soil_cfg : TuyaLocalCluster = TuyaSoilMoisture ,
440
440
scale : float = 100 ,
441
- ) -> QuirkBuilder :
441
+ ) -> Self :
442
442
"""Add a Tuya Soil Moisture Configuration."""
443
443
self .tuya_dp (
444
444
dp_id ,
@@ -454,7 +454,7 @@ def tuya_temperature(
454
454
dp_id : int ,
455
455
temp_cfg : TuyaLocalCluster = TuyaTemperatureMeasurement ,
456
456
scale : float = 100 ,
457
- ) -> QuirkBuilder :
457
+ ) -> Self :
458
458
"""Add a Tuya Temperature Configuration."""
459
459
self .tuya_dp (
460
460
dp_id ,
@@ -465,7 +465,7 @@ def tuya_temperature(
465
465
self .adds (temp_cfg )
466
466
return self
467
467
468
- def tuya_vibration (self , dp_id : int ):
468
+ def tuya_vibration (self , dp_id : int ) -> Self :
469
469
"""Add a Tuya IAS vibration sensor."""
470
470
self .tuya_ias (
471
471
dp_id = dp_id ,
@@ -479,7 +479,7 @@ def tuya_voc(
479
479
dp_id : int ,
480
480
voc_cfg : TuyaLocalCluster = TuyaAirQualityVOC ,
481
481
scale : float = 1e-6 ,
482
- ) -> QuirkBuilder :
482
+ ) -> Self :
483
483
"""Add a Tuya VOC Configuration."""
484
484
self .tuya_dp (
485
485
dp_id ,
@@ -497,7 +497,7 @@ def tuya_attribute(
497
497
type : type = t .uint16_t ,
498
498
access : foundation .ZCLAttributeAccess = foundation .ZCLAttributeAccess .NONE ,
499
499
is_manufacturer_specific = True ,
500
- ) -> QuirkBuilder :
500
+ ) -> Self :
501
501
"""Add an attribute to AttributeDefs."""
502
502
attr_id : int = int .from_bytes ([0xEF , dp_id ])
503
503
@@ -522,7 +522,7 @@ def tuya_dp(
522
522
dp_converter : Callable [[Any ], Any ] | None = None ,
523
523
endpoint_id : int | None = None ,
524
524
dp_handler : str = "_dp_2_attr_update" ,
525
- ) -> QuirkBuilder :
525
+ ) -> Self :
526
526
"""Add Tuya DP Converter."""
527
527
528
528
self .tuya_dp_multi (
@@ -545,7 +545,7 @@ def tuya_dp_multi(
545
545
dp_id : int ,
546
546
attribute_mapping : list [DPToAttributeMapping ],
547
547
dp_handler : str = "_dp_2_attr_update" ,
548
- ) -> QuirkBuilder : # fmt: skip
548
+ ) -> Self : # fmt: skip
549
549
"""Add Tuya DP Converter that maps to multiple attributes."""
550
550
551
551
if dp_id in self .tuya_dp_to_attribute :
@@ -567,7 +567,7 @@ def tuya_dp_attribute(
567
567
type : type = t .uint16_t ,
568
568
access : foundation .ZCLAttributeAccess = foundation .ZCLAttributeAccess .NONE ,
569
569
is_manufacturer_specific = True ,
570
- ) -> QuirkBuilder :
570
+ ) -> Self :
571
571
"""Add an Tuya DataPoint and corresponding AttributeDef."""
572
572
self .tuya_attribute (
573
573
dp_id = dp_id ,
@@ -602,7 +602,7 @@ def tuya_switch(
602
602
attribute_initialized_from_cache : bool = True ,
603
603
translation_key : str | None = None ,
604
604
fallback_name : str | None = None ,
605
- ) -> QuirkBuilder :
605
+ ) -> Self :
606
606
"""Add an EntityMetadata containing SwitchMetadata and return self.
607
607
608
608
This method allows exposing a switch entity in Home Assistant.
@@ -645,7 +645,7 @@ def tuya_enum(
645
645
attribute_initialized_from_cache : bool = True ,
646
646
translation_key : str | None = None ,
647
647
fallback_name : str | None = None ,
648
- ) -> QuirkBuilder :
648
+ ) -> Self :
649
649
"""Add an EntityMetadata containing ZCLEnumMetadata and return self.
650
650
651
651
This method allows exposing an enum based entity in Home Assistant.
@@ -691,7 +691,7 @@ def tuya_number(
691
691
attribute_initialized_from_cache : bool = True ,
692
692
translation_key : str | None = None ,
693
693
fallback_name : str | None = None ,
694
- ) -> QuirkBuilder :
694
+ ) -> Self :
695
695
"""Add an EntityMetadata containing NumberMetadata and return self.
696
696
697
697
This method allows exposing a number entity in Home Assistant.
@@ -733,7 +733,7 @@ def tuya_binary_sensor(
733
733
attribute_initialized_from_cache : bool = True ,
734
734
translation_key : str | None = None ,
735
735
fallback_name : str | None = None ,
736
- ) -> QuirkBuilder :
736
+ ) -> Self :
737
737
"""Add an EntityMetadata containing BinarySensorMetadata and return self.
738
738
739
739
This method allows exposing a binary sensor entity in Home Assistant.
@@ -777,7 +777,7 @@ def tuya_sensor(
777
777
attribute_initialized_from_cache : bool = True ,
778
778
translation_key : str | None = None ,
779
779
fallback_name : str | None = None ,
780
- ) -> QuirkBuilder :
780
+ ) -> Self :
781
781
"""Add an EntityMetadata containing ZCLSensorMetadata and return self.
782
782
783
783
This method allows exposing a sensor entity in Home Assistant.
@@ -812,7 +812,7 @@ def tuya_sensor(
812
812
813
813
def tuya_enchantment (
814
814
self , read_attr_spell : bool = True , data_query_spell : bool = False
815
- ) -> QuirkBuilder :
815
+ ) -> Self :
816
816
"""Set the Tuya enchantment spells."""
817
817
818
818
class EnchantedDeviceV2 (CustomDeviceV2 , BaseEnchantedDevice ):
0 commit comments