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

Release 0.4.0 #9

Merged
merged 1 commit into from
Jun 23, 2024
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
16 changes: 3 additions & 13 deletions .github/workflows/build matterbridge plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,15 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Install matterbridge
run: npm -g install matterbridge

- name: Install dependencies
run: npm install

- name: Install matterbridge
run: npm install --save-dev matterbridge

- name: Lint the project
run: npm run lint

#- name: Test the project
# run: npm run test

- name: Build the project
run: npm run build

- name: List, audit, fix outdated dependencies and build again
run: |
npm list --outdated
npm audit || true # ignore failures
npm audit fix || true
npm list --outdated
npm run build
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

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

## [0.4.0] - 2024-06-23

### Added

- [update]: If the device has a firmware update available, a message is displayed.
- [update]: If the device's CoIoT is not correctly set, a message is displayed.

### Fixed

- [deviceGen2]: Fix mdnsDiscovery for gen 2 pro devices. When you upgrade select resetStorageDiscover on the first start please.

<a href="https://www.buymeacoffee.com/luligugithub">
<img src="./yellow-button.png" alt="Buy me a coffee" width="120">
</a>

## [0.3.3] - 2024-06-21

### Added

- [deviceGen2]: Fix power meter update from gen. 2/3 devices.

<a href="https://www.buymeacoffee.com/luligugithub">
<img src="./yellow-button.png" alt="Buy me a coffee" width="120">
</a>

## [0.3.2] - 2024-06-21

### Added
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Features:
- Shelly Gen 1 devices are controlled using the CoIoT protocol (see the note below).
- Shelly Gen 2 and Gen 3 devices are controlled using WebSocket.
- The Matter device takes the name configured in the Shelly device's web page.
- A 10-minute timer checks if the device has reported in that time.
- If the device has a firmware update available, a message is displayed.
- If the device's CoIoT is not correctly set, a message is displayed.
- A 10-minute timer checks if the device has reported within that time frame, and fetch un update.

## Acknowledgements

Expand Down
61 changes: 51 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matterbridge-shelly",
"version": "0.3.3",
"version": "0.4.0",
"description": "Matterbridge shelly plugin",
"author": "https://github.com/Luligu",
"license": "Apache-2.0",
Expand Down Expand Up @@ -104,15 +104,16 @@
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.12",
"@types/multicast-dns": "^7.2.4",
"@types/node": "^20.14.6",
"@types/node": "^20.14.8",
"@types/ws": "^8.5.10",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"matterbridge": "file:../matterbridge",
"prettier": "^3.3.2",
"ts-jest": "^29.1.5",
"typescript": "^5.4.5",
"typescript": "^5.5.2",
"typescript-eslint": "^7.13.1"
},
"overrides": {
Expand Down
53 changes: 35 additions & 18 deletions src/mdnsScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,56 @@ export class MdnsScanner extends EventEmitter {
this.scanner = mdns();
this.scanner.on('response', async (response: ResponsePacket) => {
let port = 0;
let gen = 0;
let gen = 1;
if (debug) this.log.debug(`***--- start ---`);
// if (debug && response.answers.length === 0 && response.additionals.length === 0) this.log.debug('ResponsePacket:\n', response);
if (debug) this.log.debug(`--- response.answers ---`);
for (const a of response.answers) {
if (debug && a.type === 'PTR') {
this.log.debug(`[${idn}${a.type}${rs}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
if (debug && a.type === 'TXT') {
// this.log.debug(`[${idn}${a.type}${rs}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
if (debug && a.type === 'PTR' && a.name === '_http._tcp.local') {
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
if (debug && a.type === 'A' && a.name.startsWith('shelly')) {
if (debug && a.type === 'A' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
if (debug && a.type === 'NSEC' && a.name.startsWith('shelly')) {
if (debug && a.type === 'NSEC' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
if (debug && a.type === 'SRV' && a.name.startsWith('shelly')) {
if (debug && a.type === 'SRV' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
if (debug && a.type === 'TXT' && a.name.startsWith('shelly')) {
if (debug && a.type === 'TXT' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${a.data}`);
}
if (a.type === 'SRV' && a.name.startsWith('shelly')) {
if (a.type === 'SRV' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
port = a.data.port;
}
if (a.type === 'A' && a.name.startsWith('shelly')) {
if (!this.discoveredDevices.has(a.name.replace('.local', ''))) {
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}`);
this.discoveredDevices.set(a.name.replace('.local', ''), { id: a.name.replace('.local', ''), host: a.data, port, gen: 1 });
this.emit('discovered', { id: a.name.replace('.local', ''), host: a.data, port, gen: 1 });
if (a.type === 'TXT' && a.name.startsWith('Shelly') && a.data.toString() === 'gen=2') {
gen = 2;
}
if (a.type === 'A' && (a.name.startsWith('shelly') || a.name.startsWith('Shelly'))) {
const [name, mac] = a.name.replace('.local', '').split('-');
const deviceId = name.toLowerCase() + '-' + mac.toUpperCase();
if (!this.discoveredDevices.has(deviceId)) {
this.log.info(`Discovered shelly gen: ${CYAN}${gen}${nf} device id: ${hk}${deviceId}${nf} host: ${zb}${a.data}${nf} port: ${zb}${port}${nf}`);
this.discoveredDevices.set(deviceId, { id: deviceId, host: a.data, port, gen });
this.emit('discovered', { id: deviceId, host: a.data, port, gen });
}
}
}
if (debug) this.log.debug(`--- response.additionals ---`);
for (const a of response.additionals) {
if (debug && a.type === 'PTR') {
this.log.debug(`[${idn}${a.type}${rs}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
if (debug && a.type === 'TXT') {
// this.log.debug(`[${idn}${a.type}${rs}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
if (debug && a.type === 'PTR' && a.name === '_http._tcp.local') {
this.log.debug(`[${BLUE}${a.type}${db}] Name: ${CYAN}${a.name}${db} data: ${typeof a.data === 'string' ? a.data : debugStringify(a.data)}`);
}
Expand All @@ -100,15 +115,16 @@ export class MdnsScanner extends EventEmitter {
gen = parseInt(a.data.toString().replace('gen=', ''));
}
if (a.type === 'A' && a.name.startsWith('Shelly')) {
if (!this.discoveredDevices.has(a.name.replace('.local', '').toLowerCase())) {
this.log.info(
`Discovered shelly gen: ${CYAN}${gen}${nf} device id: ${hk}${a.name.replace('.local', '').toLowerCase()}${nf} host: ${zb}${a.data}${nf} port: ${zb}${port}${nf}`,
);
this.discoveredDevices.set(a.name.replace('.local', '').toLowerCase(), { id: a.name.replace('.local', '').toLowerCase(), host: a.data, port, gen });
this.emit('discovered', { id: a.name.replace('.local', '').toLowerCase(), host: a.data, port, gen });
const [name, mac] = a.name.replace('.local', '').split('-');
const deviceId = name.toLowerCase() + '-' + mac.toUpperCase();
if (!this.discoveredDevices.has(deviceId)) {
this.log.info(`Discovered shelly gen: ${CYAN}${gen}${nf} device id: ${hk}${deviceId}${nf} host: ${zb}${a.data}${nf} port: ${zb}${port}${nf}`);
this.discoveredDevices.set(deviceId, { id: deviceId, host: a.data, port, gen });
this.emit('discovered', { id: deviceId, host: a.data, port, gen });
}
}
}
if (debug) this.log.debug(`--- end ---`);
});

this.sendQuery();
Expand Down Expand Up @@ -150,8 +166,9 @@ export class MdnsScanner extends EventEmitter {
}

/*
// node dist/mdnsScanner.js mdnsScanner
if (process.argv.includes('mdnsScanner')) {
const mdnsScanner = new MdnsScanner();
const mdnsScanner = new MdnsScanner(true);
mdnsScanner.start(undefined, true);

process.on('SIGINT', async function () {
Expand Down
Loading
Loading