Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z-Wave Improvements #615

Merged
merged 10 commits into from
Dec 3, 2019
18 changes: 11 additions & 7 deletions front/src/actions/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ const actions = store => ({
});
},
async getIntegrationByName(state, name, podId = null) {
const query = {
pod_id: podId
};
const currentIntegration = await state.httpClient.get(`/api/v1/service/${name}`, query);
store.setState({
currentIntegration
});
try {
const query = {
pod_id: podId
};
const currentIntegration = await state.httpClient.get(`/api/v1/service/${name}`, query);
store.setState({
currentIntegration
});
} catch (e) {
console.log(e);
}
},
getIntegrationByCategory(state, category) {
const userLanguage = getLanguage(state);
Expand Down
2 changes: 2 additions & 0 deletions front/src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import ZwaveNetworkPage from '../routes/integration/all/zwave/network-page';
import ZwaveSettingsPage from '../routes/integration/all/zwave/settings-page';
import ZwaveSetupPage from '../routes/integration/all/zwave/setup-page';
import ZwaveNodeOperationPage from '../routes/integration/all/zwave/node-operation-page';
import ZwaveEditPage from '../routes/integration/all/zwave/edit-page';
import RtspCameraPage from '../routes/integration/all/rtsp-camera';
import XiaomiPage from '../routes/integration/all/xiaomi';
import EditXiaomiPage from '../routes/integration/all/xiaomi/edit-page';
Expand Down Expand Up @@ -160,6 +161,7 @@ const AppRouter = connect(
<ZwaveSettingsPage path="/dashboard/integration/device/zwave/settings" />
<ZwaveSetupPage path="/dashboard/integration/device/zwave/setup" />
<ZwaveNodeOperationPage path="/dashboard/integration/device/zwave/node-operation" />
<ZwaveEditPage path="/dashboard/integration/device/zwave/edit/:deviceSelector" />
<RtspCameraPage path="/dashboard/integration/device/rtsp-camera" />
<MqttDevicePage path="/dashboard/integration/device/mqtt" />
<MqttDeviceSetupPage path="/dashboard/integration/device/mqtt/edit" />
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/boxs/device-in-room/DeviceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DeviceRow = ({ children, ...props }) => {

// if device is a sensor, we display the sensor deviceFeature
if (props.deviceFeature.read_only) {
return <SensorDeviceFeature deviceFeature={props.deviceFeature} />;
return <SensorDeviceFeature user={props.user} deviceFeature={props.deviceFeature} />;
}

// else, it's not a sensor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const RoomCard = ({ children, ...props }) => {
props.devices.map((device, deviceIndex) =>
device.features.map((deviceFeature, deviceFeatureIndex) => (
<DeviceRow
user={props.user}
x={props.x}
y={props.y}
device={device}
Expand All @@ -74,7 +75,7 @@ const RoomCard = ({ children, ...props }) => {
);
};

@connect('session,DashboardBoxDataDevicesInRoom,DashboardBoxStatusDevicesInRoom', actions)
@connect('session,user,DashboardBoxDataDevicesInRoom,DashboardBoxStatusDevicesInRoom', actions)
class DevicesInRoomComponent extends Component {
updateDeviceStateWebsocket = payload => this.props.deviceFeatureWebsocketEvent(this.props.x, this.props.y, payload);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import { Text } from 'preact-i18n';
import { DEVICE_FEATURE_UNITS } from '../../../../../../server/utils/constants';
const OPEN_CLOSE_SENSORS = ['door-opening-sensor', 'window-opening-sensor'];
import get from 'get-value';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';

dayjs.extend(relativeTime);

import { DEVICE_FEATURE_UNITS, DEVICE_FEATURE_CATEGORIES } from '../../../../../../server/utils/constants';

const SPECIAL_SENSORS = [DEVICE_FEATURE_CATEGORIES.OPENING_SENSOR, DEVICE_FEATURE_CATEGORIES.MOTION_SENSOR];

import { DeviceFeatureCategoriesIcon } from '../../../../utils/consts';

const SensorDeviceType = ({ children, ...props }) => (
<tr>
<td>
{props.deviceFeature.category === 'temperature-sensor' && <i class="fe fe-thermometer" />}
{props.deviceFeature.category === 'humidity-sensor' && <i class="fe fe-droplet" />}
{props.deviceFeature.category === 'light-sensor' && <i class="fe fe-sun" />}
{props.deviceFeature.category === 'battery-sensor' && <i class="fe fe-percent" />}
{props.deviceFeature.category === 'switch' && props.deviceFeature.type === 'power' && <i class="fe fe-zap" />}
{OPEN_CLOSE_SENSORS.indexOf(props.deviceFeature.category) !== -1 && <i class="fe fe-home" />}
{props.deviceFeature.category === null && <i class="fe fe-bar-chart-2" />}
<i
class={`mr-2 fe fe-${get(
DeviceFeatureCategoriesIcon,
`${props.deviceFeature.category}.${props.deviceFeature.type}`
)}`}
/>
</td>
{props.deviceFeature.name && <td>{props.deviceFeature.name}</td>}
{!props.deviceFeature.name && props.deviceFeature.type === 'binary' && <td>{props.deviceFeature.name}</td>}
{!props.deviceFeature.name && props.deviceFeature.type !== 'binary' && (
<td>
{props.deviceFeature.name} - {props.deviceFeature.type}
</td>
)}
{OPEN_CLOSE_SENSORS.indexOf(props.deviceFeature.category) === -1 && (
<td>{props.deviceFeature.name}</td>
{SPECIAL_SENSORS.indexOf(props.deviceFeature.category) === -1 && (
<td class="text-right">
{props.deviceFeature.last_value !== null && props.deviceFeature.last_value}
{props.deviceFeature.last_value === null && <Text id="dashboard.boxes.devicesInRoom.noValue" />}
{props.deviceFeature.category === 'temperature-sensor' && props.deviceFeature.last_value !== null && (
<span>{props.deviceFeature.unit === 'celsius' ? '°C' : '°F'}</span>
)}
{props.deviceFeature.category !== 'temperature-sensor' && props.deviceFeature.last_value !== null && (
{props.deviceFeature.last_value !== null && (
<span>
{' '}
{props.deviceFeature.unit === DEVICE_FEATURE_UNITS.PERCENT && '%'}
{props.deviceFeature.unit === DEVICE_FEATURE_UNITS.CELSIUS && '°C'}
{props.deviceFeature.unit === DEVICE_FEATURE_UNITS.FAHRENHEIT && '°F'}
{props.deviceFeature.unit === DEVICE_FEATURE_UNITS.KILOWATT && 'kW'}
{props.deviceFeature.unit === DEVICE_FEATURE_UNITS.KILOWATT_HOUR && 'kW/h'}
{props.deviceFeature.unit === DEVICE_FEATURE_UNITS.LUX && 'Lx'}
Expand All @@ -38,12 +40,19 @@ const SensorDeviceType = ({ children, ...props }) => (
)}
</td>
)}
{OPEN_CLOSE_SENSORS.indexOf(props.deviceFeature.category) !== -1 && (
{props.deviceFeature.category === DEVICE_FEATURE_CATEGORIES.OPENING_SENSOR && (
<td class="text-right">
{props.deviceFeature.last_value === 1 && <i class="fe fe-shield" />}
{props.deviceFeature.last_value === 0 && <i class="fe fe-shield-off" />}
</td>
)}
{props.deviceFeature.category === DEVICE_FEATURE_CATEGORIES.MOTION_SENSOR && (
<td class="text-right">
{dayjs(props.deviceFeature.last_value_changed)
.locale(props.user.language)
.fromNow()}
</td>
)}
</tr>
);

Expand Down
114 changes: 74 additions & 40 deletions front/src/config/demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
"name": "Temperature",
"selector": "temperature-living-room-celsius",
"category": "temperature-sensor",
"type": "",
"type": "decimal",
"unit": "celsius",
"min": -200,
"max": 200,
Expand All @@ -269,7 +269,7 @@
"name": "Temperature",
"selector": "temperature-living-room-celsius",
"category": "temperature-sensor",
"type": "",
"type": "decimal",
"unit": "celsius",
"min": -200,
"max": 200,
Expand All @@ -281,8 +281,8 @@
"name": "Humidity",
"selector": "temperature-living-room-celsius",
"category": "humidity-sensor",
"type": "",
"unit": "%",
"type": "decimal",
"unit": "percent",
"min": -200,
"max": 200,
"read_only": true,
Expand All @@ -292,9 +292,9 @@
{
"name": "Kitchen door",
"selector": "temperature-living-room-celsius",
"category": "door-opening-sensor",
"type": "",
"unit": "%",
"category": "opening-sensor",
"type": "binary",
"unit": null,
"min": -200,
"max": 200,
"read_only": true,
Expand Down Expand Up @@ -513,38 +513,18 @@
},
"get /api/v1/service/zwave/node": [
{
"id": "1",
"manufacturer": "Z-Wave.Me",
"manufacturerid": "0x0115",
"product": "ZME_UZB1 USB Stick",
"producttype": "0x0400",
"productid": "0x0001",
"type": "Static PC Controller",
"name": "",
"loc": "",
"classes": {
"32": {
"0": {
"value_id": "1-32-1-0",
"node_id": 1,
"class_id": 32,
"type": "byte",
"genre": "basic",
"instance": 1,
"index": 0,
"label": "Basic",
"units": "",
"help": "",
"read_only": false,
"write_only": false,
"min": 0,
"max": 255,
"is_polled": false,
"value": 0
}
}
},
"ready": true
"name": "ZME_UZB1 USB Stick",
"features": [],
"params": [],
"rawZwaveNode": {
"id": 1,
"manufacturer": "Z-Wave.Me",
"manufacturerid": "0x0115",
"product": "ZME_UZB1 USB Stick",
"producttype": "0x0400",
"productid": "0x0001",
"type": "Static PC Controller"
}
}
],
"get /api/v1/service/zwave/neighbor": [
Expand Down Expand Up @@ -644,7 +624,7 @@
"service_id": "a810b8db-6d04-4697-bed3-c4b72c996279",
"room_id": "cecc52c7-3e67-4b75-9b13-9a8867b0443d",
"name": "Fibaro Motion Sensor",
"selector": "test-sensor",
"selector": "zwave:1234",
"external_id": "test-sensor-external",
"should_poll": false,
"poll_frequency": null,
Expand Down Expand Up @@ -975,6 +955,60 @@
"name": "Xiaomi",
"selector": "xiaomi"
},
"get /api/v1/device/zwave:1234": {
"id": "fbedb47f-4d25-4381-8923-2633b23192a0",
"service_id": "a810b8db-6d04-4697-bed3-c4b72c996279",
"room_id": "cecc52c7-3e67-4b75-9b13-9a8867b0443d",
"name": "Fibaro Motion Sensor",
"selector": "zwave:1234",
"external_id": "test-sensor-external",
"should_poll": false,
"poll_frequency": null,
"created_at": "2019-02-12T07:49:07.556Z",
"updated_at": "2019-02-12T07:49:07.556Z",
"features": [
{
"name": "Temperature",
"external_id": "zwave:1234:temperature",
"selector": "test-temperature",
"category": "temperature-sensor",
"unit": "celsius",
"type": "decimal"
},
{
"name": "Motion",
"selector": "test-motion",
"external_id": "zwave:1234:temperature",
"category": "motion-sensor",
"type": "binary"
},
{
"name": "Battery",
"selector": "test-battery",
"external_id": "zwave:1234:temperature",
"category": "battery",
"type": "integer",
"last_value": "92"
},
{
"name": "Lux",
"selector": "test-light",
"external_id": "zwave:1234:temperature",
"category": "light-sensor",
"type": "integer"
}
],
"room": {
"id": "cecc52c7-3e67-4b75-9b13-9a8867b0443d",
"name": "Living Room",
"selector": "living-room"
}
},
"get /api/v1/service/zwave": {
"id": "a810b8db-6d04-4697-bed3-c4b72c996279",
"name": "Zwave",
"selector": "zwave"
},
"get /api/v1/device/xiaomi:1234": {
"id": "e5317b24-28e1-4839-9879-0bb7a3102e98",
"name": "Xiaomi Temperature",
Expand Down
8 changes: 6 additions & 2 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@
"featuresLabel": "Features",
"noFeatures": "No features",
"saveButton": "Save",
"deleteButton": "Delete"
"deleteButton": "Delete",
"editButton": "Edit"
},
"setup": {
"title": "Z-Wave Devices",
Expand All @@ -296,6 +297,7 @@
"features": "Features",
"params": "Params",
"noFeatures": "No features",
"nodeId": "Node",
"zwaveNotConfiguredError": "Z-wave is not configured. Please select the USB port where you Z-Wave key is plugged in settings.",
"createDeviceError": "There was an error while creating this device in Gladys.",
"deviceCreatedSuccess": "The device was added with success."
Expand All @@ -321,7 +323,9 @@
"addNodeTitle": "Inclusion Mode",
"removeNodeTitle": "Exclusion Mode",
"seconds": "seconds remaining",
"cancelButton": "Cancel"
"cancelButton": "Cancel",
"nodeAddedTitle": "A new node was found",
"nodeAddedDescription": "Wait a few seconds while we get all informations from this node..."
}
},
"darkSky": {
Expand Down
20 changes: 20 additions & 0 deletions front/src/routes/integration/all/zwave/edit-page/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component } from 'preact';
import { connect } from 'unistore/preact';
// import actions from '../actions';
import ZwavePage from '../ZwavePage';
import UpdateDevice from '../../../../../components/device';

const ZWAVE_PAGE_PATH = '/dashboard/integration/device/zwave';

@connect('user,session,httpClient,currentIntegration,houses', {})
class EditZwaveDevice extends Component {
render(props, {}) {
return (
<ZwavePage>
<UpdateDevice {...props} integrationName="zwave" allowModifyFeatures={false} previousPage={ZWAVE_PAGE_PATH} />
</ZwavePage>
);
}
}

export default EditZwaveDevice;
Loading