Skip to content

Commit

Permalink
feat(dingz): use DeviceSystem name for LED
Browse files Browse the repository at this point in the history
Merge pull request #153 from granturism0/granturimo-mods, thanks @granturism0 for the contribution!
  • Loading branch information
johannrichard committed Nov 30, 2020
2 parents 98dbb77 + c9bd15e commit 1d14c2d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 55 deletions.
123 changes: 68 additions & 55 deletions src/dingzAccessory.ts
Expand Up @@ -129,64 +129,73 @@ export class DingzAccessory extends DingzDaBaseAccessory {
address: this.device.address,
token: this.device.token,
})
.then(({ dingzDevices, inputConfig, dimmerConfig, blindConfig }) => {
if (
inputConfig?.inputs &&
dimmerConfig?.dimmers &&
dimmerConfig?.dimmers.length === 4
) {
this.device.dingzInputInfo = inputConfig.inputs;
this.device.dimmerConfig = dimmerConfig;
this.device.windowCoveringConfig = blindConfig.blinds;

if (dingzDevices[this.device.mac]) {
this.log.debug(
'Updated device info received -> update accessory',
dingzDevices[this.device.mac],
);
.then(
({
dingzDevices,
inputConfig,
systemConfig,
dimmerConfig,
blindConfig,
}) => {
if (
inputConfig?.inputs &&
dimmerConfig?.dimmers &&
dimmerConfig?.dimmers.length === 4
) {
this.device.dingzInputInfo = inputConfig.inputs;
this.device.systemConfig = systemConfig;
this.device.dimmerConfig = dimmerConfig;
this.device.windowCoveringConfig = blindConfig.blinds;

if (dingzDevices[this.device.mac]) {
this.log.debug(
'Updated device info received -> update accessory',
dingzDevices[this.device.mac],
);

// Persist updated info
this.device.hwInfo = dingzDevices[this.device.mac];
this.accessory.context.device = this.device;
this.dingzDeviceInfo = this.device.hwInfo as DingzDeviceInfo;
this.baseUrl = `http://${this.device.address}`;
// Persist updated info
this.device.hwInfo = dingzDevices[this.device.mac];
this.accessory.context.device = this.device;
this.dingzDeviceInfo = this.device.hwInfo as DingzDeviceInfo;
this.baseUrl = `http://${this.device.address}`;
this.setAccessoryInformation();
}
this.setAccessoryInformation();
}
this.setAccessoryInformation();
this.setButtonCallbacks();
this.setButtonCallbacks();

// Now we have what we need and can create the services …
this.addOutputServices();
// Now we have what we need and can create the services …
this.addOutputServices();

// Add auxiliary services (Motion, Temperature)
if (this.dingzDeviceInfo.has_pir) {
// dingz has a Motion sensor -- let's create it
this.addMotionService();
} else {
this.log.info('This dingz has no Motion sensor.');
}
// dingz has a temperature sensor and an LED,
// make these available here
this.addTemperatureService();
this.addLEDService();
this.addLightSensorService();
this.addButtonServices();

this.services.forEach((service) => {
this.log.info(
'Service created ->',
service.getCharacteristic(this.platform.Characteristic.Name)
.value,
);
});
// Add auxiliary services (Motion, Temperature)
if (this.dingzDeviceInfo.has_pir) {
// dingz has a Motion sensor -- let's create it
this.addMotionService();
} else {
this.log.info('This dingz has no Motion sensor.');
}
// dingz has a temperature sensor and an LED,
// make these available here
this.addTemperatureService();
this.addLEDService();
this.addLightSensorService();
this.addButtonServices();

this.services.forEach((service) => {
this.log.info(
'Service created ->',
service.getCharacteristic(this.platform.Characteristic.Name)
.value,
);
});

// Retry at least once every day
retrySlow.execute(() => {
this.updateAccessory();
return true;
});
}
})
// Retry at least once every day
retrySlow.execute(() => {
this.updateAccessory();
return true;
});
}
},
)
.catch(this.handleRequestErrors.bind(this));
}

Expand Down Expand Up @@ -1293,15 +1302,19 @@ export class DingzAccessory extends DingzDaBaseAccessory {
}

private addLEDService() {
const systemConfig = this.device.systemConfig;
// get the LightBulb service if it exists, otherwise create a new LightBulb service
// you can create multiple services for each accessory
const ledService =
this.accessory.getServiceById(this.platform.Service.Lightbulb, 'LED') ??
this.accessory.addService(this.platform.Service.Lightbulb, 'LED', 'LED');

// set the service name, this is what is displayed as the default name on the Home app
ledService.setCharacteristic(this.platform.Characteristic.Name, 'LED');

let ledName = 'LED';
if (systemConfig?.dingz_name) {
ledName = `${systemConfig?.dingz_name} LED`;
}
ledService.setCharacteristic(this.platform.Characteristic.Name, ledName);
// register handlers for the On/Off Characteristic
ledService
.getCharacteristic(this.platform.Characteristic.On)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/commonTypes.ts
Expand Up @@ -11,6 +11,7 @@ import { MyStromPIRAccessory } from '../myStromPIRAccessory';
import {
DingzDeviceInfo,
DingzInputInfoItem,
DingzDeviceSystemConfig,
DingzDeviceDimmerConfig,
DingzWindowCoveringConfigItem,
} from './dingzTypes';
Expand Down Expand Up @@ -43,6 +44,7 @@ export interface DeviceInfo {
model?: string;
token?: string;
hwInfo?: DingzDeviceInfo | MyStromDeviceInfo;
systemConfig?: DingzDeviceSystemConfig;
dimmerConfig?: DingzDeviceDimmerConfig;
windowCoveringConfig?: DingzWindowCoveringConfigItem[];
dingzInputInfo?: DingzInputInfoItem[];
Expand Down

0 comments on commit 1d14c2d

Please sign in to comment.