Small cosmetics
This commit is contained in:
parent
b95352b05b
commit
f6450f9463
20
README.md
20
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.
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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));
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user