Skip to content

Commit

Permalink
Use battery enum in ikea/xiaomi quirks
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4nt0r committed Jan 23, 2025
1 parent 3acf637 commit 6405d78
Show file tree
Hide file tree
Showing 23 changed files with 51 additions and 36 deletions.
4 changes: 2 additions & 2 deletions zhaquirks/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ class BatterySize(t.enum8):
CR2 = 0x07
CR123A = 0x08
CR2450 = 0x09
CR2032 = 0x10
CR1632 = 0x11
CR2032 = 0x0A
CR1632 = 0x0B
Unknown = 0xFF
11 changes: 6 additions & 5 deletions zhaquirks/ikea/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from zigpy.zcl.clusters.general import Basic, PowerConfiguration, Scenes

from zhaquirks import EventableCluster
from zhaquirks.const import BatterySize

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -148,7 +149,7 @@ class PowerConfig1AAACluster(CustomCluster, PowerConfiguration):
"""Updating power attributes: 2 AAA."""

_CONSTANT_ATTRIBUTES = {
BATTERY_SIZE: 4,
BATTERY_SIZE: BatterySize.AAA,
BATTERY_QUANTITY: 1,
BATTERY_RATED_VOLTAGE: 15,
}
Expand All @@ -158,7 +159,7 @@ class PowerConfig2AAACluster(CustomCluster, PowerConfiguration):
"""Updating power attributes: 2 AAA."""

_CONSTANT_ATTRIBUTES = {
BATTERY_SIZE: 4,
BATTERY_SIZE: BatterySize.AAA,
BATTERY_QUANTITY: 2,
BATTERY_RATED_VOLTAGE: 15,
}
Expand All @@ -168,7 +169,7 @@ class PowerConfig2CRCluster(CustomCluster, PowerConfiguration):
"""Updating power attributes: 2 CR2032."""

_CONSTANT_ATTRIBUTES = {
BATTERY_SIZE: 10,
BATTERY_SIZE: BatterySize.CR2032,
BATTERY_QUANTITY: 2,
BATTERY_RATED_VOLTAGE: 30,
}
Expand All @@ -178,7 +179,7 @@ class PowerConfig1CRCluster(CustomCluster, PowerConfiguration):
"""Updating power attributes: 1 CR2032."""

_CONSTANT_ATTRIBUTES = {
BATTERY_SIZE: 10,
BATTERY_SIZE: BatterySize.CR2032,
BATTERY_QUANTITY: 1,
BATTERY_RATED_VOLTAGE: 30,
}
Expand All @@ -189,7 +190,7 @@ class PowerConfig1CRXCluster(CustomCluster, PowerConfiguration):

_CONSTANT_ATTRIBUTES = {
BATTERY_VOLTAGE: 0,
BATTERY_SIZE: 10,
BATTERY_SIZE: BatterySize.CR2032,
BATTERY_QUANTITY: 1,
BATTERY_RATED_VOLTAGE: 30,
}
Expand Down
9 changes: 2 additions & 7 deletions zhaquirks/tuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
import zigpy.types as t
from zigpy.zcl import BaseAttributeDefs, foundation
from zigpy.zcl.clusters.closures import WindowCovering
from zigpy.zcl.clusters.general import (
Basic,
BatterySize,
LevelControl,
OnOff,
PowerConfiguration,
)
from zigpy.zcl.clusters.general import Basic, LevelControl, OnOff, PowerConfiguration
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
from zigpy.zcl.clusters.hvac import Thermostat, UserInterface
from zigpy.zcl.clusters.smartenergy import Metering
Expand All @@ -30,6 +24,7 @@
RIGHT,
SHORT_PRESS,
ZHA_SEND_EVENT,
BatterySize,
)

# ---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion zhaquirks/tuya/tuya_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from zigpy.quirks.v2.homeassistant import CONCENTRATION_PARTS_PER_MILLION, UnitOfTime
from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
import zigpy.types as t
from zigpy.zcl.clusters.general import BatterySize
from zigpy.zcl.clusters.security import IasZone

from zhaquirks.const import BatterySize
from zhaquirks.tuya import TuyaLocalCluster
from zhaquirks.tuya.builder import TuyaQuirkBuilder

Expand Down
2 changes: 1 addition & 1 deletion zhaquirks/tuya/tuya_siren.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from zigpy.quirks.v2.homeassistant import PERCENTAGE, UnitOfTemperature, UnitOfTime
from zigpy.quirks.v2.homeassistant.binary_sensor import BinarySensorDeviceClass
import zigpy.types as t
from zigpy.zcl.clusters.general import BatterySize

from zhaquirks.const import BatterySize
from zhaquirks.tuya.builder import TuyaQuirkBuilder


Expand Down
2 changes: 1 addition & 1 deletion zhaquirks/tuya/tuya_valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from zigpy.quirks.v2.homeassistant import UnitOfTime, UnitOfVolume
from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
import zigpy.types as t
from zigpy.zcl.clusters.general import BatterySize
from zigpy.zcl.clusters.smartenergy import Metering

from zhaquirks.const import BatterySize
from zhaquirks.tuya import TUYA_CLUSTER_ID
from zhaquirks.tuya.builder import TuyaQuirkBuilder, TuyaValveWaterConsumed
from zhaquirks.tuya.mcu import TuyaMCUCluster
Expand Down
7 changes: 5 additions & 2 deletions zhaquirks/xiaomi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
UNKNOWN,
VALUE,
ZHA_SEND_EVENT,
BatterySize,
)

BATTERY_LEVEL = "battery_level"
Expand Down Expand Up @@ -116,7 +117,7 @@ class XiaomiCustomDevice(CustomDevice):
def __init__(self, *args, **kwargs):
"""Init."""
if not hasattr(self, BATTERY_SIZE):
self.battery_size = 10
self.battery_size = BatterySize.CR2032
super().__init__(*args, **kwargs)


Expand Down Expand Up @@ -507,7 +508,9 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._CONSTANT_ATTRIBUTES = {
BATTERY_QUANTITY_ATTR: 1,
BATTERY_SIZE_ATTR: getattr(self.endpoint.device, BATTERY_SIZE, 0xFF),
BATTERY_SIZE_ATTR: getattr(
self.endpoint.device, BATTERY_SIZE, BatterySize.Unknown
),
}
self._slope = 200 / (self.MAX_VOLTS_MV - self.MIN_VOLTS_MV)

Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
TURN_ON,
VALUE,
ZHA_SEND_EVENT,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand Down Expand Up @@ -161,7 +162,7 @@ class Cube(XiaomiQuickInitDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 9
self.battery_size = BatterySize.CR2450

Check warning on line 165 in zhaquirks/xiaomi/aqara/cube.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/aqara/cube.py#L165

Added line #L165 was not covered by tests
super().__init__(*args, **kwargs)

class MultistateInputCluster(CustomCluster, MultistateInput):
Expand Down
5 changes: 3 additions & 2 deletions zhaquirks/xiaomi/aqara/cube_aqgl01.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
TURN_ON,
VALUE,
ZHA_SEND_EVENT,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand Down Expand Up @@ -214,7 +215,7 @@ class CubeAQGL01(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 9
self.battery_size = BatterySize.CR2450

Check warning on line 218 in zhaquirks/xiaomi/aqara/cube_aqgl01.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/aqara/cube_aqgl01.py#L218

Added line #L218 was not covered by tests
super().__init__(*args, **kwargs)

signature = {
Expand Down Expand Up @@ -353,7 +354,7 @@ class CubeCAGL02(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 9
self.battery_size = BatterySize.CR2450

Check warning on line 357 in zhaquirks/xiaomi/aqara/cube_aqgl01.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/aqara/cube_aqgl01.py#L357

Added line #L357 was not covered by tests
super().__init__(*args, **kwargs)

signature = {
Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/magnet_ac01.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand Down Expand Up @@ -42,7 +43,7 @@ class LumiMagnetAC01(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 8
self.battery_size = BatterySize.CR123A

Check warning on line 46 in zhaquirks/xiaomi/aqara/magnet_ac01.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/aqara/magnet_ac01.py#L46

Added line #L46 was not covered by tests
super().__init__(*args, **kwargs)

signature = {
Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/magnet_acn001.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand All @@ -28,7 +29,7 @@ class MagnetE1(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 11
self.battery_size = BatterySize.CR1632

Check warning on line 32 in zhaquirks/xiaomi/aqara/magnet_acn001.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/aqara/magnet_acn001.py#L32

Added line #L32 was not covered by tests
super().__init__(*args, **kwargs)

signature = {
Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/magnet_agl02.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
BatterySize,
)
from zhaquirks.xiaomi import (
BasicCluster,
Expand All @@ -25,7 +26,7 @@ class MagnetT1(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 11
self.battery_size = BatterySize.CR1632
super().__init__(*args, **kwargs)

signature = {
Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/magnet_aq2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
OUTPUT_CLUSTERS,
PROFILE_ID,
SKIP_CONFIGURATION,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand All @@ -31,7 +32,7 @@ class MagnetAQ2(XiaomiQuickInitDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 11
self.battery_size = BatterySize.CR1632

Check warning on line 35 in zhaquirks/xiaomi/aqara/magnet_aq2.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/aqara/magnet_aq2.py#L35

Added line #L35 was not covered by tests
super().__init__(*args, **kwargs)

signature = {
Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/motion_ac02.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
BatterySize,
)
from zhaquirks.xiaomi import (
LocalIlluminanceMeasurementCluster,
Expand Down Expand Up @@ -91,7 +92,7 @@ class LumiMotionAC02(CustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 11
self.battery_size = BatterySize.CR1632
self.battery_quantity = 2
self.motion_bus = Bus()
super().__init__(*args, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/motion_acn001.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand All @@ -30,7 +31,7 @@ class MotionE1(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 11
self.battery_size = BatterySize.CR1632
self.motion_bus = Bus()
super().__init__(*args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/motion_agl02.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand All @@ -32,7 +33,7 @@ class MotionT1(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 11
self.battery_size = BatterySize.CR1632
self.motion_bus = Bus()
super().__init__(*args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/motion_agl04.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
BatterySize,
)
from zhaquirks.xiaomi import (
DeviceTemperatureCluster,
Expand Down Expand Up @@ -64,7 +65,7 @@ class LumiLumiMotionAgl04(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 11
self.battery_size = BatterySize.CR1632

Check warning on line 68 in zhaquirks/xiaomi/aqara/motion_agl04.py

View check run for this annotation

Codecov / codecov/patch

zhaquirks/xiaomi/aqara/motion_agl04.py#L68

Added line #L68 was not covered by tests
self.battery_quantity = 2
self.motion_bus = Bus()
super().__init__(*args, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/motion_aq2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
OUTPUT_CLUSTERS,
PROFILE_ID,
SKIP_CONFIGURATION,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand All @@ -36,7 +37,7 @@ class MotionAQ2(XiaomiQuickInitDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 9
self.battery_size = BatterySize.CR2450
self.motion_bus = Bus()
super().__init__(*args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/aqara/motion_aq2b.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
OUTPUT_CLUSTERS,
PROFILE_ID,
SKIP_CONFIGURATION,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand All @@ -32,7 +33,7 @@ class MotionAQ2(XiaomiCustomDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 9
self.battery_size = BatterySize.CR2450
self.motion_bus = Bus()
super().__init__(*args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/mija/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
OUTPUT_CLUSTERS,
PROFILE_ID,
SKIP_CONFIGURATION,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand All @@ -40,7 +41,7 @@ class Motion(XiaomiQuickInitDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 9
self.battery_size = BatterySize.CR2450
self.motion_bus = Bus()
super().__init__(*args, **kwargs)

Expand Down
3 changes: 2 additions & 1 deletion zhaquirks/xiaomi/mija/sensor_magnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
OUTPUT_CLUSTERS,
PROFILE_ID,
SKIP_CONFIGURATION,
BatterySize,
)
from zhaquirks.xiaomi import (
LUMI,
Expand All @@ -38,7 +39,7 @@ class Magnet(XiaomiQuickInitDevice):

def __init__(self, *args, **kwargs):
"""Init."""
self.battery_size = 11
self.battery_size = BatterySize.CR1632
super().__init__(*args, **kwargs)

signature = {
Expand Down
Loading

0 comments on commit 6405d78

Please sign in to comment.