Skip to content

Commit

Permalink
Implemented stop discovering
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Nov 30, 2023
1 parent f36d6c9 commit 8fdc98d
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- discriminator editable ?
- ble
- fake delete (so the real deletion will be done in backend with factory reset of device)
- Check bridge in controller

## Changelog
### **WORK IN PROGRESS**
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@
"url": "https://github.com/ioBroker/ioBroker.matter"
},
"optionalDependencies": {
"@project-chip/matter-node-ble.js": "0.7.1-alpha.0-20231123-a7b3779"
"@project-chip/matter-node-ble.js": "0.7.2-alpha.0-20231128-db9207d2"
},
"dependencies": {
"@iobroker/adapter-core": "^3.0.4",
"@project-chip/matter-node.js": "0.7.1-alpha.0-20231123-a7b3779",
"@project-chip/matter-node.js": "0.7.2-alpha.0-20231128-db9207d2",
"@iobroker/type-detector": "^3.0.5",
"axios": "^1.6.2",
"jsonwebtoken": "^9.0.2"
},
"devDependencies": {
"@alcalzone/release-script": "^3.6.0",
"@alcalzone/release-script-plugin-iobroker": "^3.6.0",
"@alcalzone/release-script-plugin-license": "^3.5.9",
"@alcalzone/release-script": "^3.7.0",
"@alcalzone/release-script-plugin-iobroker": "^3.7.0",
"@alcalzone/release-script-plugin-license": "^3.7.0",
"@iobroker/legacy-testing": "^1.0.3",
"@types/iobroker": "^5.0.6",
"@types/jsonwebtoken": "^9.0.5",
"@types/node": "^20.9.4",
"@types/node": "^20.10.1",
"colorette": "^2.0.20",
"puppeteer": "^21.5.2",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"chai": "^4.3.10",
"eslint": "^8.54.0",
"eslint-config-standard-with-typescript": "^40.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"private": true,
"dependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@iobroker/adapter-react-v5": "^4.7.3",
"@iobroker/adapter-react-v5": "^4.7.6",
"@iobroker/type-detector": "^3.0.5",
"@mui/icons-material": "^5.14.18",
"@sentry/browser": "^7.81.1",
"@sentry/integrations": "^7.81.1",
"@mui/icons-material": "^5.14.19",
"@sentry/browser": "^7.84.0",
"@sentry/integrations": "^7.84.0",
"babel-eslint": "^10.1.0",
"eslint": "^8.54.0",
"@mui/material": "5.14.14",
Expand Down
2 changes: 1 addition & 1 deletion src-admin/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class App extends GenericApp {
bridges: {},
devices: {},
};
this.state.detectedDevices = {};
this.state.detectedDevices = null;

this.configHandler = null;
this.intervalSubscribe = null;
Expand Down
6 changes: 3 additions & 3 deletions src-admin/src/Tabs/Bridges.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ export class Bridges extends BridgesAndDevices {
if (this.state.addDeviceDialog.noAutoDetect) {
this.bridgeIndex = this.state.addDeviceDialog.bridgeIndex;
return <SelectID
imagePrefix="../.."
dialogName="matter"
themeType={this.props.themeType}
socket={this.props.socket}
Expand Down Expand Up @@ -991,6 +990,7 @@ export class Bridges extends BridgesAndDevices {
{this.renderResetDialog()}
<Tooltip title={I18n.t('Add bridge')} classes={{ popper: this.props.classes.tooltip }}>
<Fab
size="small"
onClick={async () => {
const isLicenseOk = await this.props.checkLicenseOnAdd('addBridge');
if (!isLicenseOk) {
Expand All @@ -1017,8 +1017,8 @@ export class Bridges extends BridgesAndDevices {
}}
style={{
position: 'absolute',
right: 20,
bottom: 84,
right: 15,
bottom: 74,
}}
>
<Add />
Expand Down
25 changes: 21 additions & 4 deletions src-admin/src/Tabs/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TabletAndroid as DeviceIcon,
CompareArrows as ReadWriteStateIcon,
ArrowRightAlt as WriteOnlyStateIcon,
KeyboardBackspace as ReadOnlyStateIcon,
KeyboardBackspace as ReadOnlyStateIcon, SearchOff,
} from '@mui/icons-material';

import { I18n } from '@iobroker/adapter-react-v5';
Expand Down Expand Up @@ -172,6 +172,15 @@ class Controller extends React.Component {
};

onStateChange = (id, state) => {
if (id === `matter.${this.props.instance}.controller.info.discovering`) {
if (state?.val) {
this.setState({ discoveryRunning: true });
} else {
this.setState({ discoveryRunning: false });
}
return;
}

if (!this.state.states) {
return;
}
Expand Down Expand Up @@ -362,6 +371,15 @@ class Controller extends React.Component {
</Table>
</DialogContent>
<DialogActions>
<Button
disabled={!this.state.discoveryRunning}
variant="contained"
onClick={() => this.props.socket.sendTo(`matter.${this.props.instance}`, 'controllerDiscoveryStop', { })
.then(() => this.setState({ discoveryDone: false }))}
startIcon={<SearchOff />}
>
{I18n.t('Stop')}
</Button>
<Button
disabled={this.state.discoveryRunning}
variant="contained"
Expand Down Expand Up @@ -569,14 +587,13 @@ class Controller extends React.Component {
disabled={this.state.discoveryRunning}
startIcon={this.state.discoveryRunning ? <CircularProgress size={20} /> : <Search />}
onClick={() => {
this.setState({ discoveryRunning: true, discovered: [] }, () =>
this.setState({ discovered: [] }, () =>
this.props.socket.sendTo(`matter.${this.props.instance}`, 'controllerDiscovery', { })
.then(result => {
if (result.error) {
this.setState({ discoveryRunning: false });
window.alert(`Cannot discover: ${result.error}`);
} else {
this.setState({ discovered: result.result, discoveryDone: true, discoveryRunning: false });
this.setState({ discovered: result.result, discoveryDone: true });
}
}));
}}
Expand Down
11 changes: 6 additions & 5 deletions src-admin/src/Tabs/Devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ class Devices extends BridgesAndDevices {

if (this.state.addDeviceDialog.noAutoDetect) {
return <SelectID
imagePrefix="../.."
dialogName="matter"
themeType={this.props.themeType}
socket={this.props.socket}
Expand Down Expand Up @@ -705,6 +704,7 @@ class Devices extends BridgesAndDevices {
{this.renderResetDialog()}
<Tooltip title={I18n.t('Add device with auto-detection')} classes={{ popper: this.props.classes.tooltip }}>
<Fab
size="small"
onClick={() => this.setState({
addDeviceDialog: {
devices: this.props.matter.devices,
Expand All @@ -713,15 +713,16 @@ class Devices extends BridgesAndDevices {
})}
style={{
position: 'absolute',
right: 84,
bottom: 84,
right: 64,
bottom: 74,
}}
>
<Add />
</Fab>
</Tooltip>
<Tooltip title={I18n.t('Add device from one state')} classes={{ popper: this.props.classes.tooltip }}>
<Fab
size="small"
onClick={() => this.setState({
addDeviceDialog: {
devices: this.props.matter.devices,
Expand All @@ -731,8 +732,8 @@ class Devices extends BridgesAndDevices {
style={{
opacity: 0.6,
position: 'absolute',
right: 20,
bottom: 84,
right: 15,
bottom: 74,
}}
>
<Add />
Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ export class MatterAdapter extends utils.Adapter {
} else {
obj.callback && this.sendTo(obj.from, obj.command, { error: 'Controller not exist' }, obj.callback);
}
} else if (obj.command === 'controllerDiscoveryStop') {
if (this.controller) {
if (this.controller.isDiscovering()) {
await this.controller.discoveryStop();
obj.callback && this.sendTo(obj.from, obj.command, { result: 'ok' }, obj.callback);
} else {
obj.callback && this.sendTo(obj.from, obj.command, { error: 'Controller not discovering' }, obj.callback);
}
} else {
obj.callback && this.sendTo(obj.from, obj.command, { error: 'Controller not exist' }, obj.callback);
}
} else if (obj.command === 'controllerAddDevice') {
if (this.controller) {
const options: CommissioningOptions = obj.message as CommissioningOptions;
Expand Down
Loading

0 comments on commit 8fdc98d

Please sign in to comment.