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

Sonoff service (over MQTT) #519

Merged
merged 34 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
28e57ac
MQTT: sonoff (front/back) + owntracks
atrovato Aug 8, 2019
2d81371
MQTT: device creation by subService
atrovato Aug 9, 2019
713efcf
sonoff : scan for devices
atrovato Aug 13, 2019
4182d2e
Sonoff: restructure MQTT service
atrovato Aug 13, 2019
0bebd13
Sonoff: try to fix import
atrovato Aug 14, 2019
63dcdef
Sonoff: improve model name
atrovato Aug 14, 2019
5eaa51f
Sonoff: complete demo mode
atrovato Aug 14, 2019
8ddb795
Sonoff service: Fix typo
atrovato Sep 24, 2019
81aa635
Sonoff service: refactor models
atrovato Sep 24, 2019
8d26171
Run prettier :/
atrovato Sep 24, 2019
1fc2acd
Sonoff service: fix front impacts
atrovato Sep 24, 2019
bf70ddb
Sonoff service: fix model name
atrovato Sep 25, 2019
964a507
Sonoff: limit integration description
atrovato Oct 9, 2019
59ab4a8
Sonoff: improve discover UX messages
atrovato Oct 9, 2019
cb9faa5
Sonoff: improve devices UX
atrovato Oct 9, 2019
b85b237
MQTT service status
atrovato Oct 9, 2019
b89c04d
Sonoff: use device.model iso params
atrovato Oct 9, 2019
ce13009
Sonoff: use device.model iso params
atrovato Oct 9, 2019
e15180d
MQTT: fix status UX behavior
atrovato Oct 9, 2019
e4a3603
Sonoff: improve error message
atrovato Oct 9, 2019
6c1ed7a
Sonoff: topic help
atrovato Oct 9, 2019
ac38e41
Sonoff: pushing to re-run circleCI
atrovato Oct 9, 2019
01a80bb
Sonoff: update demo.json according to changes
atrovato Oct 12, 2019
76ffc80
Mqtt/Sonoff: changing service client for device
atrovato Oct 14, 2019
f9d0813
Sonoff: add ability to change value
atrovato Oct 14, 2019
3973c1d
Sonoff: force 'sonoff:' topic prefix
atrovato Oct 15, 2019
702e10e
Sonoff: improve manual/auto device creation
atrovato Oct 15, 2019
ceee298
Sonoff: documentation link
atrovato Oct 15, 2019
4bd53e3
Sonoff: fix selector + clean
atrovato Oct 18, 2019
e2e3542
Sonoff: forgot to adapt tests
atrovato Oct 19, 2019
df02177
Sonoff: test coverage
atrovato Oct 19, 2019
96a520a
Sonoff: documentation link
atrovato Oct 21, 2019
27e4651
Sonoff: fix typos
atrovato Oct 24, 2019
a3fc2dd
Merge branch 'master' into sonoff-mqtt-service
Pierre-Gilles Oct 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Sonoff: use device.model iso params
  • Loading branch information
atrovato committed Oct 22, 2019
commit ce13009e953fe21990f938f20304af846aa3e066
6 changes: 3 additions & 3 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@
"topicPlaceholder": "%topic% Sonoff MQTT value",
"modelLabel": "Sonoff Model",
"model": {
"basic": "Basic",
"pow": "Pow",
"s26": "S20/S26 Smart Plug"
"sonoff-basic": "Basic",
"sonoff-pow": "Pow",
"sonoff-s2x": "S20/S26 Smart Plug"
},
"saveButton": "Save",
"alreadyCreatedButton": "Already created",
Expand Down
12 changes: 0 additions & 12 deletions front/src/routes/integration/all/sonoff/device-page/SonoffBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,8 @@ class SonoffBox extends Component {

updateModel = e => {
const selectedModel = e.target.value;
const params = (this.props.device.params || []).slice();
const model = params.find(p => p.name === 'model');

if (model) {
model.value = selectedModel;
} else {
params.push({
name: 'model',
value: selectedModel
});
}

this.props.updateDeviceField(this.props.deviceIndex, 'model', selectedModel);
this.props.updateDeviceField(this.props.deviceIndex, 'params', params);
this.props.updateDeviceField(
this.props.deviceIndex,
'features',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ function createActions(store) {
}

const sonoffsReceived = await state.httpClient.get('/api/v1/service/sonoff/device', options);
sonoffsReceived.forEach(device => {
const model = device.params.find(p => p.name === 'model');
if (model) {
device.model = model.value;
}
});

let sonoffDevices;
if (skip === 0) {
sonoffDevices = sonoffsReceived;
Expand Down
11 changes: 6 additions & 5 deletions front/src/routes/integration/all/sonoff/device-page/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import uuid from 'uuid';
import models from '../../../../../../../server/services/sonoff/models';

export const Models = {
basic: 1,
pow: 6,
s26: 8
'sonoff-basic': 1,
'sonoff-pow': 6,
'sonoff-s2x': 8
};

export const GetFeatures = (modelName, deviceName, deviceTopic) => {
if (models[modelName]) {
return models[modelName].getFeatures(uuid, deviceName, deviceTopic);
const modelKey = Models[modelName];
if (modelKey && models[modelKey]) {
return models[modelKey].getFeatures(uuid, deviceName, deviceTopic);
}

return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ function createActions(store) {
});
try {
const discoveredDevices = await state.httpClient.get('/api/v1/service/sonoff/discover');
discoveredDevices.forEach(device => {
const model = device.params.find(p => p.name === 'model');
if (model) {
device.model = model.value;
}
});

store.setState({
discoveredDevices,
loading: false,
Expand Down
2 changes: 1 addition & 1 deletion server/services/sonoff/lib/handleMqttMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function handleMqttMessage(topic, message) {
name: friendlyName,
external_id: `sonoff:${deviceExternalId}`,
features: model.getFeatures(uuid, friendlyName, deviceExternalId),
params: model.getParams(),
model: model.getModel(),
service_id: this.serviceId,
should_poll: false,
id: uuid.v4(),
Expand Down
4 changes: 2 additions & 2 deletions server/services/sonoff/models/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const basic = require('./switch_basic');
const s26 = require('./plug_s26');
const s2x = require('./plug_s2x');
const pow = require('./switch_pow');

module.exports = {
1: basic,
6: pow,
8: s26,
8: s2x,
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../utils/constants');

const getParams = () => {
return [
{
name: 'model',
value: 's26',
},
];
const getModel = () => {
return 'sonoff-s2x';
};

const getFeatures = (uuid, deviceName, deviceTopic) => {
Expand All @@ -27,5 +22,5 @@ const getFeatures = (uuid, deviceName, deviceTopic) => {

module.exports = {
getFeatures,
getParams,
getModel,
};
11 changes: 3 additions & 8 deletions server/services/sonoff/models/switch_basic.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../utils/constants');

const getParams = () => {
return [
{
name: 'model',
value: 'basic',
},
];
const getModel = () => {
return 'sonoff-basic';
};

const getFeatures = (uuid, deviceName, deviceTopic) => {
Expand All @@ -27,5 +22,5 @@ const getFeatures = (uuid, deviceName, deviceTopic) => {

module.exports = {
getFeatures,
getParams,
getModel,
};
12 changes: 4 additions & 8 deletions server/services/sonoff/models/switch_pow.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../utils/constants');

const getParams = () => {
return [
{
name: 'model',
value: 'pow',
},
];
const getModel = () => {
return 'sonoff-pow';
};

const getFeatures = (uuid, deviceName, deviceTopic) => {
Expand All @@ -30,6 +25,7 @@ const getFeatures = (uuid, deviceName, deviceTopic) => {
has_feedback: false,
min: 0,
max: 10000,
unit: 'A',
name: `${deviceName} - ${DEVICE_FEATURE_TYPES.SWITCH.POWER}`,
external_id: `sonoff:${deviceTopic}:${DEVICE_FEATURE_TYPES.SWITCH.POWER}`,
},
Expand All @@ -38,5 +34,5 @@ const getFeatures = (uuid, deviceName, deviceTopic) => {

module.exports = {
getFeatures,
getParams,
getModel,
};
12 changes: 3 additions & 9 deletions server/test/services/sonoff/models/plug_s26.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../..
const modelId = 8;

describe('SonoffService - Model - Plug S2x', () => {
it('get params for Sonoff Plug S2x', () => {
const params = models[modelId].getParams();
it('get model for Sonoff Plug S2x', () => {
const model = models[modelId].getModel();

expect(params).to.be.lengthOf(1);
expect(params).deep.eq([
{
name: 'model',
value: 's26',
},
]);
expect(model).to.eq('sonoff-s2x');
});

it('get features for Sonoff Plug S2x', () => {
Expand Down
12 changes: 3 additions & 9 deletions server/test/services/sonoff/models/switch_basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../..
const modelId = 1;

describe('SonoffService - Model - Basic', () => {
it('get params for Sonoff Basic', () => {
const params = models[modelId].getParams();
it('get model for Sonoff Basic', () => {
const model = models[modelId].getModel();

expect(params).to.be.lengthOf(1);
expect(params).deep.eq([
{
name: 'model',
value: 'basic',
},
]);
expect(model).to.eq('sonoff-basic');
});

it('get features for Sonoff Basic', () => {
Expand Down
14 changes: 4 additions & 10 deletions server/test/services/sonoff/models/switch_pow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ const { DEVICE_FEATURE_CATEGORIES, DEVICE_FEATURE_TYPES } = require('../../../..
const modelId = 6;

describe('SonoffService - Model - Pow', () => {
it('get params for Sonoff Pow', () => {
const params = models[modelId].getParams();

expect(params).to.be.lengthOf(1);
expect(params).deep.eq([
{
name: 'model',
value: 'pow',
},
]);
it('get model for Sonoff Pow', () => {
const model = models[modelId].getModel();

expect(model).to.eq('sonoff-pow');
});

it('get features for Sonoff Pow', () => {
Expand Down