Skip to content

Commit

Permalink
Fix Develco SPLZB-131 plug device temperature divisor (#2132)
Browse files Browse the repository at this point in the history
Adds quirk for SPLZB-131!

---------

Co-authored-by: TheJulianJES <[email protected]>
  • Loading branch information
eriknn and TheJulianJES authored May 20, 2023
1 parent a601847 commit ffdf2fb
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_develco.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
"""Tests for Develco/Frient A/S quirks."""
import pytest
from zigpy.zcl.clusters.general import DeviceTemperature

import zhaquirks.develco.motion
import zhaquirks.develco.power_plug

from tests.common import ClusterListener

zhaquirks.setup()


@pytest.mark.parametrize("quirk", (zhaquirks.develco.power_plug.SPLZB131,))
async def test_develco_plug_device_temp_multiplier(zigpy_device_from_quirk, quirk):
"""Test device temperature multiplication."""

device = zigpy_device_from_quirk(quirk)

dev_temp_cluster = device.endpoints[2].device_temperature
dev_temp_listener = ClusterListener(dev_temp_cluster)

dev_temp_attr_id = DeviceTemperature.attributes_by_name["current_temperature"].id

# turn off heating
dev_temp_cluster._update_attribute(dev_temp_attr_id, 25)
assert len(dev_temp_listener.attribute_updates) == 1
assert dev_temp_listener.attribute_updates[0][0] == dev_temp_attr_id
assert dev_temp_listener.attribute_updates[0][1] == 2500 # multiplied by 100


def test_motion_signature(assert_signature_matches_quirk):
Expand Down
106 changes: 106 additions & 0 deletions zhaquirks/develco/power_plug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""Develco smart plugs."""
from zigpy.profiles import zha
from zigpy.quirks import CustomCluster, CustomDevice
from zigpy.zcl.clusters.general import (
Alarms,
Basic,
DeviceTemperature,
Groups,
Identify,
OnOff,
Ota,
Scenes,
Time,
)
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
from zigpy.zcl.clusters.measurement import OccupancySensing
from zigpy.zcl.clusters.smartenergy import Metering

from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.develco import DEVELCO

DEV_TEMP_ID = DeviceTemperature.attributes_by_name["current_temperature"].id


class DevelcoDeviceTemperature(CustomCluster, DeviceTemperature):
"""Custom device temperature cluster to multiply the temperature by 100."""

def _update_attribute(self, attrid, value):
if attrid == DEV_TEMP_ID:
value = value * 100
super()._update_attribute(attrid, value)


class SPLZB131(CustomDevice):
"""Custom device Develco smart plug device."""

signature = {
MODELS_INFO: [(DEVELCO, "SPLZB-131")],
ENDPOINTS: {
1: {
PROFILE_ID: 0xC0C9,
DEVICE_TYPE: 1,
INPUT_CLUSTERS: [
Scenes.cluster_id,
OnOff.cluster_id,
],
OUTPUT_CLUSTERS: [],
},
2: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
DeviceTemperature.cluster_id,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
Alarms.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
],
OUTPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
Time.cluster_id,
Ota.cluster_id,
OccupancySensing.cluster_id,
],
},
},
}

replacement = {
ENDPOINTS: {
2: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
DevelcoDeviceTemperature,
Identify.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
OnOff.cluster_id,
Alarms.cluster_id,
Metering.cluster_id,
ElectricalMeasurement.cluster_id,
],
OUTPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
Time.cluster_id,
Ota.cluster_id,
OccupancySensing.cluster_id,
],
},
}
}

0 comments on commit ffdf2fb

Please sign in to comment.