Skip to content

Commit

Permalink
Added noComposed flag to bridge devices and to simple devices
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Oct 20, 2023
1 parent 391216e commit fc2a0be
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 21 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->
## ToDo
- License
- Dimmer
- Disallow composed
- Button to TOTAL reset
- Controller
- Devices
- Encode vendor IDs

## Changelog
### **WORK IN PROGRESS**
Expand Down
37 changes: 28 additions & 9 deletions src-admin/src/components/Bridges.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Bridges extends React.Component {
oid: device._id,
type: device.deviceType,
enabled: true,
noComposed: true,
});
}
});
Expand All @@ -126,15 +127,13 @@ class Bridges extends React.Component {
enabled: true,
productID: this.state.editDialog.productID,
vendorID: this.state.editDialog.vendorID,
noComposed: this.state.editDialog.noComposed,
list: [],
uuid: uuidv4(),
});
} else if (this.state.editDialog.type === 'bridge') {
matter.bridges[this.state.editDialog.bridge].name = this.state.editDialog.name;
matter.bridges[this.state.editDialog.bridge].productID = this.state.editDialog.productID;
matter.bridges[this.state.editDialog.bridge].vendorID = this.state.editDialog.vendorID;
matter.bridges[this.state.editDialog.bridge].noComposed = this.state.editDialog.noComposed;
} else if (this.state.editDialog.bridge !== undefined) {
matter.bridges[this.state.editDialog.bridge].list[this.state.editDialog.device].name = this.state.editDialog.name;
}
Expand All @@ -145,13 +144,15 @@ class Bridges extends React.Component {
const isDisabled =
this.state.editDialog.name === this.state.editDialog.originalName &&
this.state.editDialog.vendorID === this.state.editDialog.originalVendorID &&
this.state.editDialog.productID === this.state.editDialog.originalProductID;
this.state.editDialog.productID === this.state.editDialog.originalProductID &&
this.state.editDialog.noComposed === this.state.editDialog.originalNoComposed;

return <Dialog onClose={() => this.setState({ editDialog: false })} open={!0}>
<DialogTitle>
{this.state.editDialog?.add ?
I18n.t('Add bridge') :
`${I18n.t('Edit bridge')} ${this.state.editDialog?.originalName}`}
{this.state.editDialog.type === 'device' ? `${I18n.t('Edit bridge')} "${this.state.editDialog?.originalName}"` :
(this.state.editDialog.add ?
I18n.t('Add bridge') :
`${I18n.t('Edit bridge')} "${this.state.editDialog?.originalName}"`)}
</DialogTitle>
<DialogContent>
<TextField
Expand Down Expand Up @@ -208,6 +209,18 @@ class Bridges extends React.Component {
{productID}
</MenuItem>)}
</TextField> : null}
{this.state.editDialog.type === 'device' ? <FormControlLabel
variant="standard"
control={<Checkbox
checked={this.state.editDialog.noComposed}
onChange={e => {
const editDialog = JSON.parse(JSON.stringify(this.state.editDialog));
editDialog.noComposed = e.target.checked;
this.setState({ editDialog });
}}
/>}
label={<span style={{ fontSize: 'smaller' }}>{I18n.t('Do not compose devices (Alexa does not support composed devices yet)')}</span>}
/> : null}
</DialogContent>
<DialogActions>
<Button
Expand Down Expand Up @@ -303,14 +316,14 @@ class Bridges extends React.Component {
</Dialog>;
}

renderDevicesDialog() {
renderDeviceDialog() {
if (!this.state.dialog) {
return null;
}

return <DeviceDialog
onClose={() => this.setState({ dialog: false })}
{...(this.state.dialog || {})}
{...this.state.dialog}
matter={this.props.matter}
socket={this.props.socket}
themeType={this.props.themeType}
Expand Down Expand Up @@ -361,6 +374,8 @@ class Bridges extends React.Component {
device: devIndex,
vendorID: false,
productID: false,
noComposed: !!device.noComposed,
originalNoComposed: !!device.noComposed,
originalVendorID: false,
originalProductID: false,
},
Expand Down Expand Up @@ -508,6 +523,8 @@ class Bridges extends React.Component {
countText = `(${bridge.list.length})`;
}

const allowDisable = this.props.bri;

return <React.Fragment key={bridgeIndex}>
<TableRow
sx={theme => (
Expand Down Expand Up @@ -595,6 +612,8 @@ class Bridges extends React.Component {
originalVendorID: bridge.vendorID,
productID: bridge.productID,
originalProductID: bridge.productID,
noComposed: false,
originalNoComposed: false,
},
},
);
Expand Down Expand Up @@ -654,7 +673,7 @@ class Bridges extends React.Component {

render() {
return <div>
{this.renderDevicesDialog()}
{this.renderDeviceDialog()}
{this.renderDeleteDialog()}
{this.renderEditDialog()}
{this.renderQrCodeDialog()}
Expand Down
4 changes: 4 additions & 0 deletions src-admin/src/components/ConfigHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class ConfigHandler {
changed = true;
device.enabled = obj.native.enabled;
}
if (device.noComposed !== obj.native.noComposed) {
changed = true;
device.noComposed = obj.native.noComposed;
}
if (device.name !== obj.common.name) {
changed = true;
device.name = obj.common.name;
Expand Down
21 changes: 18 additions & 3 deletions src-admin/src/components/Devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ class Devices extends React.Component {
matter.devices[this.state.editDialog.device].name = this.state.editDialog.name;
matter.devices[this.state.editDialog.device].productID = this.state.editDialog.productID;
matter.devices[this.state.editDialog.device].vendorID = this.state.editDialog.vendorID;
matter.devices[this.state.editDialog.device].noComposed = this.state.editDialog.noComposed;
this.setState({ editDialog: false }, () => this.props.updateConfig(matter));
};

const isDisabled =
this.state.editDialog?.name === this.state.editDialog?.originalName &&
this.state.editDialog?.vendorID === this.state.editDialog?.originalVendorID &&
this.state.editDialog?.productID === this.state.editDialog?.originalProductID;
this.state.editDialog?.productID === this.state.editDialog?.originalProductID &&
this.state.editDialog?.noComposed === this.state.editDialog?.originalNoComposed;

return <Dialog onClose={() => this.setState({ editDialog: false })} open={!0}>
<DialogTitle>
Expand Down Expand Up @@ -163,7 +165,6 @@ class Devices extends React.Component {
this.setState({ editDialog });
}}
label={I18n.t('Vendor ID')}
helperText={<span style={{ display: 'block', height: 20 }} />}
variant="standard"
>
{['0xFFF1', '0xFFF2', '0xFFF3', '0xFFF4'].map(vendorID =>
Expand All @@ -184,7 +185,6 @@ class Devices extends React.Component {
this.setState({ editDialog });
}}
label={I18n.t('Product ID')}
helperText={<span style={{ display: 'block', height: 20 }} />}
variant="standard"
>
{this.props.productIDs.map(productID =>
Expand All @@ -195,6 +195,18 @@ class Devices extends React.Component {
{productID}
</MenuItem>)}
</TextField>
<FormControlLabel
variant="standard"
control={<Checkbox
checked={this.state.editDialog.noComposed}
onChange={e => {
const editDialog = JSON.parse(JSON.stringify(this.state.editDialog));
editDialog.noComposed = e.target.checked;
this.setState({ editDialog });
}}
/>}
label={<span style={{ fontSize: 'smaller' }}>{I18n.t('Do not compose devices (Alexa does not support composed devices yet)')}</span>}
/>
</DialogContent>
<DialogActions>
<Button
Expand Down Expand Up @@ -229,6 +241,7 @@ class Devices extends React.Component {
type: device.deviceType,
productID: device.productID,
vendorID: device.vendorID,
noComposed: true,
enabled: true,
});
}
Expand Down Expand Up @@ -339,6 +352,8 @@ class Devices extends React.Component {
productID: device.productID,
originalVendorID: device.vendorID,
originalProductID: device.productID,
originalNoComposed: !!device.noComposed,
noComposed: !!device.noComposed,
},
},
);
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ export class MatterAdapter extends utils.Adapter {
}
}

if (!_bridges.length) {
// create one bridge, that is enabled
}


// Create new bridges
for (const b in _bridges) {
const bridge = _bridges[b];
Expand Down
30 changes: 21 additions & 9 deletions src/matter/BridgedDevicesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum BridgeStates {
Creating = 'creating',
Listening = 'listening',
Commissioned = 'commissioned',
ConnectedWithController = 'connected',
}


Expand Down Expand Up @@ -155,7 +156,7 @@ class BridgedDevice {
this.sendToGui({
uuid: this.parameters.uuid,
command: 'status',
data: 'creating',
status: 'creating',
});
return BridgeStates.Creating;
}
Expand Down Expand Up @@ -203,14 +204,25 @@ class BridgedDevice {
}
});

this.sendToGui({
uuid: this.parameters.uuid,
command: 'status',
data: 'connecting',
connectionInfo,
});
console.log('Device is already commissioned. Waiting for controllers to connect ...');
return BridgeStates.Commissioned;
if (connectionInfo.find((info: any) => info.connected)) {
this.sendToGui({
uuid: this.parameters.uuid,
command: 'status',
status: 'connected',
connectionInfo,
});
console.log('Device is already commissioned and connected with controller');
return BridgeStates.ConnectedWithController;
} else {
this.sendToGui({
uuid: this.parameters.uuid,
command: 'status',
status: 'connecting',
connectionInfo,
});
console.log('Device is already commissioned. Waiting for controllers to connect ...');
return BridgeStates.Commissioned;
}
}
}

Expand Down

0 comments on commit fc2a0be

Please sign in to comment.