Skip to content

Commit

Permalink
Added edit of devices
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Oct 23, 2023
1 parent db82166 commit c052fae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src-admin/src/Tabs/Bridges.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Bridges extends React.Component {
}
}

addDevicesToBridge = (devices, bridgeIndex) => {
addDevicesToBridge = (devices, bridgeIndex, isAutoDetected) => {
const matter = JSON.parse(JSON.stringify(this.props.matter));
const bridge = matter.bridges[bridgeIndex];
devices.forEach(device => {
Expand All @@ -149,7 +149,7 @@ class Bridges extends React.Component {
type: device.deviceType,
enabled: true,
noComposed: true,
auto: bridgeIndex === undefined,
auto: isAutoDetected,
};
if (device.type === 'dimmer') {
obj.hasOnState = device.hasOnState;
Expand Down Expand Up @@ -354,8 +354,10 @@ class Bridges extends React.Component {
editDeviceDialog.deviceType = e.target.value;
this.setState({ editDeviceDialog });
}}
renderValue={value => <span><span>{DEVICE_ICONS[value] || <QuestionMark />}</span>{I18n.t(value)}</span>}
>
{Object.keys(Types).filter(key => SUPPORTED_DEVICES.includes(key)).map(type => <MenuItem key={type} value={type}>
<span>{DEVICE_ICONS[type] || <QuestionMark />}</span>
{I18n.t(type)}
</MenuItem>)}
</Select>
Expand Down Expand Up @@ -602,7 +604,7 @@ class Bridges extends React.Component {
return <DeviceDialog
onClose={() => this.setState({ addDeviceDialog: false })}
{...this.state.addDeviceDialog}
addDevices={devices => this.addDevicesToBridge(devices, this.state.addDeviceDialog.bridgeIndex)}
addDevices={devices => this.addDevicesToBridge(devices, this.state.addDeviceDialog.bridgeIndex, true)}
matter={this.props.matter}
socket={this.props.socket}
themeType={this.props.themeType}
Expand Down Expand Up @@ -642,8 +644,10 @@ class Bridges extends React.Component {
addCustomDeviceDialog.deviceType = e.target.value;
this.setState({ addCustomDeviceDialog });
}}
renderValue={value => <span><span>{DEVICE_ICONS[value] || <QuestionMark />}</span>{I18n.t(value)}</span>}
>
{Object.keys(Types).filter(key => SUPPORTED_DEVICES.includes(key)).map(type => <MenuItem key={type} value={type}>
<span>{DEVICE_ICONS[type] || <QuestionMark />}</span>
{I18n.t(type)}
</MenuItem>)}
</Select>
Expand All @@ -659,7 +663,7 @@ class Bridges extends React.Component {
},
deviceType: this.state.addCustomDeviceDialog.deviceType,
hasOnState: this.state.addCustomDeviceDialog.hasOnState,
}], this.state.addCustomDeviceDialog.bridgeIndex);
}], this.state.addCustomDeviceDialog.bridgeIndex, false);

this.setState({ addCustomDeviceDialog: false });
}}
Expand Down
11 changes: 7 additions & 4 deletions src-admin/src/Tabs/Devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ class Devices extends React.Component {
editDeviceDialog.deviceType = e.target.value;
this.setState({ editDeviceDialog });
}}
renderValue={value => <span><span>{DEVICE_ICONS[value] || <QuestionMark />}</span>{I18n.t(value)}</span>}
>
{Object.keys(Types).filter(key => SUPPORTED_DEVICES.includes(key)).map(type => <MenuItem key={type} value={type}>
<span>{DEVICE_ICONS[type] || <QuestionMark />}</span>
{I18n.t(type)}
</MenuItem>)}
</Select>
Expand Down Expand Up @@ -308,7 +310,7 @@ class Devices extends React.Component {
</Dialog>;
}

addDevices = devices => {
addDevices = (devices, isAutoDetected) => {
const matter = JSON.parse(JSON.stringify(this.props.matter));
devices.forEach(device => {
if (!matter.devices.find(d => d.oid === device)) {
Expand All @@ -318,6 +320,7 @@ class Devices extends React.Component {
oid: device._id,
type: device.deviceType,
hasOnState: device.hasOnState,
auto: isAutoDetected,
productID: device.productID,
vendorID: device.vendorID,
noComposed: true,
Expand Down Expand Up @@ -422,14 +425,14 @@ class Devices extends React.Component {
<DialogActions>
<Button
onClick={() => {
this.addDevicesToBridge([{
this.addDevices([{
_id: this.state.addCustomDeviceDialog.oid,
common: {
name: this.state.addCustomDeviceDialog.name,
},
deviceType: this.state.addCustomDeviceDialog.deviceType,
hasOnState: this.state.addCustomDeviceDialog.hasOnState,
}], this.state.addCustomDeviceDialog.bridgeIndex);
}], this.state.addCustomDeviceDialog.bridgeIndex, false);

this.setState({ addCustomDeviceDialog: false });
}}
Expand Down Expand Up @@ -505,7 +508,7 @@ class Devices extends React.Component {
return <DeviceDialog
onClose={() => this.setState({ addDeviceDialog: false })}
{...(this.state.addDeviceDialog || {})}
addDevices={this.addDevices}
addDevices={devices => this.addDevices(devices, true)}
matter={this.props.matter}
socket={this.props.socket}
themeType={this.props.themeType}
Expand Down

0 comments on commit c052fae

Please sign in to comment.