Skip to content

Commit

Permalink
Merge pull request #162 from modmax/dev
Browse files Browse the repository at this point in the history
Synchronize states and read values from response  #157
  • Loading branch information
kirovilya authored Jan 23, 2019
2 parents 9696bc8 + 351ede1 commit 66ba6b3
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 102 deletions.
77 changes: 40 additions & 37 deletions lib/devstates.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,12 @@ const states = {
const transitionTime = hasTransitionTime ? options.transition_time : 0;
return transitionTime * 1000;
},
readResponse: (resp) => {
const respObj = resp[0];
if (respObj.status === 0 && respObj.attrData != undefined) {
return Math.round(respObj.attrData * 100 / 254);
}
},
},
colortemp: {
id: 'colortemp',
Expand Down Expand Up @@ -1130,27 +1136,23 @@ const comb = {
};

//return list of states to read after main change has been done
const readAfter = {
const sync = {
brightness: (state, value, options) => {
// if state is brightness
if (state.id === states.brightness.id) {
const hasTransitionTime = options && options.hasOwnProperty('transition_time');
const timeout = (hasTransitionTime ? options.transition_time : 0) * 1000;
if (value > 0) {
if (!options.state) {
// read if light is turned on
// light is turned on
return [{
stateDesc: states.state,
value: true,
timeout: timeout,
}];
}
} else if (options.state) {
// read if light is turned off
// light is turned off
return [{
stateDesc: states.state,
value: false,
timeout: timeout,
}];
}
}
Expand Down Expand Up @@ -1308,7 +1310,7 @@ const devices = [{
models: ['lumi.light.aqcn02'],
icon: 'img/aqara_bulb.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},

// Osram
Expand All @@ -1318,28 +1320,28 @@ const devices = [{
models: ['TRADFRI Driver 10W', 'TRADFRI transformer 10W'],
icon: 'img/lightify-driver.png',
states: lightStates,
linkedStates: [comb.brightnessAndState],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['PAR16 50 TW'],
icon: 'img/lightify-par16.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['PAR 16 50 RGBW - LIGHTIFY'],
icon: 'img/lightify-par16.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['Classic B40 TW - LIGHTIFY'],
icon: 'img/lightify-b40tw.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
Expand All @@ -1352,56 +1354,56 @@ const devices = [{
models: ['Classic A60 RGBW', 'CLA60 RGBW OSRAM'],
icon: 'img/osram_a60_rgbw.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['LIGHTIFY A19 Tunable White', 'Classic A60 TW', 'CLA60 TW OSRAM'],
icon: 'img/osram_lightify.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['Ceiling TW OSRAM'],
icon: 'img/osram_ceiling_tw.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['Flex RGBW', 'LIGHTIFY Indoor Flex RGBW', 'LIGHTIFY Outdoor Flex RGBW'],
icon: 'img/philips_hue_lst002.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['Gardenpole RGBW-Lightify', 'Gardenspot W'],
icon: 'img/philips_hue_lst002.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['Classic A60 W clear - LIGHTIFY'],
icon: 'img/osram_lightify.png',
states: lightStates,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['Surface Light TW'],
icon: 'img/osram_surface_light_tw.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'OSRAM',
models: ['Surface Light W �C LIGHTIFY'],
icon: 'img/osram_surface_light_tw.png',
states: lightStates,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},

// Hue and Philips
Expand All @@ -1410,105 +1412,105 @@ const devices = [{
models: ['LWB010'],
icon: 'img/philips_hue_white.png',
states: lightStates,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LLC010'],
icon: 'img/philips_hue_iris.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LLC012', 'LLC011'],
icon: 'img/hue_go.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LLC020'],
icon: 'img/hue_go.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LST002'],
icon: 'img/philips_hue_lst002.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LWB004'],
icon: 'img/philips_hue_white.png',
states: lightStates,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LWB006'],
icon: 'img/philips_hue_white.png',
states: lightStates,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LCT001', 'LCT007', 'LCT010', 'LCT012', 'LCT014', 'LCT015', 'LCT016'],
icon: 'img/philips_hue_color.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LCT003'],
icon: 'img/philips_hue_gu10_color.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LTC001'],
icon: 'img/philips_white_ambiance_being.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LCT024'],
icon: 'img/philips_hue_lightbar.png',
states: lightStatesWithColor,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LTW001','LTW004'],
icon: 'img/philips_hue_ambiance.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LTW010'],
icon: 'img/philips_hue_ambiance.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LTW012'],
icon: 'img/philips_hue_e14_ambiance.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
models: ['LTW013'],
icon: 'img/philips_hue_gu10_ambiance.png',
states: lightStatesWithColortemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Philips',
Expand All @@ -1521,6 +1523,7 @@ const devices = [{
models: ['SML001'],
icon: 'img/sensor_philipshue.png',
states: [states.battery, states.occupancy, states.occupancy_pirOToUDelay, states.temperature, states.illuminance],
readAfterWriteStates: [states.occupancy_pirOToUDelay],
},


Expand Down Expand Up @@ -1784,14 +1787,14 @@ const devices = [{
models: ['Dimmablelight '],
icon: 'img/dimmablelight.png',
states: lightStates,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
{
vendor: 'Paulmann',
models: ['RGBW light '],
icon: 'img/paulmann_rgbw_controller.png',
states: lightStatesWithColorNoTemp,
readAfterStates: [readAfter.brightness],
syncStates: [sync.brightness],
},
// Ksentry
{
Expand Down
Loading

0 comments on commit 66ba6b3

Please sign in to comment.