From f6450f9463a87ca35b95904eaff9011e10b5f8af Mon Sep 17 00:00:00 2001 From: Serge Wagener Date: Thu, 10 Feb 2022 12:57:30 +0100 Subject: [PATCH] Small cosmetics --- README.md | 20 ++++++++++---------- src/Accessories/ContactSensor.ts | 6 +++--- src/Accessories/Lightbulb.ts | 16 +++++++++------- src/Accessories/OccupancySensor.ts | 6 +++--- src/Accessories/WindowCovering.ts | 4 +--- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 47ac031..fd0bbaa 100644 --- a/README.md +++ b/README.md @@ -68,34 +68,34 @@ Optional: } ``` ### Doorbell -TODO +*TODO* ### Fan -TODO +*TODO* ### LightBulb -TODO +*TODO* ### Occupancy sensor -TODO +*TODO* ### Motion sensor -TODO +*TODO* ### Contact sensor -TODO +*TODO* ### Switch -TODO +*TODO* ### Outlet -TODO +*TODO* ### Temperature sensor -TODO +*TODO* ### Thermostat -TODO +*TODO* ### WindowCovering In addition to the common characteristics the following are available. diff --git a/src/Accessories/ContactSensor.ts b/src/Accessories/ContactSensor.ts index 71ab1c8..ce02a9f 100644 --- a/src/Accessories/ContactSensor.ts +++ b/src/Accessories/ContactSensor.ts @@ -28,7 +28,7 @@ export class ContactSensor implements AccessoryPlugin { .setCharacteristic(this.platform.Characteristic.Model, accessory.model) .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.contactstate); - this.platform.shng.addMonitor(accessory.contactstate, this.shngCallback.bind(this)); + this.platform.shng.addMonitor(accessory.contactstate, this.shngContactStateCallback.bind(this)); this.platform.log.info('ContactSensor', accessory.name, 'created!'); } @@ -49,8 +49,8 @@ export class ContactSensor implements AccessoryPlugin { return this.contactState; } - shngCallback(value: unknown): void { - this.platform.log.debug('shngCallback:', this.accessory.name, '=', value, '(' + typeof value + ')'); + shngContactStateCallback(value: unknown): void { + this.platform.log.debug('shngContactStateCallback:', this.accessory.name, '=', value, '(' + typeof value + ')'); if (typeof value === 'boolean') { if (value) { this.contactState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED; diff --git a/src/Accessories/Lightbulb.ts b/src/Accessories/Lightbulb.ts index 30721e6..7360ec3 100644 --- a/src/Accessories/Lightbulb.ts +++ b/src/Accessories/Lightbulb.ts @@ -20,6 +20,8 @@ type RGB = { B: number; }; +enum LightType { ONOFF, DIMMABLE, RGB, RGBW } + export class Lightbulb implements AccessoryPlugin { private readonly deviceService: Service; private readonly informationService: Service; @@ -33,7 +35,7 @@ export class Lightbulb implements AccessoryPlugin { private W = 0; WMin = 0; WMax = 100; private hue = 0; private saturation = 0; - private lightType = 0; // 0 = OnOff Light, 1 = Dimmable Light, 2 = RGB, 3 = RGBW + private lightType = LightType.ONOFF; // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory: any) { @@ -51,7 +53,7 @@ export class Lightbulb implements AccessoryPlugin { .onGet(this.getBrightness.bind(this)) .onSet(this.setBrightness.bind(this)); this.platform.shng.addMonitor(accessory.brightness, this.shngBrightnessCallback.bind(this)); - this.lightType = 1; // Dimmable light + this.lightType = LightType.DIMMABLE; } // If RGB or RGBW light @@ -66,11 +68,11 @@ export class Lightbulb implements AccessoryPlugin { this.platform.shng.addMonitor(accessory.R, this.shngRCallback.bind(this)); this.platform.shng.addMonitor(accessory.G, this.shngGCallback.bind(this)); this.platform.shng.addMonitor(accessory.B, this.shngBCallback.bind(this)); - this.lightType = 2; // RGB light + this.lightType = LightType.RGB; if (accessory.w) { this.platform.shng.addMonitor(accessory.W, this.shngWCallback.bind(this)); - this.lightType = 3; // RGBW light + this.lightType = LightType.RGBW; } } @@ -91,7 +93,7 @@ export class Lightbulb implements AccessoryPlugin { this.BMin = accessory.bmin ? accessory.bmin : this.BMin; this.WMax = accessory.wmax ? accessory.wmax : this.WMax; this.WMin = accessory.wmin ? accessory.wmin : this.WMin; - this.platform.log.info("Lightbulb '%s' created!", accessory.name); + this.platform.log.info("Lightbulb '%s' created! (" + LightType[this.lightType] + ')', accessory.name); } identify(): void { @@ -152,13 +154,13 @@ export class Lightbulb implements AccessoryPlugin { } updateColor(): void { - if (this.lightType === 3) { + if (this.lightType === LightType.RGBW) { const rgbw: RGBW = this.hsb2rgbw(this.hue, this.saturation, this.brightness); this.platform.shng.setItem(this.accessory.r, this.convertRange(rgbw.R, 0, 100, this.RMin, this.RMax)); this.platform.shng.setItem(this.accessory.g, this.convertRange(rgbw.G, 0, 100, this.GMin, this.GMax)); this.platform.shng.setItem(this.accessory.b, this.convertRange(rgbw.B, 0, 100, this.BMin, this.BMax)); this.platform.shng.setItem(this.accessory.w, this.convertRange(rgbw.W, 0, 100, this.WMin, this.WMax)); - } else if (this.lightType === 2) { + } else if (this.lightType === LightType.RGB) { const rgb: RGB = this.hsb2rgb(this.hue, this.saturation, this.brightness); this.platform.shng.setItem(this.accessory.r, this.convertRange(rgb.R, 0, 100, this.RMin, this.RMax)); this.platform.shng.setItem(this.accessory.g, this.convertRange(rgb.G, 0, 100, this.GMin, this.GMax)); diff --git a/src/Accessories/OccupancySensor.ts b/src/Accessories/OccupancySensor.ts index 48466ef..8e0def1 100644 --- a/src/Accessories/OccupancySensor.ts +++ b/src/Accessories/OccupancySensor.ts @@ -28,7 +28,7 @@ export class OccupancySensor implements AccessoryPlugin { .setCharacteristic(this.platform.Characteristic.Model, accessory.model) .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.occupancydetected); - this.platform.shng.addMonitor(accessory.occupancydetected, this.shngCallback.bind(this)); + this.platform.shng.addMonitor(accessory.occupancydetected, this.shngAccupancyDetectedCallback.bind(this)); this.platform.log.info('OccupancySensor', accessory.name, 'created!'); } @@ -45,8 +45,8 @@ export class OccupancySensor implements AccessoryPlugin { return this.occupencyDetected; } - shngCallback(value: unknown): void { - this.platform.log.debug('shngCallback:', this.accessory.name, '=', value, '(' + typeof value + ')'); + shngAccupancyDetectedCallback(value: unknown): void { + this.platform.log.debug('shngAccupancyDetectedCallback:', this.accessory.name, '=', value, '(' + typeof value + ')'); if (typeof value === 'boolean') { if (value) { this.occupencyDetected = this.platform.Characteristic.OccupancyDetected.OCCUPANCY_DETECTED; diff --git a/src/Accessories/WindowCovering.ts b/src/Accessories/WindowCovering.ts index 6280e59..d9389bf 100644 --- a/src/Accessories/WindowCovering.ts +++ b/src/Accessories/WindowCovering.ts @@ -4,8 +4,6 @@ import { Service, Nullable, } from 'homebridge'; -import { setMaxListeners } from 'process'; -import { setFlagsFromString } from 'v8'; import { SmartHomeNGPlatform } from '../platform'; @@ -134,7 +132,7 @@ export class WindowCovering implements AccessoryPlugin { if (inverted) { result = newmax - result; } - this.platform.log.warn( + this.platform.log.debug( 'Transposing', value, 'from range', oldmin, '-', oldmax, 'to', newmin, '-', newmax,