Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Xiaomi LYWSD03MMC temp sensor with custom Zigbee firmware #3329

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/test_xiaomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,3 +1757,32 @@ def test_aqara_acn014_signature_match(assert_signature_matches_quirk):
assert_signature_matches_quirk(
zhaquirks.xiaomi.aqara.light_acn.LumiLightAcn014, signature
)


def test_custom_z03mmc_signature_match(assert_signature_matches_quirk):
"""Test signature."""
signature = {
"node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=56085, maximum_buffer_size=74, maximum_incoming_transfer_size=404, server_mask=10752, maximum_outgoing_transfer_size=404, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
"endpoints": {
"1": {
"profile_id": 0x0104,
"device_type": "0x0302",
"in_clusters": [
"0x0000",
"0x0001",
"0x0003",
"0x0204",
"0x0402",
"0x0405",
],
"out_clusters": ["0x0019"],
}
},
"manufacturer": "Xiaomi",
"model": "LYWSD03MMC",
"class": "zigpy.device.Device",
}

assert_signature_matches_quirk(
zhaquirks.xiaomi.custom.z03mmc.LYWSD03MMC_devbis, signature
)
1 change: 1 addition & 0 deletions zhaquirks/xiaomi/custom/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module for Xiaomi custom firmware quirks implementations."""
153 changes: 153 additions & 0 deletions zhaquirks/xiaomi/custom/z03mmc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
"""Xiaomi LYWSD03MMC Bluetooth temperature and humidity sensor."""

from zigpy.profiles import zha
from zigpy.types import Bool, int16s, uint16_t
from zigpy.zcl.clusters.general import Basic, Identify, Ota, PowerConfiguration
from zigpy.zcl.clusters.hvac import UserInterface
from zigpy.zcl.clusters.measurement import RelativeHumidity, TemperatureMeasurement
from zigpy.zcl.foundation import ZCLAttributeDef

from zhaquirks import CustomCluster
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.xiaomi import XiaomiCustomDevice


class TemperatureMeasurementCustom(CustomCluster, TemperatureMeasurement):
"""Temperature Measurement Cluster with calibration attribute."""

class AttributeDefs(TemperatureMeasurement.AttributeDefs):
"""Attribute Definitions."""

# A value in 0.01ºC offset to fix up incorrect values from sensor
temperature_calibration = ZCLAttributeDef(
id=0x0010,
type=int16s,
access="rw",
is_manufacturer_specific=True,
)


class RelativeHumidityCustom(CustomCluster, RelativeHumidity):
"""Relative Humidity Cluster with calibration attribute."""

class AttributeDefs(RelativeHumidity.AttributeDefs):
"""Attribute Definitions."""

# A value in 0.01%RH offset to fix up incorrect values from sensor
humidity_calibration = ZCLAttributeDef(
id=0x0010,
type=int16s,
access="rw",
is_manufacturer_specific=True,
)


class UserInterfaceCustom(CustomCluster, UserInterface):
"""Custom User Interface Cluster with smiley control."""

class AttributeDefs(UserInterface.AttributeDefs):
"""Attribute Definitions."""

# of the 3 ZCL Thermostat User Interface spec attributes,
# only the first one (TemperatureDisplayMode) is implemented fully.
# KeypadLockout is implemented but completely unused in the device firmware
# and ScheduleProgrammingVisibility is not implemented at all
# https://github.com/devbis/z03mmc/blob/1.1.0/src/sensorEpCfg.c#L256

# 0 - smiley is off, 1 - smiley is on (according to comfort values)
smiley = ZCLAttributeDef(
id=0x0010,
type=Bool,
access="rw",
is_manufacturer_specific=True,
)

# display. 0 - display is off, 1 - display is on
display = ZCLAttributeDef(
id=0x0011,
type=Bool,
access="rw",
is_manufacturer_specific=True,
)

# comfort temperature min: A value in 0.01ºC to set minimum comfort temperature for happy face
comfort_temperature_min = ZCLAttributeDef(
id=0x0102,
type=int16s,
access="rw",
is_manufacturer_specific=True,
)

# comfort temperature max: A value in 0.01ºC to set maximum comfort temperature for happy face
comfort_temperature_max = ZCLAttributeDef(
id=0x0103,
type=int16s,
access="rw",
is_manufacturer_specific=True,
)

# comfort humidity min: A value in 0.01%RH to set minimum comfort humidity for happy face
comfort_humidity_min = ZCLAttributeDef(
id=0x0104,
type=uint16_t,
access="rw",
is_manufacturer_specific=True,
)

# comfort humidity max: A value in 0.01%RH to set maximum comfort humidity for happy face
comfort_humidity_max = ZCLAttributeDef(
id=0x0105,
type=uint16_t,
access="rw",
is_manufacturer_specific=True,
)


# https://github.com/devbis/z03mmc
# defined by 1.1.0 firmware (0x11003001)
# see README.md in the repo for more info
class LYWSD03MMC_devbis(XiaomiCustomDevice):
"""LYWSD03MMC sensor with devbis custom firmware."""

signature = {
MODELS_INFO: [("Xiaomi", "LYWSD03MMC")],
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
PowerConfiguration.cluster_id,
RelativeHumidity.cluster_id,
TemperatureMeasurement.cluster_id,
UserInterface.cluster_id,
],
OUTPUT_CLUSTERS: [Ota.cluster_id],
},
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
PowerConfiguration.cluster_id,
RelativeHumidityCustom,
TemperatureMeasurementCustom,
UserInterfaceCustom,
],
OUTPUT_CLUSTERS: [Ota.cluster_id],
},
},
}
Loading