Skip to content

Commit

Permalink
Added bluetooth to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Nov 24, 2023
1 parent dde71ea commit 8a4b567
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 46 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"type": "git",
"url": "https://github.com/ioBroker/ioBroker.matter"
},
"optionalDependencies": {
"@project-chip/matter-node-ble.js": "0.7.1-alpha.0-20231123-a7b3779"
},
"dependencies": {
"@iobroker/adapter-core": "^3.0.4",
"@project-chip/matter-node.js": "0.7.1-alpha.0-20231123-a7b3779",
Expand Down
71 changes: 70 additions & 1 deletion src-admin/src/Tabs/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
DialogActions, DialogContent, DialogTitle, IconButton,
Switch, Table, TableBody,
TableCell, TableHead, TableRow, TextField,
LinearProgress, Select, MenuItem,
LinearProgress, Select, MenuItem, FormControlLabel, Checkbox,
} from '@mui/material';
import {
Add, Close, KeyboardArrowDown, KeyboardArrowUp,
Expand Down Expand Up @@ -480,6 +480,75 @@ class Controller extends React.Component {
/>
{I18n.t('On')}
</div>
{this.props.matter.controller.enabled ? <div>
<FormControlLabel
control={<Checkbox
checked={!!this.props.matter.controller.ble}
onChange={e => {
const matter = JSON.parse(JSON.stringify(this.props.matter));
matter.controller.ble = e.target.checked;
this.props.updateConfig(matter);
}}
/>}
label={I18n.t('Bluetooth')}
/>
</div> : null}
{this.props.matter.controller.enabled && this.props.matter.controller.ble ? <div>
<TextField
fullWidth
style={{ maxWidth: 600 }}
label={I18n.t('WiFI SSID')}
error={!this.props.matter.controller.wifiSSID}
helperText={this.props.matter.controller.wifiSSID ? '' : I18n.t('Required')}
value={this.props.matter.controller.wifiSSID || ''}
onChange={e => {
const matter = JSON.parse(JSON.stringify(this.props.matter));
matter.controller.wifiSSID = e.target.value;
this.props.updateConfig(matter);
}}
/>
</div> : null}
{this.props.matter.controller.enabled && this.props.matter.controller.ble ? <div>
<TextField
fullWidth
style={{ maxWidth: 600 }}
label={I18n.t('WiFI password')}
error={!this.props.matter.controller.wifiPasword}
helperText={this.props.matter.controller.wifiPasword ? '' : I18n.t('Required')}
value={this.props.matter.controller.wifiPasword || ''}
onChange={e => {
const matter = JSON.parse(JSON.stringify(this.props.matter));
matter.controller.wifiPasword = e.target.value;
this.props.updateConfig(matter);
}}
/>
</div> : null}
{this.props.matter.controller.enabled && this.props.matter.controller.ble ? <div>
<TextField
fullWidth
style={{ maxWidth: 600 }}
label={I18n.t('Thread network name')}
value={this.props.matter.controller.threadNetworkname || ''}
onChange={e => {
const matter = JSON.parse(JSON.stringify(this.props.matter));
matter.controller.threadNetworkname = e.target.value;
this.props.updateConfig(matter);
}}
/>
</div> : null}
{this.props.matter.controller.enabled && this.props.matter.controller.ble ? <div>
<TextField
fullWidth
style={{ maxWidth: 600 }}
label={I18n.t('Thread operational dataset')}
value={this.props.matter.controller.threadOperationalDataSet || ''}
onChange={e => {
const matter = JSON.parse(JSON.stringify(this.props.matter));
matter.controller.threadOperationalDataSet = e.target.value;
this.props.updateConfig(matter);
}}
/>
</div> : null}
{this.props.matter.controller.enabled && this.props.alive ? <div>
<Button
variant="contained"
Expand Down
2 changes: 1 addition & 1 deletion src-admin/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Bridges": "Bridges",
"Cancel": "Abbrechen",
"Collapse all": "Alles einklappen",
"Controller": "Regler",
"Controller": "Controller",
"Delete": "Löschen",
"Delete bridge": "Bridge löschen",
"Delete device": "Gerät löschen",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DeviceFabric.ts → src/lib/DeviceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const types = {
[Types.warning]: Warning,
};

async function DeviceFabric(detectedDevice: DetectedDevice, adapter: ioBroker.Adapter, options: DeviceOptions): Promise<GenericDevice | undefined> {
async function DeviceFactory(detectedDevice: DetectedDevice, adapter: ioBroker.Adapter, options: DeviceOptions): Promise<GenericDevice | undefined> {
// @ts-ignore
const type = types[detectedDevice.type];
if (type) {
Expand All @@ -91,4 +91,4 @@ async function DeviceFabric(detectedDevice: DetectedDevice, adapter: ioBroker.Ad
}
}

export default DeviceFabric;
export default DeviceFactory;
4 changes: 2 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Camera from './devices/Camera';
import Chart from './devices/Chart';
import Cie from './devices/Cie';
import Ct from './devices/Ct';
import DeviceFabric from './DeviceFabric';
import DeviceFactory from './DeviceFactory';
import Dimmer from './devices/Dimmer';
import Door from './devices/Door';
import FireAlarm from './devices/FireAlarm';
Expand Down Expand Up @@ -51,7 +51,7 @@ export {
Chart,
Cie,
Ct,
DeviceFabric,
DeviceFactory,
Dimmer,
Door,
FireAlarm,
Expand Down
40 changes: 20 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Level, Logger } from '@project-chip/matter-node.js/log';
import { CommissionableDevice } from '@project-chip/matter-node.js/common';

import { StorageIoBroker } from './matter/StorageIoBroker';
import { DeviceFabric, SubscribeManager } from './lib';
import { DeviceFactory, SubscribeManager } from './lib';
import { DetectedDevice, DeviceOptions } from './lib/devices/GenericDevice';
import BridgedDevice, { NodeStateResponse } from './matter/BridgedDevicesNode';
import MatterDevice from './matter/DeviceNode';
Expand Down Expand Up @@ -384,27 +384,27 @@ export class MatterAdapter extends utils.Adapter {
parts.pop();
const channelId= parts.join('.');
obj = await this.getForeignObjectAsync(channelId);
if (obj && obj.type === 'device') {
return channelId;
}
if (obj && obj.type === 'channel') {
parts.pop();
const deviceId = parts.join('.');
obj = await this.getForeignObjectAsync(deviceId);
if (obj && obj.type === 'device') {
return deviceId;
}

if (obj && (obj.type === 'device' || obj.type === 'channel')) {
return channelId;
}
// if (obj && obj.type === 'channel') {
// parts.pop();
// const deviceId = parts.join('.');
// obj = await this.getForeignObjectAsync(deviceId);
// if (obj && obj.type === 'device') {
// return deviceId;
// }
//
// return channelId;
// }
return id;
} else if (obj && obj.type === 'channel') {
// we can go maximal two levels up: channel => device
parts.pop();
obj = await this.getForeignObjectAsync(parts.join('.'));
if (obj && obj.type === 'device') {
return parts.join('.');
}
// // we can go maximal two levels up: channel => device
// parts.pop();
// obj = await this.getForeignObjectAsync(parts.join('.'));
// if (obj && obj.type === 'device') {
// return parts.join('.');
// }

return id;
}
Expand Down Expand Up @@ -550,7 +550,7 @@ export class MatterAdapter extends utils.Adapter {
};
}
if (detectedDevice) {
const deviceObject = await DeviceFabric(detectedDevice, this, device as DeviceOptions);
const deviceObject = await DeviceFactory(detectedDevice, this, device as DeviceOptions);
if (deviceObject) {
if (devices.length >= 5) {
if (!(await this.checkLicense())) {
Expand Down Expand Up @@ -612,7 +612,7 @@ export class MatterAdapter extends utils.Adapter {
};
}
if (detectedDevice) {
const deviceObject = await DeviceFabric(detectedDevice, this, options as DeviceOptions);
const deviceObject = await DeviceFactory(detectedDevice, this, options as DeviceOptions);
if (deviceObject) {
device = deviceObject;
}
Expand Down
40 changes: 20 additions & 20 deletions src/matter/ControllerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export interface ControllerCreateOptions {
export interface ControllerOptions {
ble?: boolean;
uuid: string;
wifiSSID?: string;
wifiPasword?: string;
threadNetworkname?: string;
threadOperationalDataSet?: string;
}

interface AddDeviceResult {
Expand Down Expand Up @@ -556,26 +560,22 @@ class Controller {
regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,
regulatoryCountryCode: 'XX',
};
// if (hasParameter("ble")) {
// const wifiSsid = getParameter("ble-wifi-ssid");
// const wifiCredentials = getParameter("ble-wifi-credentials");
// const threadNetworkName = getParameter("ble-thread-networkname");
// const threadOperationalDataset = getParameter("ble-thread-operationaldataset");
// if (wifiSsid !== undefined && wifiCredentials !== undefined) {
// this.adapter.log.debug(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);
// commissioningOptions.wifiNetwork = {
// wifiSsid: wifiSsid,
// wifiCredentials: wifiCredentials,
// };
// }
// if (threadNetworkName !== undefined && threadOperationalDataset !== undefined) {
// this.adapter.log.debug(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);
// commissioningOptions.threadNetwork = {
// networkName: threadNetworkName,
// operationalDataset: threadOperationalDataset,
// };
// }
// }
if (this.parameters.ble) {
if (this.parameters.wifiSSID && this.parameters.wifiPasword) {
this.adapter.log.debug(`Registering Commissioning over BLE with WiFi: ${this.parameters.wifiSSID}`);
commissioningOptions.wifiNetwork = {
wifiSsid: this.parameters.wifiSSID,
wifiCredentials: this.parameters.wifiPasword,
};
}
if (this.parameters.threadNetworkname !== undefined && this.parameters.threadOperationalDataSet !== undefined) {
this.adapter.log.debug(`Registering Commissioning over BLE with Thread: ${this.parameters.threadNetworkname}`);
commissioningOptions.threadNetwork = {
networkName: this.parameters.threadNetworkname,
operationalDataset: this.parameters.threadOperationalDataSet,
};
}
}

let passcode: number | undefined;
let shortDiscriminator: number | undefined;
Expand Down

0 comments on commit 8a4b567

Please sign in to comment.