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 1.0.11 #99

Merged
merged 33 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d2145c9
Refactor PowerSource
Luligu Nov 22, 2024
44c9e89
Dev 1.0.11-dev.1
Luligu Nov 25, 2024
3a13e77
Platform jest test on shelly1
Luligu Nov 25, 2024
788f29d
Dev 1.0.11-dev.2
Luligu Dec 1, 2024
3d769e2
Jest shellyProperty 100%
Luligu Dec 1, 2024
c315131
Jest shellyComponent 100%
Luligu Dec 1, 2024
d578e9a
Jest shellyComponent 100%
Luligu Dec 1, 2024
fdc9664
Jest shellyComponent 100%
Luligu Dec 1, 2024
39b3856
Jest platform
Luligu Dec 1, 2024
0f39335
Jest shellyComponent 100%
Luligu Dec 1, 2024
0ccbc12
Dev 1.0.11-dev.2
Luligu Dec 1, 2024
503d11f
Dev 1.0.11-dev.2
Luligu Dec 1, 2024
b1f10e6
Verified support for shelly2pmg3 (Shelly 2PM Gen 3) mode cover
Luligu Dec 1, 2024
48d22b1
The cache file is saved for all sleepy devices when they wake up
Luligu Dec 2, 2024
c9c448c
Dev 1.0.11-dev.3
Luligu Dec 2, 2024
ab70f3d
Requires matterbridge 1.6.5.
Luligu Dec 2, 2024
8762e62
Refactor Thermostat component
Luligu Dec 3, 2024
5ed7687
Refactor Thermostat component for BLU TRV
Luligu Dec 3, 2024
e1529ea
Add separate shellySwitchCommandHandler
Luligu Dec 3, 2024
1705dd4
Add separate shellyLight
Luligu Dec 3, 2024
b51c3c1
Add separate shellyCover
Luligu Dec 3, 2024
91b3de2
Add separate shellyUpdateHandler
Luligu Dec 3, 2024
030da27
Add deviceType modeSelect
Luligu Dec 3, 2024
24b7892
Dev 1.0.11-dev.4
Luligu Dec 3, 2024
112b667
CHANGELOG
Luligu Dec 3, 2024
12a5fa4
Dev 1.0.11-dev.4
Luligu Dec 3, 2024
2879cf6
Add Identify cluster
Luligu Dec 3, 2024
99479e6
Require node 18, 20 or 22
Luligu Dec 4, 2024
2cb91b7
Refactor PowerSource
Luligu Dec 4, 2024
fe9aabf
Dev 1.0.11-dev.5
Luligu Dec 4, 2024
3392014
Dev 1.0.11-dev.5
Luligu Dec 4, 2024
51683f2
Release 1.0.11
Luligu Dec 4, 2024
fb1e96c
Release 1.0.11
Luligu Dec 4, 2024
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
Prev Previous commit
Next Next commit
Add separate shellyCover
CommandHandler
  • Loading branch information
Luligu committed Dec 3, 2024
commit b51c3c1134852e8af53156d349f784f922c679c3
14 changes: 7 additions & 7 deletions src/platform.ts
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ import { DiscoveredDevice } from './mdnsScanner.js';
import { ShellyDevice } from './shellyDevice.js';
import { isLightComponent, isSwitchComponent, ShellyComponent, ShellyCoverComponent, ShellyLightComponent, ShellySwitchComponent } from './shellyComponent.js';
import { ShellyData, ShellyDataType } from './shellyTypes.js';
import { shellyLightCommandHandler, shellySwitchCommandHandler } from './platformCommandHadlers.js';
import { shellyCoverCommandHandler, shellyLightCommandHandler, shellySwitchCommandHandler } from './platformCommandHadlers.js';

type ConfigDeviceIp = Record<string, string>;

@@ -730,18 +730,18 @@ export class ShellyPlatform extends MatterbridgeDynamicPlatform {

// Add command handlers
mbDevice.addCommandHandler('upOrOpen', async (data) => {
this.shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Open', 0);
shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Open', 0);
});
mbDevice.addCommandHandler('downOrClose', async (data) => {
this.shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Close', 10000);
shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Close', 10000);
});
mbDevice.addCommandHandler('stopMotion', async (data) => {
this.shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Stop');
shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Stop');
});
mbDevice.addCommandHandler('goToLiftPercentage', async (data) => {
if (data.request.liftPercent100thsValue === 0) this.shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Open', 0);
else if (data.request.liftPercent100thsValue === 10000) this.shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Close', 10000);
else this.shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'GoToPosition', data.request.liftPercent100thsValue);
if (data.request.liftPercent100thsValue === 0) shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Open', 0);
else if (data.request.liftPercent100thsValue === 10000) shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'Close', 10000);
else shellyCoverCommandHandler(mbDevice, data.endpoint.number, device, 'GoToPosition', data.request.liftPercent100thsValue);
});
// Add event handler
coverComponent.on('update', (component: string, property: string, value: ShellyDataType) => {
61 changes: 59 additions & 2 deletions src/platformCommandHadlers.ts
Original file line number Diff line number Diff line change
@@ -21,12 +21,12 @@
* limitations under the License. *
*/

import { EndpointNumber, MatterbridgeDevice } from 'matterbridge';
import { EndpointNumber, MatterbridgeDevice, WindowCovering, WindowCoveringCluster } from 'matterbridge';
import { db, dn, er, hk, idn, nf, rs, YELLOW } from 'matterbridge/logger';
import { isValidNumber, isValidObject } from 'matterbridge/utils';

import { ShellyDevice } from './shellyDevice.js';
import { ShellyLightComponent, ShellySwitchComponent } from './shellyComponent.js';
import { ShellyCoverComponent, ShellyLightComponent, ShellySwitchComponent } from './shellyComponent.js';

export function shellySwitchCommandHandler(
matterbridgeDevice: MatterbridgeDevice,
@@ -137,3 +137,60 @@ export function shellyLightCommandHandler(
}
return true;
}

export function shellyCoverCommandHandler(
matterbridgeDevice: MatterbridgeDevice,
endpointNumber: EndpointNumber | undefined,
shellyDevice: ShellyDevice,
command: string,
pos?: number,
): boolean {
// Get the matter endpoint
if (!endpointNumber) {
shellyDevice.log.error(`shellyCoverCommandHandler error: endpointNumber undefined for shelly device ${dn}${shellyDevice?.id}${er}`);
return false;
}
const endpoint = matterbridgeDevice.getChildEndpoint(endpointNumber);
if (!endpoint) {
shellyDevice.log.error(`shellyCoverCommandHandler error: endpoint not found for shelly device ${dn}${shellyDevice?.id}${er}`);
return false;
}
// Get the Shelly cover component
const componentName = endpoint.uniqueStorageKey;
if (!componentName) {
shellyDevice.log.error(`shellyCoverCommandHandler error: componentName not found for endpoint ${endpointNumber} on shelly device ${dn}${shellyDevice?.id}${er}`);
return false;
}
const coverComponent = shellyDevice?.getComponent(componentName) as ShellyCoverComponent;
if (!coverComponent) {
shellyDevice.log.error(`shellyCoverCommandHandler error: component ${componentName} not found for shelly device ${dn}${shellyDevice?.id}${er}`);
return false;
}
// Matter uses 10000 = fully closed 0 = fully opened
// Shelly uses 0 = fully closed 100 = fully opened
const coverCluster = endpoint.getClusterServer(
WindowCoveringCluster.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift /* , WindowCovering.Feature.AbsolutePosition*/),
);
if (!coverCluster) {
shellyDevice.log.error('shellyCoverCommandHandler error: cluster WindowCoveringCluster not found');
return false;
}
if (command === 'Stop') {
shellyDevice.log.info(`${db}Sent command ${hk}${componentName}${nf}:${command}()${db} to shelly device ${idn}${shellyDevice?.id}${rs}${db}`);
coverComponent.Stop();
} else if (command === 'Open') {
matterbridgeDevice.setAttribute(WindowCoveringCluster.id, 'targetPositionLiftPercent100ths', 0, shellyDevice.log, endpoint);
shellyDevice.log.info(`${db}Sent command ${hk}${componentName}${nf}:${command}()${db} to shelly device ${idn}${shellyDevice?.id}${rs}${db}`);
coverComponent.Open();
} else if (command === 'Close') {
matterbridgeDevice.setAttribute(WindowCoveringCluster.id, 'targetPositionLiftPercent100ths', 10000, shellyDevice.log, endpoint);
shellyDevice.log.info(`${db}Sent command ${hk}${componentName}${nf}:${command}()${db} to shelly device ${idn}${shellyDevice?.id}${rs}${db}`);
coverComponent.Close();
} else if (command === 'GoToPosition' && isValidNumber(pos, 0, 10000)) {
matterbridgeDevice.setAttribute(WindowCoveringCluster.id, 'targetPositionLiftPercent100ths', pos, shellyDevice.log, endpoint);
const shellyPos = 100 - Math.max(Math.min(Math.round(pos / 100), 100), 0);
shellyDevice.log.info(`${db}Sent command ${hk}${componentName}${nf}:${command}(${shellyPos})${db} to shelly device ${idn}${shellyDevice?.id}${rs}${db}`);
coverComponent.GoToPosition(shellyPos);
}
return true;
}