Skip to content

Commit

Permalink
Implemented button sensor capability component.
Browse files Browse the repository at this point in the history
  • Loading branch information
kallaspriit committed Aug 17, 2016
1 parent e2c1a86 commit b5666d2
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.button-sensor-capability-component {
.button-status-wrap {
padding: 20px 0;
margin: -15px;
text-align: center;

&.is-button-active {
background-color: #DFD;
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"html-webpack-plugin": "^2.22.0",
"js-schema": "^1.0.1",
"keymirror": "^0.1.1",
"material-ui": "^0.15.3",
"material-ui": "^0.15.4",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"react": "^15.3.0",
Expand Down Expand Up @@ -66,7 +66,7 @@
"cross-env": "^2.0.0",
"css-loader": "^0.23.1",
"enzyme": "^2.4.1",
"eslint": "^3.2.2",
"eslint": "^3.3.1",
"eslint-config-sl": "^1.5.0",
"expect": "^1.20.2",
"import-glob-loader": "^1.1.0",
Expand Down
2 changes: 2 additions & 0 deletions src/AbstractPlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ export default class AbstractPlatform {
LIGHT: null,
MOTION: null,
POSITION: null,
BUTTON: null,
});

static MeasurementType = keyMirror({
UNSUPPORTED: null,
LIGHT: null,
MOTION: null,
RELAY: null,
BUTTON: null,
});

constructor() {
Expand Down
2 changes: 2 additions & 0 deletions src/CumulocityPlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export default class CumulocityPlatform extends AbstractPlatform {
c8y_MotionSensor: AbstractPlatform.CapabilityType.MOTION,
c8y_Hardware: AbstractPlatform.CapabilityType.HARDWARE,
c8y_Position: AbstractPlatform.CapabilityType.POSITION,
com_stagnationlab_c8y_driver_sensors_AbstractButtonSensor_ButtonSensor: AbstractPlatform.CapabilityType.BUTTON,
};

static measurementTypeMapping = {
c8y_LightMeasurement: AbstractPlatform.MeasurementType.LIGHT,
com_stagnationlab_c8y_driver_measurements_MotionStateMeasurement: AbstractPlatform.MeasurementType.MOTION,
com_stagnationlab_c8y_driver_measurements_RelayStateMeasurement: AbstractPlatform.MeasurementType.RELAY,
com_stagnationlab_c8y_driver_measurements_ButtonStateMeasurement: AbstractPlatform.MeasurementType.BUTTON,
};

constructor({
Expand Down
66 changes: 66 additions & 0 deletions views/components/capabilities/ButtonSensorCapabilityComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import classNames from 'classnames';

import CircularProgress from 'material-ui/CircularProgress';

import AbstractPlatform from '../../../src/AbstractPlatform';

class ButtonSensorCapabilityComponent extends Component {

static propTypes = {
capability: PropTypes.object.isRequired,
deviceInfo: PropTypes.object.isRequired,
measurements: PropTypes.array.isRequired,
};

static getType() {
return AbstractPlatform.CapabilityType.BUTTON;
}

render() {
return (
<div className="capability-component button-sensor-capability-component">
{this.renderContents()}
</div>
);
}

renderContents() {
const {
measurements,
} = this.props;

const measurement = measurements.find(
(item) => item.type === AbstractPlatform.MeasurementType.BUTTON
) || null;

if (!measurement) {
return (
<div className="loader-wrap">
<CircularProgress />
</div>
);
}

const isButtonActive = measurement.info.state.value === 1;

const className = classNames(
'button-status-wrap', {
'is-button-active': isButtonActive,
}
);

return (
<div className={className}>
{isButtonActive ? 'Button pressed' : 'Button released'}
</div>
);
}
}

export default connect(
state => ({
}), {
}
)(ButtonSensorCapabilityComponent);
8 changes: 4 additions & 4 deletions views/components/capabilities/HardwareCapabilityComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ class HardwareCapabilityComponent extends Component {
render() {
return (
<div className="capability-component hardware-capability-component">
{this.renderContents()}
{this.renderInfoList()}
</div>
);
}

renderContents() {
renderInfoList() {
return (
<ul className="info-list">
{Object.keys(this.props.capability.info).map(
(key) => this.renderHardwareListItem(key, this.props.capability.info[key])
(key) => this.renderInfoListItem(key, this.props.capability.info[key])
)}
</ul>
);
}

renderHardwareListItem(key, value) {
renderInfoListItem(key, value) {
return (
<li key={key}>
<strong>{changeCase.sentenceCase(key)}:</strong> {value}
Expand Down
1 change: 1 addition & 0 deletions views/components/capabilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export LightSensorCapabilityComponent from './LightSensorCapabilityComponent';
export MotionSensorCapabilityComponent from './MotionSensorCapabilityComponent';
export RelayActuatorCapabilityComponent from './RelayActuatorCapabilityComponent';
export PositionSensorCapabilityComponent from './PositionSensorCapabilityComponent';
export ButtonSensorCapabilityComponent from './ButtonSensorCapabilityComponent';

0 comments on commit b5666d2

Please sign in to comment.