Skip to content

Commit

Permalink
Start working on Matter Socket
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Oct 19, 2023
1 parent aea4e73 commit 22d9107
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
48 changes: 44 additions & 4 deletions src-admin/src/components/Bridges.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@mui/material';
import {
Add,
Close,
Close, ConnectWithoutContact,
ContentCopy,
Delete,
Edit,
Expand All @@ -28,7 +28,7 @@ import {
UnfoldMore,
} from '@mui/icons-material';

import {I18n, Utils} from '@iobroker/adapter-react-v5';
import { I18n, Utils } from '@iobroker/adapter-react-v5';

import DeviceDialog, { DEVICE_ICONS } from '../DeviceDialog';
import { getText } from '../Utils';
Expand Down Expand Up @@ -74,7 +74,7 @@ const styles = () => ({
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
}
},
});

class Bridges extends React.Component {
Expand Down Expand Up @@ -440,12 +440,40 @@ class Bridges extends React.Component {
</Dialog>;
}

renderDebugDialog() {
if (!this.state.showDebugData) {
return null;
}
return <Dialog
onClose={() => this.setState({ showDebugData: null })}
open={!0}
maxWidth="md"
>
<DialogTitle>{I18n.t('QR Code to connect ')}</DialogTitle>
<DialogContent>
<pre style={{ width: '100%' }}>
{JSON.stringify(this.props.nodeStates[this.state.showDebugData.uuid], null, 2)}
</pre>
</DialogContent>
<DialogActions>
<Button
onClick={() => this.setState({ showDebugData: null })}
startIcon={<Close />}
color="grey"
variant="contained"
>
{I18n.t('Close')}
</Button>
</DialogActions>
</Dialog>;
}

renderStatus(bridge) {
if (!this.props.nodeStates[bridge.uuid]) {
return null;
}
if (this.props.nodeStates[bridge.uuid].command === 'showQRCode') {
return <Tooltip title={I18n.t('Show QR Code')}>
return <Tooltip title={I18n.t('Bridge is not commissioned. Show QR Code got commissioning')}>
<IconButton
style={{ height: 40 }}
onClick={() => this.setState({ showQrCode: bridge })}
Expand All @@ -454,6 +482,17 @@ class Bridges extends React.Component {
</IconButton>
</Tooltip>;
}
if (this.props.nodeStates[bridge.uuid].command === 'status' && this.props.nodeStates[bridge.uuid].data === 'connecting') {
return <Tooltip title={I18n.t('Device is already commissioning. Show status information')}>
<IconButton
style={{ height: 40 }}
onClick={() => this.setState({ showDebugData: bridge })}
>
<ConnectWithoutContact />
</IconButton>
</Tooltip>;
}
return null;
}

renderBridge(bridge, bridgeIndex) {
Expand Down Expand Up @@ -617,6 +656,7 @@ class Bridges extends React.Component {
{this.renderDeleteDialog()}
{this.renderEditDialog()}
{this.renderQrCodeDialog()}
{this.renderDebugDialog()}
<Tooltip title={I18n.t('Add bridge')}>
<Fab
onClick={() => {
Expand Down
9 changes: 7 additions & 2 deletions src/matter/BridgedDevicesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CommissioningServer, MatterServer } from '@project-chip/matter-node.js'

import { VendorId } from '@project-chip/matter-node.js/datatype';
import { Aggregator, DeviceTypes, OnOffPluginUnitDevice } from '@project-chip/matter-node.js/device';
import { QrCode } from '@project-chip/matter-node.js/schema';
import { toJson } from '@project-chip/matter.js/storage';

import { GenericDevice, Socket } from '../lib';

Expand Down Expand Up @@ -175,12 +175,17 @@ class BridgedDevice {
// console.log(`Manual pairing code: ${manualPairingCode}`);
return BridgeStates.Listening;
} else {
const activeSession = this.commissioningServer.getActiveSessionInformation();
const fabric = this.commissioningServer.getCommissionedFabricInformation();

this.sendToGui({
uuid: this.parameters.uuid,
command: 'status',
data: 'connecting',
activeSession: toJson(activeSession),
fabric: toJson(fabric),
});
console.log("Device is already commissioned. Waiting for controllers to connect ...");
console.log('Device is already commissioned. Waiting for controllers to connect ...');
return BridgeStates.Commissioned;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/matter/StorageIoBroker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fromJson, Storage, StorageError, SupportedStorageTypes, toJson } from "@project-chip/matter.js/storage";
import { fromJson, Storage, StorageError, SupportedStorageTypes, toJson } from '@project-chip/matter.js/storage';

export class StorageIoBroker implements Storage {
private readonly adapter: ioBroker.Adapter;
Expand Down

0 comments on commit 22d9107

Please sign in to comment.