Small cosmetics

This commit is contained in:
Serge Wagener 2022-02-10 12:57:30 +01:00
parent b95352b05b
commit f6450f9463
5 changed files with 26 additions and 26 deletions

View File

@ -68,34 +68,34 @@ Optional:
} }
``` ```
### Doorbell ### Doorbell
TODO *TODO*
### Fan ### Fan
TODO *TODO*
### LightBulb ### LightBulb
TODO *TODO*
### Occupancy sensor ### Occupancy sensor
TODO *TODO*
### Motion sensor ### Motion sensor
TODO *TODO*
### Contact sensor ### Contact sensor
TODO *TODO*
### Switch ### Switch
TODO *TODO*
### Outlet ### Outlet
TODO *TODO*
### Temperature sensor ### Temperature sensor
TODO *TODO*
### Thermostat ### Thermostat
TODO *TODO*
### WindowCovering ### WindowCovering
In addition to the common characteristics the following are available. In addition to the common characteristics the following are available.

View File

@ -28,7 +28,7 @@ export class ContactSensor implements AccessoryPlugin {
.setCharacteristic(this.platform.Characteristic.Model, accessory.model) .setCharacteristic(this.platform.Characteristic.Model, accessory.model)
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.contactstate); .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!'); this.platform.log.info('ContactSensor', accessory.name, 'created!');
} }
@ -49,8 +49,8 @@ export class ContactSensor implements AccessoryPlugin {
return this.contactState; return this.contactState;
} }
shngCallback(value: unknown): void { shngContactStateCallback(value: unknown): void {
this.platform.log.debug('shngCallback:', this.accessory.name, '=', value, '(' + typeof value + ')'); this.platform.log.debug('shngContactStateCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'boolean') { if (typeof value === 'boolean') {
if (value) { if (value) {
this.contactState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED; this.contactState = this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED;

View File

@ -20,6 +20,8 @@ type RGB = {
B: number; B: number;
}; };
enum LightType { ONOFF, DIMMABLE, RGB, RGBW }
export class Lightbulb implements AccessoryPlugin { export class Lightbulb implements AccessoryPlugin {
private readonly deviceService: Service; private readonly deviceService: Service;
private readonly informationService: Service; private readonly informationService: Service;
@ -33,7 +35,7 @@ export class Lightbulb implements AccessoryPlugin {
private W = 0; WMin = 0; WMax = 100; private W = 0; WMin = 0; WMax = 100;
private hue = 0; private hue = 0;
private saturation = 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 // eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory: any) { constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory: any) {
@ -51,7 +53,7 @@ export class Lightbulb implements AccessoryPlugin {
.onGet(this.getBrightness.bind(this)) .onGet(this.getBrightness.bind(this))
.onSet(this.setBrightness.bind(this)); .onSet(this.setBrightness.bind(this));
this.platform.shng.addMonitor(accessory.brightness, this.shngBrightnessCallback.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 // 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.R, this.shngRCallback.bind(this));
this.platform.shng.addMonitor(accessory.G, this.shngGCallback.bind(this)); this.platform.shng.addMonitor(accessory.G, this.shngGCallback.bind(this));
this.platform.shng.addMonitor(accessory.B, this.shngBCallback.bind(this)); this.platform.shng.addMonitor(accessory.B, this.shngBCallback.bind(this));
this.lightType = 2; // RGB light this.lightType = LightType.RGB;
if (accessory.w) { if (accessory.w) {
this.platform.shng.addMonitor(accessory.W, this.shngWCallback.bind(this)); 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.BMin = accessory.bmin ? accessory.bmin : this.BMin;
this.WMax = accessory.wmax ? accessory.wmax : this.WMax; this.WMax = accessory.wmax ? accessory.wmax : this.WMax;
this.WMin = accessory.wmin ? accessory.wmin : this.WMin; 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 { identify(): void {
@ -152,13 +154,13 @@ export class Lightbulb implements AccessoryPlugin {
} }
updateColor(): void { updateColor(): void {
if (this.lightType === 3) { if (this.lightType === LightType.RGBW) {
const rgbw: RGBW = this.hsb2rgbw(this.hue, this.saturation, this.brightness); 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.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.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.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)); 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); 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.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)); this.platform.shng.setItem(this.accessory.g, this.convertRange(rgb.G, 0, 100, this.GMin, this.GMax));

View File

@ -28,7 +28,7 @@ export class OccupancySensor implements AccessoryPlugin {
.setCharacteristic(this.platform.Characteristic.Model, accessory.model) .setCharacteristic(this.platform.Characteristic.Model, accessory.model)
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.occupancydetected); .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!'); this.platform.log.info('OccupancySensor', accessory.name, 'created!');
} }
@ -45,8 +45,8 @@ export class OccupancySensor implements AccessoryPlugin {
return this.occupencyDetected; return this.occupencyDetected;
} }
shngCallback(value: unknown): void { shngAccupancyDetectedCallback(value: unknown): void {
this.platform.log.debug('shngCallback:', this.accessory.name, '=', value, '(' + typeof value + ')'); this.platform.log.debug('shngAccupancyDetectedCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'boolean') { if (typeof value === 'boolean') {
if (value) { if (value) {
this.occupencyDetected = this.platform.Characteristic.OccupancyDetected.OCCUPANCY_DETECTED; this.occupencyDetected = this.platform.Characteristic.OccupancyDetected.OCCUPANCY_DETECTED;

View File

@ -4,8 +4,6 @@ import {
Service, Service,
Nullable, Nullable,
} from 'homebridge'; } from 'homebridge';
import { setMaxListeners } from 'process';
import { setFlagsFromString } from 'v8';
import { SmartHomeNGPlatform } from '../platform'; import { SmartHomeNGPlatform } from '../platform';
@ -134,7 +132,7 @@ export class WindowCovering implements AccessoryPlugin {
if (inverted) { if (inverted) {
result = newmax - result; result = newmax - result;
} }
this.platform.log.warn( this.platform.log.debug(
'Transposing', value, 'Transposing', value,
'from range', oldmin, '-', oldmax, 'from range', oldmin, '-', oldmax,
'to', newmin, '-', newmax, 'to', newmin, '-', newmax,