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

fix(ignore): Add linkquality sensor #25780

Merged
merged 2 commits into from
Jan 12, 2025
Merged
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
15 changes: 13 additions & 2 deletions lib/model/device.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import assert from 'node:assert';

import * as zhc from 'zigbee-herdsman-converters';
import {access, Numeric} from 'zigbee-herdsman-converters';
import {CustomClusters} from 'zigbee-herdsman/dist/zspec/zcl/definition/tstype';

import * as settings from '../util/settings';

const LINKQUALITY = new Numeric('linkquality', access.STATE)
.withUnit('lqi')
.withDescription('Link quality (signal strength)')
.withValueMin(0)
.withValueMax(255)
.withCategory('diagnostic');

export default class Device {
public zh: zh.Device;
public definition?: zhc.Definition;
Expand Down Expand Up @@ -38,13 +46,16 @@ export default class Device {
}

exposes(): zhc.Expose[] {
const exposes: zhc.Expose[] = [];
assert(this.definition, 'Cannot retreive exposes before definition is resolved');
if (typeof this.definition.exposes == 'function') {
const options: KeyValue = this.options;
return this.definition.exposes(this.zh, options);
exposes.push(...this.definition.exposes(this.zh, options));
} else {
return this.definition.exposes;
exposes.push(...this.definition.exposes);
}
exposes.push(LINKQUALITY);
return exposes;
}

async resolveDefinition(ignoreCache: boolean = false): Promise<void> {
Expand Down
82 changes: 30 additions & 52 deletions test/extensions/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,28 +315,22 @@ describe('Extension: Bridge', () => {

it('Should publish devices on startup', async () => {
await resetExtension();
// console.log(mockMQTT.publish.mock.calls.find((c) => c[0] === 'zigbee2mqtt/bridge/devices')[1]);
// console.log(mockMQTTPublishAsync.mock.calls.find((c) => c[0] === 'zigbee2mqtt/bridge/devices')[1]);
expect(mockMQTTPublishAsync).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/devices',
stringify([
{
date_code: undefined,
// definition: undefined,
disabled: false,
endpoints: {1: {bindings: [], clusters: {input: [], output: []}, configured_reportings: [], scenes: []}},
endpoints: {'1': {bindings: [], clusters: {input: [], output: []}, configured_reportings: [], scenes: []}},
friendly_name: 'Coordinator',
ieee_address: '0x00124b00120144ae',
interview_completed: false,
interviewing: false,
model_id: undefined,
network_address: 0,
power_source: undefined,
software_build_id: undefined,
supported: true,
type: 'Coordinator',
},
{
date_code: undefined,
definition: {
description: 'TRADFRI bulb E26/E27, white spectrum, globe, opal, 980 lm',
exposes: [
Expand Down Expand Up @@ -552,7 +546,7 @@ describe('Extension: Bridge', () => {
description: 'this is my bulb',
disabled: false,
endpoints: {
1: {
'1': {
bindings: [],
clusters: {
input: ['genBasic', 'genScenes', 'genOnOff', 'genLevelCtrl', 'lightingColorCtrl'],
Expand All @@ -577,7 +571,6 @@ describe('Extension: Bridge', () => {
model_id: 'TRADFRI bulb E27 WS opal 980lm',
network_address: 40369,
power_source: 'Mains (single phase)',
software_build_id: undefined,
supported: true,
type: 'Router',
},
Expand Down Expand Up @@ -754,7 +747,7 @@ describe('Extension: Bridge', () => {
},
disabled: false,
endpoints: {
1: {
'1': {
bindings: [],
clusters: {
input: ['genBasic', 'genScenes', 'genOnOff', 'genLevelCtrl', 'lightingColorCtrl'],
Expand All @@ -777,7 +770,6 @@ describe('Extension: Bridge', () => {
type: 'Router',
},
{
date_code: undefined,
definition: {
description: 'Hue dimmer switch',
exposes: [
Expand Down Expand Up @@ -881,7 +873,7 @@ describe('Extension: Bridge', () => {
},
disabled: false,
endpoints: {
1: {
'1': {
bindings: [
{cluster: 'genLevelCtrl', target: {endpoint: 1, ieee_address: '0x000b57fffec6a5b3', type: 'endpoint'}},
{cluster: 'genOnOff', target: {endpoint: 1, ieee_address: '0x000b57fffec6a5b3', type: 'endpoint'}},
Expand All @@ -893,7 +885,7 @@ describe('Extension: Bridge', () => {
configured_reportings: [],
scenes: [],
},
2: {bindings: [], clusters: {input: ['genBasic'], output: ['genOta', 'genOnOff']}, configured_reportings: [], scenes: []},
'2': {bindings: [], clusters: {input: ['genBasic'], output: ['genOta', 'genOnOff']}, configured_reportings: [], scenes: []},
},
friendly_name: 'remote',
ieee_address: '0x0017880104e45517',
Expand All @@ -902,12 +894,10 @@ describe('Extension: Bridge', () => {
model_id: 'RWL021',
network_address: 6535,
power_source: 'Battery',
software_build_id: undefined,
supported: true,
type: 'EndDevice',
},
{
date_code: undefined,
definition: {
description: 'Automatically generated definition',
exposes: [
Expand Down Expand Up @@ -982,7 +972,7 @@ describe('Extension: Bridge', () => {
},
disabled: false,
endpoints: {
1: {
'1': {
bindings: [],
clusters: {input: ['genBasic'], output: ['genBasic', 'genOnOff', 'genLevelCtrl', 'genScenes']},
configured_reportings: [],
Expand All @@ -997,12 +987,10 @@ describe('Extension: Bridge', () => {
model_id: 'notSupportedModelID',
network_address: 6536,
power_source: 'Battery',
software_build_id: undefined,
supported: false,
type: 'EndDevice',
},
{
date_code: undefined,
definition: {
description: 'Wireless mini switch',
exposes: [
Expand Down Expand Up @@ -1086,7 +1074,7 @@ describe('Extension: Bridge', () => {
},
disabled: false,
endpoints: {
1: {
'1': {
bindings: [],
clusters: {input: ['genBasic'], output: ['genBasic', 'genOnOff', 'genLevelCtrl', 'genScenes']},
configured_reportings: [
Expand All @@ -1108,12 +1096,10 @@ describe('Extension: Bridge', () => {
model_id: 'lumi.sensor_switch.aq2',
network_address: 6537,
power_source: 'Battery',
software_build_id: undefined,
supported: true,
type: 'EndDevice',
},
{
date_code: undefined,
definition: {
description: 'Temperature and humidity sensor',
exposes: [
Expand Down Expand Up @@ -1243,20 +1229,18 @@ describe('Extension: Bridge', () => {
vendor: 'Aqara',
},
disabled: false,
endpoints: {1: {bindings: [], clusters: {input: ['genBasic'], output: []}, configured_reportings: [], scenes: []}},
endpoints: {'1': {bindings: [], clusters: {input: ['genBasic'], output: []}, configured_reportings: [], scenes: []}},
friendly_name: 'weather_sensor',
ieee_address: '0x0017880104e45522',
interview_completed: true,
interviewing: false,
model_id: 'lumi.weather',
network_address: 6539,
power_source: 'Battery',
software_build_id: undefined,
supported: true,
type: 'EndDevice',
},
{
date_code: undefined,
definition: {
description: 'Mi smart plug',
exposes: [
Expand Down Expand Up @@ -1392,20 +1376,18 @@ describe('Extension: Bridge', () => {
vendor: 'Xiaomi',
},
disabled: false,
endpoints: {1: {bindings: [], clusters: {input: ['genBasic', 'genOnOff'], output: []}, configured_reportings: [], scenes: []}},
endpoints: {'1': {bindings: [], clusters: {input: ['genBasic', 'genOnOff'], output: []}, configured_reportings: [], scenes: []}},
friendly_name: 'power_plug',
ieee_address: '0x0017880104e45524',
interview_completed: true,
interviewing: false,
model_id: 'lumi.plug',
network_address: 6540,
power_source: 'Mains (single phase)',
software_build_id: undefined,
supported: true,
type: 'Router',
},
{
date_code: undefined,
definition: {
description: 'zigfred plus smart in-wall switch',
exposes: [
Expand Down Expand Up @@ -1436,18 +1418,6 @@ describe('Extension: Bridge', () => {
'button_4_release',
],
},
{
access: 1,
category: 'diagnostic',
description: 'Link quality (signal strength)',
label: 'Linkquality',
name: 'linkquality',
property: 'linkquality',
type: 'numeric',
unit: 'lqi',
value_max: 255,
value_min: 0,
},
{
endpoint: 'l1',
features: [
Expand Down Expand Up @@ -1684,6 +1654,18 @@ describe('Extension: Bridge', () => {
],
type: 'cover',
},
{
access: 1,
category: 'diagnostic',
description: 'Link quality (signal strength)',
label: 'Linkquality',
name: 'linkquality',
property: 'linkquality',
type: 'numeric',
unit: 'lqi',
value_max: 255,
value_min: 0,
},
],
model: 'ZFP-1A-CH',
options: [
Expand Down Expand Up @@ -1851,43 +1833,43 @@ describe('Extension: Bridge', () => {
},
disabled: false,
endpoints: {
10: {
'10': {
bindings: [],
clusters: {input: ['genBasic', 'genScenes', 'genOnOff', 'genLevelCtrl'], output: []},
configured_reportings: [],
scenes: [],
},
11: {
'11': {
bindings: [],
clusters: {input: ['genBasic', 'genScenes', 'closuresWindowCovering'], output: []},
configured_reportings: [],
scenes: [],
},
12: {
'12': {
bindings: [],
clusters: {input: ['genBasic', 'genScenes', 'closuresWindowCovering'], output: []},
configured_reportings: [],
scenes: [],
},
5: {
'5': {
bindings: [],
clusters: {input: ['genBasic', 'genScenes', 'genOnOff', 'genLevelCtrl', 'lightingColorCtrl'], output: []},
configured_reportings: [],
scenes: [],
},
7: {
'7': {
bindings: [],
clusters: {input: ['genBasic', 'genScenes', 'genOnOff', 'genLevelCtrl'], output: []},
configured_reportings: [],
scenes: [],
},
8: {
'8': {
bindings: [],
clusters: {input: ['genBasic', 'genScenes', 'genOnOff', 'genLevelCtrl'], output: []},
configured_reportings: [],
scenes: [],
},
9: {
'9': {
bindings: [],
clusters: {input: ['genBasic', 'genScenes', 'genOnOff', 'genLevelCtrl'], output: []},
configured_reportings: [],
Expand All @@ -1902,12 +1884,10 @@ describe('Extension: Bridge', () => {
model_id: 'zigfred plus',
network_address: 6589,
power_source: 'Mains (single phase)',
software_build_id: undefined,
supported: true,
type: 'Router',
},
{
date_code: undefined,
definition: {
description: 'TRADFRI bulb E26/E27, white spectrum, globe, opal, 980 lm',
exposes: [
Expand Down Expand Up @@ -2122,7 +2102,7 @@ describe('Extension: Bridge', () => {
},
disabled: false,
endpoints: {
1: {
'1': {
bindings: [],
clusters: {
input: ['genBasic', 'genScenes', 'genOnOff', 'genLevelCtrl', 'lightingColorCtrl'],
Expand All @@ -2136,11 +2116,9 @@ describe('Extension: Bridge', () => {
ieee_address: '0x000b57fffec6a5c2',
interview_completed: true,
interviewing: false,
manufacturer: undefined,
model_id: 'TRADFRI bulb E27 WS opal 980lm',
network_address: 40369,
power_source: 'Mains (single phase)',
software_build_id: undefined,
supported: true,
type: 'Router',
},
Expand Down
Loading