Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brightness of Lightbulb is now optional #39

Merged
merged 1 commit into from Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog.md
@@ -1,3 +1,8 @@
# 1.4.3 #

## Brightness of Lightbulb is now optional ##


# 1.4.2 #

## FIX for Issue #36 "Verbindungsproblem mit vw variablen" ##
Expand Down
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -182,10 +182,17 @@ Name | Value | Required | Option for | Notes
`lightbulbGet` | "Q4" | yes* | "lightbulb" | lightbulb Get - Qn, Mn or Vn.n
`lightbulbSetOn` | "V7.0" | yes* | "lightbulb" | Lightbulb Set On - Mn or Vn.n
`lightbulbSetOff` | "V7.1" | yes* | "lightbulb" | Lightbulb Set Off - Mn or Vn.n
`lightbulbSetBrightness` | "VW70" | yes* | "lightbulb" | Lightbulb Set Brightness - AMn or VWn
`lightbulbGetBrightness` | "VW72" | yes* | "lightbulb" | Lightbulb Get Brightness - AMn or VWn
`lightbulbSetBrightness` | "VW70" | no* | "lightbulb" | Lightbulb Set Brightness - AMn or VWn
`lightbulbGetBrightness` | "VW72" | no* | "lightbulb" | Lightbulb Get Brightness - AMn or VWn

```json
{
"name": "Q1",
"type": "lightbulb",
"lightbulbGet": "Q1",
"lightbulbSetOn": "V1.0",
"lightbulbSetOff": "V1.1"
},
{
"name": "Q4",
"type": "lightbulb",
Expand Down
23 changes: 17 additions & 6 deletions src/accessories/lightbulbPlatformAccessory.ts
Expand Up @@ -23,6 +23,8 @@ export class LightbulbPlatformAccessory implements AccessoryPlugin {
private updateOnQueued: boolean;
private updateBrightnessQueued: boolean;

private withBrightness: boolean;

private accStates = {
On: false,
Brightness: 100,
Expand All @@ -39,6 +41,8 @@ export class LightbulbPlatformAccessory implements AccessoryPlugin {
this.pushButton = this.device.pushButton || this.platform.pushButton;
this.logging = this.device.logging || 0;

this.withBrightness = false;

this.fakegatoService = [];
this.services = [];

Expand All @@ -50,10 +54,12 @@ export class LightbulbPlatformAccessory implements AccessoryPlugin {
.onSet(this.setOn.bind(this))
.onGet(this.getOn.bind(this));

this.service.getCharacteristic(this.platform.Characteristic.Brightness)
.onSet(this.setBrightness.bind(this))
.onGet(this.getBrightness.bind(this));

if (this.withBrightness) {
this.service.getCharacteristic(this.platform.Characteristic.Brightness)
.onSet(this.setBrightness.bind(this))
.onGet(this.getBrightness.bind(this));
}

this.information = new this.api.hap.Service.AccessoryInformation()
.setCharacteristic(this.api.hap.Characteristic.Manufacturer, this.platform.manufacturer)
.setCharacteristic(this.api.hap.Characteristic.Model, this.model + ' @ ' + this.platform.model)
Expand All @@ -68,7 +74,9 @@ export class LightbulbPlatformAccessory implements AccessoryPlugin {
if (this.platform.config.updateInterval) {
setInterval(() => {
this.updateOn();
this.updateBrightness();
if (this.withBrightness) {
this.updateBrightness();
}
}, this.platform.config.updateInterval);
}

Expand All @@ -88,9 +96,12 @@ export class LightbulbPlatformAccessory implements AccessoryPlugin {
}

errorCheck() {
if (!this.device.lightbulbGet || !this.device.lightbulbSetOn || !this.device.lightbulbSetOff || !this.device.lightbulbSetBrightness || !this.device.lightbulbGetBrightness) {
if (!this.device.lightbulbGet || !this.device.lightbulbSetOn || !this.device.lightbulbSetOff) {
this.platform.log.error('[%s] One or more LOGO! Addresses are not correct!', this.device.name);
}
if (this.device.lightbulbSetBrightness && this.device.lightbulbGetBrightness) {
this.withBrightness = true;
}
}

getServices(): Service[] {
Expand Down