Skip to content

Commit

Permalink
Several smaller fixes (#172)
Browse files Browse the repository at this point in the history
* Optimize Ecosystem icon display

* Just one status per fabric

* Prevent crash on BigInt stringify

* Adjust to better value

... because of mireds calculation

* add import for former commit

* Use Plain log

else not easy readable when getting logs

* Changelog

* Changelog

* Add missing methods

fixes #171

* package-lock
  • Loading branch information
Apollon77 authored Nov 28, 2024
1 parent 2c74ce1 commit 3d98ea3
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 28 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ TBD
-->

## Changelog

### __WORK IN PROGRESS__
* (@Apollon77) Uses plain matter.js logs for better readability
* (@Apollon77) Prevents ghost connection entries in the UI
* (@Apollon77) Adds some missing implementations for Controller of Door, Window, FloodAlarm and Motion

### 0.2.1 (2024-11-27)
* (@Apollon77) Adds Color Temperature conversion if unit is "mireds"
* (@Apollon77) Fixes Color Temperature cluster initialization
* (@Apollon77) Fixes Min/Max calculation when unit conversion is used

### 0.2.0 (2024-11-26)
* IMPORTANT: Breaking change!! Please decommission ALL devices and do a full factory reset of the adapter Matter storage before installing this version. Pair the devices new afterwards.
* IMPORTANT: Breaking change!! Please decommission ALL devices and do a full factory reset of the adapter Matter storage before installing this version. Pair the devices new afterward.
* (@Apollon77) Finalizes Devices, Bridges and Controller functionality with a first set of 11 device types
* (@Apollon77) Upgrades to new Matter.js version and API (breaks storage structure)
* (@GermanBluefox) Moved build process of GUI to vite
Expand Down
1 change: 0 additions & 1 deletion src-admin/package-lock.json

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

14 changes: 10 additions & 4 deletions src-admin/src/Tabs/BridgesAndDevices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,19 @@ class BridgesAndDevices<TProps extends BridgesAndDevicesProps, TState extends Br
}
}

static getVendorName(vendorId: number): string {
return VENDOR_IDS[vendorId]
? `${VENDOR_IDS[vendorId]} (0x${vendorId.toString(16)})`
: `0x${vendorId.toString(16)}`;
}

static getVendorIcon(vendorId: number, themeType: ThemeType): React.JSX.Element | null {
const vendor = VENDOR_IDS[vendorId];

if (vendor === 'Amazon Lab126') {
return (
<SiAmazonalexa
title={vendor}
title={this.getVendorName(vendorId)}
style={{
...STYLES.vendorIcon,
color: themeType === 'dark' ? '#0000dc' : '#001ca8',
Expand All @@ -135,7 +141,7 @@ class BridgesAndDevices<TProps extends BridgesAndDevicesProps, TState extends Br
/>
);
}
if (vendor === 'Apple Inc.') {
if (vendor === 'Apple Inc.' || vendor === 'Apple Keychain') {
return (
<SiApple
title={vendor}
Expand All @@ -146,7 +152,7 @@ class BridgesAndDevices<TProps extends BridgesAndDevicesProps, TState extends Br
/>
);
}
if (vendor === 'Samsung') {
if (vendor === 'SmartThings, Inc.' || vendor === 'Samsung') {
return (
<SiSmartthings
title={vendor}
Expand Down Expand Up @@ -284,7 +290,7 @@ class BridgesAndDevices<TProps extends BridgesAndDevicesProps, TState extends Br
<TableRow key={i}>
<TableCell>
{BridgesAndDevices.getVendorIcon(info.vendorId, this.props.themeType) ||
info.vendorId}
BridgesAndDevices.getVendorName(info.vendorId)}
{info.label ? (
<span
style={{
Expand Down
7 changes: 7 additions & 0 deletions src/lib/devices/Door.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class Door extends GenericDevice {
}
return this.#getValueState.value;
}

updateValue(value: boolean): Promise<void> {
if (!this.#getValueState) {
throw new Error('Value state not found');
}
return this.#getValueState.updateValue(value);
}
}

export default Door;
7 changes: 7 additions & 0 deletions src/lib/devices/FloodAlarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class FloodAlarm extends GenericDevice {
}
return this.#getValueState.value;
}

updateValue(value: boolean): Promise<void> {
if (!this.#getValueState) {
throw new Error('Value state not found');
}
return this.#getValueState.updateValue(value);
}
}

export default FloodAlarm;
14 changes: 14 additions & 0 deletions src/lib/devices/Motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class Motion extends GenericDevice {
return this.#getMotionState.value;
}

updateMotion(value: boolean): Promise<void> {
if (!this.#getMotionState) {
throw new Error('Value state not found');
}
return this.#getMotionState.updateValue(value);
}

hasBrightness(): boolean {
return this.propertyNames.includes(PropertyType.Brightness);
}
Expand All @@ -45,6 +52,13 @@ class Motion extends GenericDevice {
}
return this.#getBrightnessState.value;
}

updateBrightness(value: number): Promise<void> {
if (!this.#getBrightnessState) {
throw new Error('Brightness state not found');
}
return this.#getBrightnessState.updateValue(value);
}
}

export default Motion;
7 changes: 7 additions & 0 deletions src/lib/devices/Temperature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class Temperature extends GenericDevice {
}
return this.#getHumidityState.value;
}

updateHumidity(value: number): Promise<void> {
if (!this.#getHumidityState) {
throw new Error('Humidity state not found');
}
return this.#getHumidityState.updateValue(value);
}
}

export default Temperature;
7 changes: 7 additions & 0 deletions src/lib/devices/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class Window extends GenericDevice {
}
return this.#getValueState.value;
}

updateValue(value: boolean): Promise<void> {
if (!this.#getValueState) {
throw new Error('Value state not found');
}
return this.#getValueState.updateValue(value);
}
}

export default Window;
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as utils from '@iobroker/adapter-core';
import ChannelDetector, { type DetectorState, Types } from '@iobroker/type-detector';
import { Environment, LogLevel, Logger, StorageService } from '@matter/main';
import { Environment, LogLevel, LogFormat, Logger, StorageService } from '@matter/main';
import axios from 'axios';
import jwt from 'jsonwebtoken';
import fs from 'node:fs/promises';
Expand Down Expand Up @@ -340,6 +340,7 @@ export class MatterAdapter extends utils.Adapter {
async prepareMatterEnvironment(): Promise<void> {
const config: MatterAdapterConfig = this.config as MatterAdapterConfig;
Logger.defaultLogLevel = LogLevel.DEBUG;
Logger.format = LogFormat.PLAIN;
Logger.log = (level: LogLevel, formattedLog: string) => {
switch (level) {
case LogLevel.DEBUG:
Expand Down
29 changes: 9 additions & 20 deletions src/matter/BaseServerNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger, type ServerNode, type SessionsBehavior } from '@matter/main';
import { Logger, type ServerNode, type SessionsBehavior, serialize } from '@matter/main';
import type { MatterAdapter } from '../main';
import type { GeneralNode, MessageResponse } from './GeneralNode';

Expand Down Expand Up @@ -82,24 +82,13 @@ export abstract class BaseServerNode implements GeneralNode {
const activeSessions = Object.values(this.serverNode.state.sessions.sessions);
const fabrics = Object.values(this.serverNode.state.commissioning.fabrics);

const connectionInfo: ConnectionInfo[] = activeSessions.map(session => {
const vendorId = session?.fabric?.rootVendorId;
return {
vendorId,
connected: !!session.numberOfActiveSubscriptions,
label: session?.fabric?.label,
};
});

fabrics.forEach(fabric => {
if (!activeSessions.find(session => session.fabric?.fabricId === fabric.fabricId)) {
connectionInfo.push({
vendorId: fabric?.rootVendorId,
connected: false,
label: fabric?.label,
});
}
});
const connectionInfo: ConnectionInfo[] = fabrics.map(fabric => ({
vendorId: fabric?.rootVendorId,
connected: activeSessions
.filter(session => session.fabric?.fabricId === fabric.fabricId)
.some(({ numberOfActiveSubscriptions }) => !!numberOfActiveSubscriptions),
label: fabric?.label,
}));

if (connectionInfo.find(info => info.connected)) {
this.adapter.log.debug(`${this.type} ${this.uuid} is already commissioned and connected with controller`);
Expand Down Expand Up @@ -145,7 +134,7 @@ export abstract class BaseServerNode implements GeneralNode {
}
this.serverNode.events.commissioning.fabricsChanged.on(async fabricIndex => {
this.adapter.log.debug(
`commissioningChangedCallback: Commissioning changed on Fabric ${fabricIndex}: ${JSON.stringify(this.serverNode?.state.operationalCredentials.fabrics.find(fabric => fabric.fabricIndex === fabricIndex))}`,
`commissioningChangedCallback: Commissioning changed on Fabric ${fabricIndex}: ${serialize(this.serverNode?.state.operationalCredentials.fabrics.find(fabric => fabric.fabricIndex === fabricIndex))}`,
);
await this.updateUiState();
});
Expand Down
2 changes: 1 addition & 1 deletion src/matter/to-matter/CtToMatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class CtToMatter extends GenericElectricityDataDeviceToMatter {
}

async registerIoBrokerHandlersAndInitialize(): Promise<void> {
const { min = 2_000, max = 6_500 } = this.#ioBrokerDevice.getTemperatureMinMax() ?? {};
const { min = 2_000, max = 6_536 } = this.#ioBrokerDevice.getTemperatureMinMax() ?? {}; // 153 till 500 mireds

this.#ioBrokerDevice.onChange(async event => {
switch (event.property) {
Expand Down

0 comments on commit 3d98ea3

Please sign in to comment.