Skip to content

Commit a0a351b

Browse files
authored
Merge pull request #9 from Luligu/dev
Release 0.4.0
2 parents 9991398 + 38ae5c5 commit a0a351b

9 files changed

Lines changed: 352 additions & 51 deletions

File tree

.github/workflows/build matterbridge plugin.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,15 @@ jobs:
2121
with:
2222
node-version: ${{ matrix.node-version }}
2323

24+
- name: Install matterbridge
25+
run: npm -g install matterbridge
26+
2427
- name: Install dependencies
2528
run: npm install
2629

27-
- name: Install matterbridge
28-
run: npm install --save-dev matterbridge
29-
3030
- name: Lint the project
3131
run: npm run lint
3232

33-
#- name: Test the project
34-
# run: npm run test
35-
3633
- name: Build the project
3734
run: npm run build
3835

39-
- name: List, audit, fix outdated dependencies and build again
40-
run: |
41-
npm list --outdated
42-
npm audit || true # ignore failures
43-
npm audit fix || true
44-
npm list --outdated
45-
npm run build

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.4.0] - 2024-06-23
6+
7+
### Added
8+
9+
- [update]: If the device has a firmware update available, a message is displayed.
10+
- [update]: If the device's CoIoT is not correctly set, a message is displayed.
11+
12+
### Fixed
13+
14+
- [deviceGen2]: Fix mdnsDiscovery for gen 2 pro devices. When you upgrade select resetStorageDiscover on the first start please.
15+
16+
<a href="https://www.buymeacoffee.com/luligugithub">
17+
<img src="./yellow-button.png" alt="Buy me a coffee" width="120">
18+
</a>
19+
20+
## [0.3.3] - 2024-06-21
21+
22+
### Added
23+
24+
- [deviceGen2]: Fix power meter update from gen. 2/3 devices.
25+
26+
<a href="https://www.buymeacoffee.com/luligugithub">
27+
<img src="./yellow-button.png" alt="Buy me a coffee" width="120">
28+
</a>
29+
530
## [0.3.2] - 2024-06-21
631

732
### Added

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ Features:
2424
- Shelly Gen 1 devices are controlled using the CoIoT protocol (see the note below).
2525
- Shelly Gen 2 and Gen 3 devices are controlled using WebSocket.
2626
- The Matter device takes the name configured in the Shelly device's web page.
27-
- A 10-minute timer checks if the device has reported in that time.
27+
- If the device has a firmware update available, a message is displayed.
28+
- If the device's CoIoT is not correctly set, a message is displayed.
29+
- A 10-minute timer checks if the device has reported within that time frame, and fetch un update.
2830

2931
## Acknowledgements
3032

package-lock.json

Lines changed: 51 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "matterbridge-shelly",
3-
"version": "0.3.3",
3+
"version": "0.4.0",
44
"description": "Matterbridge shelly plugin",
55
"author": "https://github.com/Luligu",
66
"license": "Apache-2.0",
@@ -104,15 +104,16 @@
104104
"@types/eslint__js": "^8.42.3",
105105
"@types/jest": "^29.5.12",
106106
"@types/multicast-dns": "^7.2.4",
107-
"@types/node": "^20.14.6",
107+
"@types/node": "^20.14.8",
108108
"@types/ws": "^8.5.10",
109109
"eslint-config-prettier": "^9.1.0",
110110
"eslint-plugin-jest": "^28.6.0",
111111
"eslint-plugin-prettier": "^5.1.3",
112112
"jest": "^29.7.0",
113+
"matterbridge": "file:../matterbridge",
113114
"prettier": "^3.3.2",
114115
"ts-jest": "^29.1.5",
115-
"typescript": "^5.4.5",
116+
"typescript": "^5.5.2",
116117
"typescript-eslint": "^7.13.1"
117118
},
118119
"overrides": {

src/mdnsScanner.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,56 @@ export class MdnsScanner extends EventEmitter {
4343
this.scanner = mdns();
4444
this.scanner.on('response', async (response: ResponsePacket) => {
4545
let port = 0;
46-
let gen = 0;
46+
let gen = 1;
47+
if (debug) this.log.debug(`***--- start ---`);
48+
// if (debug && response.answers.length === 0 && response.additionals.length === 0) this.log.debug('ResponsePacket:\n', response);
49+
if (debug) this.log.debug(`--- response.answers ---`);
4750
for (const a of response.answers) {
4851
if (debug && a.type === 'PTR') {
4952
this.log.debug(`[${idn}${a.type}${rs}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
5053
}
54+
if (debug && a.type === 'TXT') {
55+
// this.log.debug(`[${idn}${a.type}${rs}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
56+
}
5157
if (debug && a.type === 'PTR' && a.name === '_http._tcp.local') {
5258
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
5359
}
54-
if (debug && a.type === 'A' && a.name.startsWith('shelly')) {
60+
if (debug && a.type === 'A' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
5561
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
5662
}
57-
if (debug && a.type === 'NSEC' && a.name.startsWith('shelly')) {
63+
if (debug && a.type === 'NSEC' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
5864
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
5965
}
60-
if (debug && a.type === 'SRV' && a.name.startsWith('shelly')) {
66+
if (debug && a.type === 'SRV' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
6167
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
6268
}
63-
if (debug && a.type === 'TXT' && a.name.startsWith('shelly')) {
69+
if (debug && a.type === 'TXT' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
6470
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${a.data}`);
6571
}
66-
if (a.type === 'SRV' && a.name.startsWith('shelly')) {
72+
if (a.type === 'SRV' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
6773
port = a.data.port;
6874
}
69-
if (a.type === 'A' && a.name.startsWith('shelly')) {
70-
if (!this.discoveredDevices.has(a.name.replace('.local', ''))) {
71-
this.log.info(`Discovered shelly gen: ${CYAN}1${nf} device id: ${hk}${a.name.replace('.local', '')}${nf} host: ${zb}${a.data}${nf} port: ${zb}${port}${nf}`);
72-
this.discoveredDevices.set(a.name.replace('.local', ''), { id: a.name.replace('.local', ''), host: a.data, port, gen: 1 });
73-
this.emit('discovered', { id: a.name.replace('.local', ''), host: a.data, port, gen: 1 });
75+
if (a.type === 'TXT' && a.name.startsWith('Shelly') && a.data.toString() === 'gen=2') {
76+
gen = 2;
77+
}
78+
if (a.type === 'A' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
79+
const [name, mac] = a.name.replace('.local', '').split('-');
80+
const deviceId = name.toLowerCase() + '-' + mac.toUpperCase();
81+
if (!this.discoveredDevices.has(deviceId)) {
82+
this.log.info(`Discovered shelly gen: ${CYAN}${gen}${nf} device id: ${hk}${deviceId}${nf} host: ${zb}${a.data}${nf} port: ${zb}${port}${nf}`);
83+
this.discoveredDevices.set(deviceId, { id: deviceId, host: a.data, port, gen });
84+
this.emit('discovered', { id: deviceId, host: a.data, port, gen });
7485
}
7586
}
7687
}
88+
if (debug) this.log.debug(`--- response.additionals ---`);
7789
for (const a of response.additionals) {
7890
if (debug && a.type === 'PTR') {
7991
this.log.debug(`[${idn}${a.type}${rs}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
8092
}
93+
if (debug && a.type === 'TXT') {
94+
// this.log.debug(`[${idn}${a.type}${rs}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
95+
}
8196
if (debug && a.type === 'PTR' && a.name === '_http._tcp.local') {
8297
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
8398
}
@@ -100,15 +115,16 @@ export class MdnsScanner extends EventEmitter {
100115
gen = parseInt(a.data.toString().replace('gen=', ''));
101116
}
102117
if (a.type === 'A' && a.name.startsWith('Shelly')) {
103-
if (!this.discoveredDevices.has(a.name.replace('.local', '').toLowerCase())) {
104-
this.log.info(
105-
`Discovered shelly gen: ${CYAN}${gen}${nf} device id: ${hk}${a.name.replace('.local', '').toLowerCase()}${nf} host: ${zb}${a.data}${nf} port: ${zb}${port}${nf}`,
106-
);
107-
this.discoveredDevices.set(a.name.replace('.local', '').toLowerCase(), { id: a.name.replace('.local', '').toLowerCase(), host: a.data, port, gen });
108-
this.emit('discovered', { id: a.name.replace('.local', '').toLowerCase(), host: a.data, port, gen });
118+
const [name, mac] = a.name.replace('.local', '').split('-');
119+
const deviceId = name.toLowerCase() + '-' + mac.toUpperCase();
120+
if (!this.discoveredDevices.has(deviceId)) {
121+
this.log.info(`Discovered shelly gen: ${CYAN}${gen}${nf} device id: ${hk}${deviceId}${nf} host: ${zb}${a.data}${nf} port: ${zb}${port}${nf}`);
122+
this.discoveredDevices.set(deviceId, { id: deviceId, host: a.data, port, gen });
123+
this.emit('discovered', { id: deviceId, host: a.data, port, gen });
109124
}
110125
}
111126
}
127+
if (debug) this.log.debug(`--- end ---`);
112128
});
113129

114130
this.sendQuery();
@@ -150,8 +166,9 @@ export class MdnsScanner extends EventEmitter {
150166
}
151167

152168
/*
169+
// node dist/mdnsScanner.js mdnsScanner
153170
if (process.argv.includes('mdnsScanner')) {
154-
const mdnsScanner = new MdnsScanner();
171+
const mdnsScanner = new MdnsScanner(true);
155172
mdnsScanner.start(undefined, true);
156173
157174
process.on('SIGINT', async function () {

0 commit comments

Comments
 (0)