Prettier reformat
This commit is contained in:
parent
3e53f11da0
commit
e5bf0dbd83
6 changed files with 1366 additions and 1435 deletions
|
@ -77,10 +77,16 @@ export class MyHeader extends React.Component {
|
|||
<Button basic inverted onClick={this.logout}>
|
||||
Logout
|
||||
</Button>
|
||||
<Segment compact style={{margin: "auto", marginTop: "1em", textAlign: "center"}}>
|
||||
<Segment
|
||||
compact
|
||||
style={{
|
||||
margin: "auto",
|
||||
marginTop: "1em",
|
||||
textAlign: "center",
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
label={<label
|
||||
>Share cameras</label>}
|
||||
label={<label>Share cameras</label>}
|
||||
checked={this.props.cameraEnabled}
|
||||
toggle
|
||||
onChange={(e, val) => this.setCameraEnabled(val.checked)}
|
||||
|
@ -108,10 +114,16 @@ export class MyHeader extends React.Component {
|
|||
</Label>
|
||||
<Divider />
|
||||
<Button onClick={this.logout}>Logout</Button>
|
||||
<Segment compact style={{margin: "auto", marginTop: "1em", textAlign: "center"}}>
|
||||
<Segment
|
||||
compact
|
||||
style={{
|
||||
margin: "auto",
|
||||
marginTop: "1em",
|
||||
textAlign: "center",
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
label={<label
|
||||
>Share cameras</label>}
|
||||
label={<label>Share cameras</label>}
|
||||
checked={this.props.cameraEnabled}
|
||||
toggle
|
||||
onChange={(e, val) => this.setCameraEnabled(val.checked)}
|
||||
|
|
|
@ -99,9 +99,7 @@ const CreateTrigger = (props) => {
|
|||
<React.Fragment>
|
||||
<Form.Field inline width={2}>
|
||||
<Dropdown
|
||||
onChange={(e, val) =>
|
||||
props.inputChange(val)
|
||||
}
|
||||
onChange={(e, val) => props.inputChange(val)}
|
||||
ref={operandsRef}
|
||||
name="operand"
|
||||
compact
|
||||
|
@ -124,9 +122,7 @@ const CreateTrigger = (props) => {
|
|||
) : (
|
||||
<Form.Field inline width={7}>
|
||||
<Dropdown
|
||||
onChange={(e, val) =>
|
||||
props.inputChange(val)
|
||||
}
|
||||
onChange={(e, val) => props.inputChange(val)}
|
||||
placeholder="State"
|
||||
name="on"
|
||||
compact
|
||||
|
@ -153,10 +149,7 @@ const SceneItem = (props) => {
|
|||
<Checkbox
|
||||
toggle
|
||||
onChange={(e, val) =>
|
||||
props.orderScenes(
|
||||
props.scene.id,
|
||||
val.checked
|
||||
)
|
||||
props.orderScenes(props.scene.id, val.checked)
|
||||
}
|
||||
checked={position + 1 > 0}
|
||||
/>
|
||||
|
@ -165,9 +158,7 @@ const SceneItem = (props) => {
|
|||
<h3>{props.scene.name}</h3>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={4}>
|
||||
<h3>
|
||||
{position !== -1 ? "# " + (position + 1) : ""}
|
||||
</h3>
|
||||
<h3>{position !== -1 ? "# " + (position + 1) : ""}</h3>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
@ -187,9 +178,7 @@ const Trigger = ({ deviceName, trigger, onRemove, index }) => {
|
|||
<Menu compact>
|
||||
<Menu.Item as="span">{deviceName}</Menu.Item>
|
||||
{operand ? <Menu.Item as="span">{symbol}</Menu.Item> : ""}
|
||||
<Menu.Item as="span">
|
||||
{operand ? value : on ? "on" : "off"}
|
||||
</Menu.Item>
|
||||
<Menu.Item as="span">{operand ? value : on ? "on" : "off"}</Menu.Item>
|
||||
</Menu>
|
||||
<Icon
|
||||
as={"i"}
|
||||
|
@ -217,8 +206,7 @@ class AutomationSaveModal extends Component {
|
|||
if (this.props.automation) {
|
||||
this.state.automationName = this.props.automation.name;
|
||||
for (const scenePriority of this.props.automation.scenes) {
|
||||
this.state.order[scenePriority.priority] =
|
||||
scenePriority.sceneId;
|
||||
this.state.order[scenePriority.priority] = scenePriority.sceneId;
|
||||
}
|
||||
for (const trigger of this.props.automation.triggers) {
|
||||
this.state.triggerList.push(
|
||||
|
@ -296,19 +284,11 @@ class AutomationSaveModal extends Component {
|
|||
return error;
|
||||
}
|
||||
let deviceKind = device.kind;
|
||||
const devicesWithPercentage = [
|
||||
"dimmableLight",
|
||||
"curtains",
|
||||
"knobDimmer",
|
||||
];
|
||||
const devicesWithPercentage = ["dimmableLight", "curtains", "knobDimmer"];
|
||||
|
||||
switch (triggerKind) {
|
||||
case "booleanTrigger":
|
||||
if (
|
||||
!trigger.device ||
|
||||
trigger.on === null ||
|
||||
trigger.on === undefined
|
||||
)
|
||||
if (!trigger.device || trigger.on === null || trigger.on === undefined)
|
||||
return error;
|
||||
break;
|
||||
case "rangeTrigger":
|
||||
|
@ -324,16 +304,14 @@ class AutomationSaveModal extends Component {
|
|||
devicesWithPercentage.includes(deviceKind) &&
|
||||
trigger.value > 100
|
||||
) {
|
||||
error.message =
|
||||
"The value can't exceed 100, as it's a percentage";
|
||||
error.message = "The value can't exceed 100, as it's a percentage";
|
||||
return error;
|
||||
} else if (
|
||||
deviceKind === "sensor" &&
|
||||
device.sensor === "HUMIDITY" &&
|
||||
trigger.value > 100
|
||||
) {
|
||||
error.message =
|
||||
"The value can't exceed 100, as it's a percentage";
|
||||
error.message = "The value can't exceed 100, as it's a percentage";
|
||||
return error;
|
||||
}
|
||||
break;
|
||||
|
@ -354,9 +332,7 @@ class AutomationSaveModal extends Component {
|
|||
}
|
||||
|
||||
addTrigger() {
|
||||
const { result, message } = this._checkNewTrigger(
|
||||
this.state.newTrigger
|
||||
);
|
||||
const { result, message } = this._checkNewTrigger(this.state.newTrigger);
|
||||
|
||||
if (result) {
|
||||
this.setState(
|
||||
|
@ -508,12 +484,7 @@ class AutomationSaveModal extends Component {
|
|||
onClick={this.openModal}
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
icon
|
||||
labelPosition="left"
|
||||
color="green"
|
||||
onClick={this.openModal}
|
||||
>
|
||||
<Button icon labelPosition="left" color="green" onClick={this.openModal}>
|
||||
<Icon name="add"></Icon>Create new automation
|
||||
</Button>
|
||||
);
|
||||
|
@ -557,32 +528,21 @@ class AutomationSaveModal extends Component {
|
|||
<Header>Create Triggers</Header>
|
||||
<List divided relaxed>
|
||||
{this.state.triggerList.length > 0 &&
|
||||
this.state.triggerList.map(
|
||||
(trigger, i) => {
|
||||
this.state.triggerList.map((trigger, i) => {
|
||||
const deviceName = this.deviceList.filter(
|
||||
(d) =>
|
||||
d.id ===
|
||||
trigger.device
|
||||
(d) => d.id === trigger.device
|
||||
)[0].name;
|
||||
const key = this._generateKey(
|
||||
trigger
|
||||
);
|
||||
const key = this._generateKey(trigger);
|
||||
return (
|
||||
<Trigger
|
||||
key={key}
|
||||
index={i}
|
||||
deviceName={
|
||||
deviceName
|
||||
}
|
||||
deviceName={deviceName}
|
||||
trigger={trigger}
|
||||
onRemove={
|
||||
this
|
||||
.removeTrigger
|
||||
}
|
||||
onRemove={this.removeTrigger}
|
||||
/>
|
||||
);
|
||||
}
|
||||
)}
|
||||
})}
|
||||
<CreateTrigger
|
||||
devices={this.props.devices}
|
||||
inputChange={this.onInputChange}
|
||||
|
@ -613,9 +573,7 @@ class AutomationSaveModal extends Component {
|
|||
key={scene.id}
|
||||
scene={scene}
|
||||
order={this.state.order}
|
||||
orderScenes={
|
||||
this.orderScenes
|
||||
}
|
||||
orderScenes={this.orderScenes}
|
||||
/>
|
||||
))}
|
||||
</List>
|
||||
|
@ -625,9 +583,7 @@ class AutomationSaveModal extends Component {
|
|||
<Header icon>
|
||||
<Icon name="world" />
|
||||
</Header>
|
||||
<Button primary>
|
||||
Create Scene
|
||||
</Button>
|
||||
<Button primary>Create Scene</Button>
|
||||
</React.Fragment>
|
||||
)}
|
||||
</Grid.Column>
|
||||
|
@ -637,10 +593,7 @@ class AutomationSaveModal extends Component {
|
|||
<Grid>
|
||||
<Grid.Row>
|
||||
<Grid.Column style={{ marginRight: "1rem" }}>
|
||||
<Button
|
||||
onClick={() => this.saveAutomation()}
|
||||
color="green"
|
||||
>
|
||||
<Button onClick={() => this.saveAutomation()} color="green">
|
||||
{this.props.id ? "Save" : "Create"}
|
||||
</Button>
|
||||
</Grid.Column>
|
||||
|
|
|
@ -51,9 +51,7 @@ const Automation = ({ automation, devices, scenes, removeAutomation }) => {
|
|||
<Menu.Item as="span">
|
||||
{device.name}{" "}
|
||||
{trigger.operator
|
||||
? getOperator(
|
||||
trigger.operator
|
||||
) +
|
||||
? getOperator(trigger.operator) +
|
||||
" " +
|
||||
trigger.range
|
||||
: trigger.on
|
||||
|
@ -76,9 +74,7 @@ const Automation = ({ automation, devices, scenes, removeAutomation }) => {
|
|||
if (!sceneData) return "";
|
||||
return (
|
||||
<Menu key={sceneData.id} compact>
|
||||
<Menu.Item as="span">
|
||||
{sceneData.name}
|
||||
</Menu.Item>
|
||||
<Menu.Item as="span">{sceneData.name}</Menu.Item>
|
||||
</Menu>
|
||||
);
|
||||
})}
|
||||
|
@ -119,9 +115,7 @@ class AutomationsPanel extends Component {
|
|||
removeAutomation = (id) => {
|
||||
this.props
|
||||
.deleteAutomation(id)
|
||||
.catch((err) =>
|
||||
console.error(`error removing automation ${id}:`, err)
|
||||
);
|
||||
.catch((err) => console.error(`error removing automation ${id}:`, err));
|
||||
};
|
||||
|
||||
render() {
|
||||
|
@ -141,11 +135,7 @@ class AutomationsPanel extends Component {
|
|||
<Grid.Row>
|
||||
{this.props.automations.map((automation, i) => {
|
||||
return (
|
||||
<Grid.Column
|
||||
key={i}
|
||||
width={8}
|
||||
style={{ margin: "2rem 0" }}
|
||||
>
|
||||
<Grid.Column key={i} width={8} style={{ margin: "2rem 0" }}>
|
||||
<Automation
|
||||
removeAutomation={this.removeAutomation}
|
||||
scenes={this.props.scenes}
|
||||
|
|
|
@ -57,13 +57,6 @@ class Sensor extends Component {
|
|||
this.name = "Sensor";
|
||||
}
|
||||
|
||||
// setName = () => {
|
||||
// if (this.props.device.name.length > 15) {
|
||||
// return this.props.device.name.slice(0, 12) + "...";
|
||||
// }
|
||||
// return this.props.device.name;
|
||||
// };
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (
|
||||
this.props.stateOrDevice.kind === "sensor" &&
|
||||
|
|
|
@ -248,8 +248,7 @@ function reducer(previousState, action) {
|
|||
change.scenes[sceneState.sceneId] || {};
|
||||
change.scenes[sceneState.sceneId].sceneStates =
|
||||
change.scenes[sceneState.sceneId].sceneStates || {};
|
||||
const sceneStates =
|
||||
change.scenes[sceneState.sceneId].sceneStates;
|
||||
const sceneStates = change.scenes[sceneState.sceneId].sceneStates;
|
||||
sceneStates.$add = sceneStates.$add || [];
|
||||
sceneStates.$add.push(sceneState.id);
|
||||
} else {
|
||||
|
@ -340,8 +339,7 @@ function reducer(previousState, action) {
|
|||
}
|
||||
|
||||
if (device.roomId in newState.rooms) {
|
||||
change.rooms[device.roomId] =
|
||||
change.rooms[device.roomId] || {};
|
||||
change.rooms[device.roomId] = change.rooms[device.roomId] || {};
|
||||
change.rooms[device.roomId].devices =
|
||||
change.rooms[device.roomId].devices || {};
|
||||
const devices = change.rooms[device.roomId].devices;
|
||||
|
@ -356,9 +354,7 @@ function reducer(previousState, action) {
|
|||
$set: new Set([device.id]),
|
||||
};
|
||||
} else {
|
||||
change.pendingJoins.rooms[device.roomId].$set.add(
|
||||
device.id
|
||||
);
|
||||
change.pendingJoins.rooms[device.roomId].$set.add(device.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -522,9 +518,7 @@ function reducer(previousState, action) {
|
|||
break;
|
||||
case "SCENE_DELETE":
|
||||
if (!(action.sceneId in previousState.scenes)) {
|
||||
console.warn(
|
||||
`Scene to delete ${action.sceneId} does not exist`
|
||||
);
|
||||
console.warn(`Scene to delete ${action.sceneId} does not exist`);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -547,9 +541,7 @@ function reducer(previousState, action) {
|
|||
break;
|
||||
case "STATE_DELETE":
|
||||
if (!(action.stateId in previousState.sceneStates)) {
|
||||
console.warn(
|
||||
`State to delete ${action.stateId} does not exist`
|
||||
);
|
||||
console.warn(`State to delete ${action.stateId} does not exist`);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -558,9 +550,7 @@ function reducer(previousState, action) {
|
|||
};
|
||||
|
||||
if (
|
||||
previousState.scenes[
|
||||
previousState.sceneStates[action.stateId].sceneId
|
||||
]
|
||||
previousState.scenes[previousState.sceneStates[action.stateId].sceneId]
|
||||
) {
|
||||
change.scenes = {
|
||||
[previousState.sceneStates[action.stateId].sceneId]: {
|
||||
|
@ -574,9 +564,7 @@ function reducer(previousState, action) {
|
|||
|
||||
case "DEVICE_DELETE":
|
||||
if (!(action.deviceId in previousState.devices)) {
|
||||
console.warn(
|
||||
`Device to delete ${action.deviceId} does not exist`
|
||||
);
|
||||
console.warn(`Device to delete ${action.deviceId} does not exist`);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -584,11 +572,7 @@ function reducer(previousState, action) {
|
|||
devices: { $unset: [action.deviceId] },
|
||||
};
|
||||
|
||||
if (
|
||||
previousState.rooms[
|
||||
previousState.devices[action.deviceId].roomId
|
||||
]
|
||||
) {
|
||||
if (previousState.rooms[previousState.devices[action.deviceId].roomId]) {
|
||||
change.rooms = {
|
||||
[previousState.devices[action.deviceId].roomId]: {
|
||||
devices: { $remove: [action.deviceId] },
|
||||
|
@ -614,8 +598,7 @@ function reducer(previousState, action) {
|
|||
const allDevices = JSON.parse(action.payload.message);
|
||||
const devices = allDevices.filter(
|
||||
(d) =>
|
||||
(d.fromHostId === null || d.fromHostId === undefined) &&
|
||||
!d.deleted
|
||||
(d.fromHostId === null || d.fromHostId === undefined) && !d.deleted
|
||||
);
|
||||
const hostDevicesMapByHostId = allDevices
|
||||
.filter((d) => d.fromHostId)
|
||||
|
|
Loading…
Reference in a new issue