diff --git a/smart-hut/src/components/SceneModal.js b/smart-hut/src/components/SceneModal.js index 9183a58..cffa062 100644 --- a/smart-hut/src/components/SceneModal.js +++ b/smart-hut/src/components/SceneModal.js @@ -17,8 +17,6 @@ class SceneModal extends Component { constructor(props) { super(props); this.state = this.initialState; - this.setInitialState(); - this.addSceneModal = this.addSceneModal.bind(this); this.modifySceneModal = this.modifySceneModal.bind(this); this.deleteScene = this.deleteScene.bind(this); diff --git a/smart-hut/src/components/dashboard/AutomationsPanel.js b/smart-hut/src/components/dashboard/AutomationsPanel.js index d3eae66..d4d828e 100644 --- a/smart-hut/src/components/dashboard/AutomationsPanel.js +++ b/smart-hut/src/components/dashboard/AutomationsPanel.js @@ -71,6 +71,7 @@ const Automation = ({ automation, devices, scenes, removeAutomation }) => { const sceneData = scenes.filter( (s) => s.id === sp.sceneId )[0]; + if (!sceneData) return ""; return ( {sceneData.name} diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js index 4dd74e2..15206b8 100644 --- a/smart-hut/src/components/dashboard/DevicePanel.js +++ b/smart-hut/src/components/dashboard/DevicePanel.js @@ -26,7 +26,7 @@ class DevicePanel extends Component { return ( {this.props.devices.map((e, i) => { - return ; + return ; })} {!this.props.isActiveRoomHome ? ( diff --git a/smart-hut/src/components/dashboard/NewSceneDevice.js b/smart-hut/src/components/dashboard/NewSceneDevice.js index 9b76044..d096bd8 100644 --- a/smart-hut/src/components/dashboard/NewSceneDevice.js +++ b/smart-hut/src/components/dashboard/NewSceneDevice.js @@ -63,7 +63,6 @@ class NewSceneDevice extends Component { createState() { for (let i = 0; i < this.state.devicesAttached.length; i++) { - console.log("DIOPORCO", i, this.state.devicesAttached[i]); let device = this.props.devices.filter( (e) => this.state.devicesAttached[i] === e.id ); @@ -98,7 +97,14 @@ class NewSceneDevice extends Component { open={this.state.openModal} onClose={this.resetState} trigger={ - + } diff --git a/smart-hut/src/components/dashboard/ScenesPanel.js b/smart-hut/src/components/dashboard/ScenesPanel.js index d8bcfd5..1950f6b 100644 --- a/smart-hut/src/components/dashboard/ScenesPanel.js +++ b/smart-hut/src/components/dashboard/ScenesPanel.js @@ -3,7 +3,7 @@ import { connect } from "react-redux"; import { RemoteService } from "../../remote"; import Device from "./devices/Device"; import NewSceneDevice from "./NewSceneDevice"; -import { Grid, Button } from "semantic-ui-react"; +import { Grid, Button, Card, Segment, Header } from "semantic-ui-react"; class ScenesPanel extends Component { constructor(props) { @@ -12,39 +12,44 @@ class ScenesPanel extends Component { } applyScene() { - console.log(this.props.activeScene); - this.props.sceneApply(this.props.activeScene).then(() => { - alert("Scene applied."); - }); + this.props + .sceneApply(this.props.activeScene) + .then(() => { + alert("Scene applied."); + }) + .catch(console.error); } render() { return ( - + {!this.props.isActiveDefaultScene ? ( - - - - ) : null} - {!this.props.isActiveDefaultScene - ? this.props.sceneStates.map((e, i) => { - return ( - - - - ); - }) - : null} - {!this.props.isActiveDefaultScene ? ( - - - + + + +
Add devices - Apply Scene
+
+ + + +
+ +
+ +
+
+
) : ( Welcome to the Scene View, you add a Scene )} -
+ {!this.props.isActiveDefaultScene + ? this.props.sceneStates.map((e, i) => { + return ; + }) + : null} +
); } } diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js index 7da9395..6a251b3 100644 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ b/smart-hut/src/components/dashboard/devices/Device.js @@ -41,8 +41,8 @@ class Device extends React.Component { } deleteState() { - //console.log("alpaca "+this.props); - this.props.deleteState(this.props.id, this.props.type); + console.log("alpaca ", this.props); + this.props.deleteState(this.props.id, this.props.stateOrDevice.kind); } renderDeviceComponent() { @@ -136,7 +136,7 @@ class Device extends React.Component { stateDescription() { return ( -
+
); diff --git a/smart-hut/src/components/dashboard/devices/Videocam.js b/smart-hut/src/components/dashboard/devices/Videocam.js index 889233f..c434be0 100644 --- a/smart-hut/src/components/dashboard/devices/Videocam.js +++ b/smart-hut/src/components/dashboard/devices/Videocam.js @@ -59,7 +59,11 @@ class Videocam extends Component { } const mapStateToProps = (state, ownProps) => ({ - device: state.devices[ownProps.id], + device: + ownProps.tab === "Devices" + ? state.devices[ownProps.id] + : state.devices[state.sceneStates[ownProps.id].deviceId], + state: state.sceneStates[ownProps.id], }); const VideocamContainer = connect(mapStateToProps, RemoteService)(Videocam); export default VideocamContainer; diff --git a/smart-hut/src/remote.js b/smart-hut/src/remote.js index 0a37934..66d47bd 100644 --- a/smart-hut/src/remote.js +++ b/smart-hut/src/remote.js @@ -13,7 +13,11 @@ class RemoteError extends Error { messages; constructor(messages) { - super(messages.join(" - ")); + super( + messages && Array.isArray(messages) + ? messages.join(" - ") + : JSON.stringify(messages, null, 2) + ); this.messages = messages; } } diff --git a/smart-hut/src/store.js b/smart-hut/src/store.js index fce1897..350cc7b 100644 --- a/smart-hut/src/store.js +++ b/smart-hut/src/store.js @@ -301,7 +301,6 @@ function reducer(previousState, action) { break; case "AUTOMATION_SAVE": - console.log("ID: ", action.automation.id); change = { automations: { [action.automation.id]: { $set: action.automation } }, }; @@ -316,7 +315,6 @@ function reducer(previousState, action) { }; if (previousState.scenes[action.sceneState.sceneId]) { - console.log("PREVSTATE", change, previousState); change.scenes = { [action.sceneState.sceneId]: { sceneStates: { @@ -334,7 +332,6 @@ function reducer(previousState, action) { }; } newState = update(previousState, change); - console.log("NEWSTATE ", newState); break; case "ROOM_DELETE": if (!(action.roomId in previousState.rooms)) { @@ -365,13 +362,9 @@ function reducer(previousState, action) { automations: { $unset: [action.id] }, }; - console.log("CHANGE ", change); - console.log("Action id: ", action.id); newState = update(previousState, change); - console.log("NEW STATE ", newState); break; case "SCENE_DELETE": - console.log("SCENE", action.sceneId); if (!(action.sceneId in previousState.scenes)) { console.warn(`Scene to delete ${action.sceneId} does not exist`); break; @@ -417,15 +410,6 @@ function reducer(previousState, action) { newState = update(previousState, change); break; - case "SCENE_APPLY": - console.log(action); - //checking that the scene actually exists - /*if (!(action.sceneId in previousState.scenes)) { - console.warn(`Scene ${action.sceneId} does not exist`); - break; - }*/ - - break; case "DEVICE_DELETE": if (!(action.deviceId in previousState.devices)) { console.warn(`Device to delete ${action.deviceId} does not exist`); @@ -487,6 +471,7 @@ function reducer(previousState, action) { break; case "REDUX_WEBSOCKET::MESSAGE": const devices = JSON.parse(action.payload.message); + //console.log("socket", JSON.stringify(devices, null, 2)); newState = reducer(previousState, { type: "DEVICES_UPDATE", diff --git a/smart-hut/src/storeActions.js b/smart-hut/src/storeActions.js index 86ac83e..e8ee30a 100644 --- a/smart-hut/src/storeActions.js +++ b/smart-hut/src/storeActions.js @@ -62,10 +62,6 @@ const actions = { type: "STATE_DELETE", stateId, }), - sceneApply: (sceneId) => ({ - type: "SCENE_APPLY", - sceneId, - }), deviceOperationUpdate: (devices) => ({ type: "DEVICES_UPDATE", devices, diff --git a/smart-hut/src/views/Dashboard.js b/smart-hut/src/views/Dashboard.js index 8ee84c7..bb92ea8 100644 --- a/smart-hut/src/views/Dashboard.js +++ b/smart-hut/src/views/Dashboard.js @@ -89,14 +89,12 @@ class Dashboard extends Component {