Skip to content

Commit

Permalink
Chore: Spread props when initializing a device.
Browse files Browse the repository at this point in the history
This removes unnecessary function wrapping for mixins
  • Loading branch information
Andrey Okonetchnikov authored and okonet committed Jan 4, 2020
1 parent 6d3e766 commit 8fbf288
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions bulbs/brightness.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const Brightness = ({ bright: b }) => Device =>
const Brightness = Device =>
class extends Device {
constructor(props, platform) {
super(props, platform);
this.bright = b;
this.bright = props.bright;

(
this.service.getCharacteristic(global.Characteristic.Brightness) ||
Expand Down
1 change: 1 addition & 0 deletions bulbs/bulb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class YeeBulb {
this.cmds = {};
this.sock = null;
this.accessory = accessory;
this.activeMode = 0; // We need to set a default activeMode since it's being used in brightness.js
this.config = platform.config || {};
this.endpoint = endpoint;
const { retries = 5, timeout = 100 } = this.config.connection || {};
Expand Down
6 changes: 3 additions & 3 deletions bulbs/color.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { isInteger } = Number;

const Color = ({ hue: h, sat: s }) => Device => {
const Color = Device => {
let hue;
let sat;

return class extends Device {
constructor(props, platform) {
super(props, platform);
this.hue = h;
this.sat = s;
this.hue = props.hue;
this.sat = props.sat;

const { Hue, Saturation } = global.Characteristic;

Expand Down
9 changes: 4 additions & 5 deletions bulbs/moonlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* 0 - Daylight mode |
* 1 - Moonlight mode
*/

// eslint-disable-next-line max-len
const MoonlightMode = ({ bright: b, active_mode: activeMode = 0 }) => Device =>
const MoonlightMode = Device =>
class extends Device {
constructor(props, platform) {
super(props, platform);
this.bright = b;
this.activeMode = activeMode;
const { bright, active_mode } = props;
this.bright = bright;
this.activeMode = active_mode || 0;

this.moonlightModeService =
this.accessory.getService(global.Service.Switch) ||
Expand Down
4 changes: 2 additions & 2 deletions bulbs/temperature.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const Temperature = ({ ct }) => Device =>
const Temperature = Device =>
class extends Device {
constructor(props, platform) {
super(props, platform);
this.temperature = ct;
this.temperature = props.ct;

const { ColorTemperature } = global.Characteristic;

Expand Down
10 changes: 5 additions & 5 deletions platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,26 @@ class YeePlatform {
// Lamps that support moonlight mode
if ([MODELS.CEILING, MODELS.LAMP].includes(family)) {
this.log(`Device ${name} supports moonlight mode`);
mixins.push(MoonlightMode(props));
mixins.push(MoonlightMode);
}

if (features.includes('set_bright')) {
this.log(`Device ${name} supports brightness`);
mixins.push(Brightness(props));
mixins.push(Brightness);
}

if (features.includes('set_hsv')) {
this.log(`Device ${name} supports color`);
mixins.push(Color(props));
mixins.push(Color);
}

if (features.includes('set_ct_abx')) {
this.log(`Device ${name} supports color temperature`);
mixins.push(Temperature(props));
mixins.push(Temperature);
}

const Bulb = class extends pipe(...mixins)(YeeBulb) {};
return new Bulb({ id, name, model, endpoint, accessory }, this);
return new Bulb({ id, name, model, endpoint, accessory, ...props }, this);
}
}

Expand Down

0 comments on commit 8fbf288

Please sign in to comment.