Expose entity device temperature from cluster in ZHA (#64189)

* expose device temperature sensor in frontend

* fixes after runnig test

* specified device temp channel

* add dev temp int test device aqara water

* black fix
This commit is contained in:
rforro 2022-01-23 15:37:01 +01:00 committed by GitHub
parent b3a8ac8932
commit 4e376181f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 1 deletions

View File

@ -18,6 +18,8 @@ from ..const import (
REPORT_CONFIG_BATTERY_SAVE,
REPORT_CONFIG_DEFAULT,
REPORT_CONFIG_IMMEDIATE,
REPORT_CONFIG_MAX_INT,
REPORT_CONFIG_MIN_INT,
SIGNAL_ATTR_UPDATED,
SIGNAL_MOVE_LEVEL,
SIGNAL_SET_LEVEL,
@ -170,6 +172,13 @@ class Commissioning(ZigbeeChannel):
class DeviceTemperature(ZigbeeChannel):
"""Device Temperature channel."""
REPORT_CONFIG = [
{
"attr": "current_temperature",
"config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50),
}
]
@registries.ZIGBEE_CHANNEL_REGISTRY.register(general.GreenPowerProxy.cluster_id)
class GreenPowerProxy(ZigbeeChannel):

View File

@ -70,6 +70,7 @@ CHANNEL_ATTRIBUTE = "attribute"
CHANNEL_BASIC = "basic"
CHANNEL_COLOR = "light_color"
CHANNEL_COVER = "window_covering"
CHANNEL_DEVICE_TEMPERATURE = "device_temperature"
CHANNEL_DOORLOCK = "door_lock"
CHANNEL_ELECTRICAL_MEASUREMENT = "electrical_measurement"
CHANNEL_EVENT_RELAY = "event_relay"

View File

@ -52,6 +52,7 @@ from .core import discovery
from .core.const import (
CHANNEL_ANALOG_INPUT,
CHANNEL_BASIC,
CHANNEL_DEVICE_TEMPERATURE,
CHANNEL_ELECTRICAL_MEASUREMENT,
CHANNEL_HUMIDITY,
CHANNEL_ILLUMINANCE,
@ -496,6 +497,18 @@ class Temperature(Sensor):
_unit = TEMP_CELSIUS
@MULTI_MATCH(channel_names=CHANNEL_DEVICE_TEMPERATURE)
class DeviceTemperature(Sensor):
"""Device Temperature Sensor."""
SENSOR_ATTR = "current_temperature"
_attr_device_class: SensorDeviceClass = SensorDeviceClass.TEMPERATURE
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
_divisor = 100
_unit = TEMP_CELSIUS
_attr_entity_category = EntityCategory.DIAGNOSTIC
@MULTI_MATCH(channel_names="carbon_dioxide_concentration")
class CarbonDioxideConcentration(Sensor):
"""Carbon Dioxide Concentration sensor."""

View File

@ -101,6 +101,7 @@ async def poll_control_device(zha_device_restored, zigpy_device_mock):
[
(0x0000, 0, {}),
(0x0001, 1, {"battery_voltage", "battery_percentage_remaining"}),
(0x0002, 1, {"current_temperature"}),
(0x0003, 0, {}),
(0x0004, 0, {}),
(0x0005, 1, {}),
@ -203,6 +204,7 @@ async def test_in_channel_config(
[
(0x0000, 0),
(0x0001, 1),
(0x0002, 1),
(0x0003, 0),
(0x0004, 0),
(0x0005, 1),

View File

@ -241,6 +241,12 @@ async def async_test_powerconfiguration(hass, cluster, entity_id):
assert hass.states.get(entity_id).attributes["battery_voltage"] == 2.0
async def async_test_device_temperature(hass, cluster, entity_id):
"""Test temperature sensor."""
await send_attributes_report(hass, cluster, {0: 2900})
assert_state(hass, entity_id, "29.0", TEMP_CELSIUS)
@pytest.mark.parametrize(
"cluster_id, entity_suffix, test_func, report_count, read_plug, unsupported_attrs",
(
@ -350,6 +356,14 @@ async def async_test_powerconfiguration(hass, cluster, entity_id):
},
None,
),
(
general.DeviceTemperature.cluster_id,
"device_temperature",
async_test_device_temperature,
1,
None,
None,
),
),
)
async def test_sensor(

View File

@ -2237,6 +2237,7 @@ DEVICES = [
"switch.lumi_lumi_plug_maus01_77665544_on_off",
"sensor.lumi_lumi_plug_maus01_77665544_basic_rssi",
"sensor.lumi_lumi_plug_maus01_77665544_basic_lqi",
"sensor.lumi_lumi_plug_maus01_77665544_device_temperature",
],
DEV_SIG_ENT_MAP: {
("switch", "00:11:22:33:44:55:66:77-1"): {
@ -2244,6 +2245,11 @@ DEVICES = [
DEV_SIG_ENT_MAP_CLASS: "Switch",
DEV_SIG_ENT_MAP_ID: "switch.lumi_lumi_plug_maus01_77665544_on_off",
},
("sensor", "00:11:22:33:44:55:66:77-1-2"): {
DEV_SIG_CHANNELS: ["device_temperature"],
DEV_SIG_ENT_MAP_CLASS: "DeviceTemperature",
DEV_SIG_ENT_MAP_ID: "sensor.lumi_lumi_plug_maus01_77665544_device_temperature",
},
("button", "00:11:22:33:44:55:66:77-1-3"): {
DEV_SIG_CHANNELS: ["identify"],
DEV_SIG_ENT_MAP_CLASS: "ZHAIdentifyButton",
@ -2328,6 +2334,7 @@ DEVICES = [
"sensor.lumi_lumi_relay_c2acn01_77665544_electrical_measurement_rms_voltage",
"sensor.lumi_lumi_relay_c2acn01_77665544_basic_rssi",
"sensor.lumi_lumi_relay_c2acn01_77665544_basic_lqi",
"sensor.lumi_lumi_relay_c2acn01_77665544_device_temperature",
],
DEV_SIG_ENT_MAP: {
("light", "00:11:22:33:44:55:66:77-1"): {
@ -2335,6 +2342,11 @@ DEVICES = [
DEV_SIG_ENT_MAP_CLASS: "Light",
DEV_SIG_ENT_MAP_ID: "light.lumi_lumi_relay_c2acn01_77665544_on_off",
},
("sensor", "00:11:22:33:44:55:66:77-1-2"): {
DEV_SIG_CHANNELS: ["device_temperature"],
DEV_SIG_ENT_MAP_CLASS: "DeviceTemperature",
DEV_SIG_ENT_MAP_ID: "sensor.lumi_lumi_relay_c2acn01_77665544_device_temperature",
},
("button", "00:11:22:33:44:55:66:77-1-3"): {
DEV_SIG_CHANNELS: ["identify"],
DEV_SIG_ENT_MAP_CLASS: "ZHAIdentifyButton",
@ -3453,7 +3465,7 @@ DEVICES = [
1: {
SIG_EP_TYPE: 1026,
DEV_SIG_EP_ID: 1,
SIG_EP_INPUT: [0, 1, 3, 1280],
SIG_EP_INPUT: [0, 1, 2, 3, 1280],
SIG_EP_OUTPUT: [25],
SIG_EP_PROFILE: 260,
},
@ -3465,6 +3477,7 @@ DEVICES = [
"binary_sensor.lumi_lumi_sensor_wleak_aq1_77665544_ias_zone",
"sensor.lumi_lumi_sensor_wleak_aq1_77665544_basic_rssi",
"sensor.lumi_lumi_sensor_wleak_aq1_77665544_basic_lqi",
"sensor.lumi_lumi_sensor_wleak_aq1_77665544_device_temperature",
],
DEV_SIG_ENT_MAP: {
("binary_sensor", "00:11:22:33:44:55:66:77-1-1280"): {
@ -3472,6 +3485,11 @@ DEVICES = [
DEV_SIG_ENT_MAP_CLASS: "IASZone",
DEV_SIG_ENT_MAP_ID: "binary_sensor.lumi_lumi_sensor_wleak_aq1_77665544_ias_zone",
},
("sensor", "00:11:22:33:44:55:66:77-1-2"): {
DEV_SIG_CHANNELS: ["device_temperature"],
DEV_SIG_ENT_MAP_CLASS: "DeviceTemperature",
DEV_SIG_ENT_MAP_ID: "sensor.lumi_lumi_sensor_wleak_aq1_77665544_device_temperature",
},
("button", "00:11:22:33:44:55:66:77-1-3"): {
DEV_SIG_CHANNELS: ["identify"],
DEV_SIG_ENT_MAP_CLASS: "ZHAIdentifyButton",