homebridge#CharacteristicSetCallback TypeScript Examples
The following examples show how to use
homebridge#CharacteristicSetCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: temperature.ts From homebridge-wiz-lan with Apache License 2.0 | 6 votes |
export function initTemperature(
accessory: PlatformAccessory,
device: Device,
wiz: HomebridgeWizLan
) {
const { Characteristic, Service } = wiz;
const service = accessory.getService(Service.Lightbulb)!;
service
.getCharacteristic(Characteristic.ColorTemperature)
.on("get", (callback) =>
getPilot(
wiz,
accessory,
device,
(pilot) => callback(null, transformTemperature(pilot)),
callback
)
)
.on(
"set",
(newValue: CharacteristicValue, next: CharacteristicSetCallback) => {
setPilot(
wiz,
accessory,
device,
{
temp: miredToKelvin(Number(newValue)),
r: undefined,
g: undefined,
b: undefined,
},
updateColorTemp(device, accessory, wiz, next)
);
}
);
}
Example #2
Source File: platformL530Accessory.ts From homebridge-tapo-p100 with Apache License 2.0 | 6 votes |
/**
* Handle "SET" requests from HomeKit
* These are sent when the user changes the state of an accessory.
*/
setSaturation(value: CharacteristicValue, callback: CharacteristicSetCallback) {
if(this.l530.getSysInfo().device_on){
this.l530.setColor(this.l530.getSysInfo().hue, Math.round(value as number)).then((result) => {
if(result){
this.l530.getSysInfo().saturation = Math.round(value as number);
this.platform.log.debug('Set Characteristic Saturation ->', Math.round(value as number));
this.platform.log.debug('With Characteristic Hue ->', this.l530.getSysInfo().hue);
// you must call the callback function
callback(null);
} else{
callback(new Error('unreachable'), false);
}
});
} else{
callback(null);
}
}
Example #3
Source File: wled-accessory.ts From homebridge-simple-wled with ISC License | 6 votes |
registerCharacteristicOnOff(): void {
this.lightService.getCharacteristic(this.hap.Characteristic.On)
.on(CharacteristicEventTypes.GET, (callback: CharacteristicGetCallback) => {
if (this.debug)
this.log("Current state of the switch was returned: " + (this.lightOn ? "ON" : "OFF"));
callback(undefined, this.lightOn);
})
.on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => {
let tempLightOn = value as boolean;
if (tempLightOn && !this.lightOn) {
this.turnOnWLED();
if (this.debug)
this.log("Light was turned on!");
} else if (!tempLightOn && this.lightOn) {
this.turnOffWLED();
if (this.debug)
this.log("Light was turned off!");
}
this.lightOn = tempLightOn;
callback();
});
}
Example #4
Source File: color.ts From homebridge-wiz-lan with Apache License 2.0 | 6 votes |
function initHue(
accessory: PlatformAccessory,
device: Device,
wiz: HomebridgeWizLan
) {
const { Characteristic, Service } = wiz;
const service = accessory.getService(Service.Lightbulb)!;
service
.getCharacteristic(Characteristic.Hue)
.on("get", callback =>
getPilot(
wiz,
accessory,
device,
pilot => callback(null, transformHue(pilot)),
callback
)
)
.on(
"set",
(newValue: CharacteristicValue, next: CharacteristicSetCallback) => {
setPilot(
wiz,
accessory,
device,
{
temp: undefined,
...hsvToColor(
Number(newValue) / 360,
pilotToColor(cachedPilot[device.mac]).saturation / 100,
wiz
),
},
updateColorTemp(device, accessory, wiz, next)
);
}
);
}
Example #5
Source File: wled-accessory.ts From homebridge-simple-wled with ISC License | 6 votes |
registerCharacteristicAmbilightOnOff(): void {
this.ambilightService.getCharacteristic(this.hap.Characteristic.On)
.on(CharacteristicEventTypes.GET, (callback: CharacteristicGetCallback) => {
if (this.debug)
this.log("Current state of the switch was returned: " + (this.ambilightOn ? "ON" : "OFF"));
callback(undefined, this.ambilightOn);
})
.on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => {
this.ambilightOn = value as boolean;
if (this.ambilightOn) {
this.turnOnAmbilight();
} else {
this.turnOffAmbilight();
}
if (this.debug)
this.log("Switch state was set to: " + (this.ambilightOn ? "ON" : "OFF"));
callback();
});
}
Example #6
Source File: onOff.ts From homebridge-wiz-lan with Apache License 2.0 | 6 votes |
export function initOnOff(
accessory: PlatformAccessory,
device: Device,
wiz: HomebridgeWizLan
) {
const { Characteristic, Service } = wiz;
const service = accessory.getService(Service.Outlet)!;
service
.getCharacteristic(Characteristic.On)
.on("get", callback =>
getPilot(
wiz,
accessory,
device,
pilot => callback(null, transformOnOff(pilot)),
callback
)
)
.on(
"set",
(newValue: CharacteristicValue, next: CharacteristicSetCallback) => {
setPilot(wiz, accessory, device, { state: Boolean(newValue) }, next);
}
);
}
Example #7
Source File: switch.ts From homebridge-esphome-ts with GNU General Public License v3.0 | 6 votes |
switchHelper = (component: SwitchComponent, accessory: PlatformAccessory): boolean => {
let service = accessory.services.find((service) => service.UUID === Service.Switch.UUID);
if (!service) {
service = accessory.addService(new Service.Switch(component.name, ''));
}
component.state$
.pipe(tap(() => service?.getCharacteristic(Characteristic.On)?.setValue(component.status)))
.subscribe();
service
.getCharacteristic(Characteristic.On)
?.on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => {
if (component.status !== !!value) {
!!value ? component.turnOn() : component.turnOff();
}
callback();
});
return true;
}
Example #8
Source File: lighbulb-service-builder.ts From homebridge-zigbee-nt with Apache License 2.0 | 6 votes |
public withOnOff(): LighbulbServiceBuilder {
const Characteristic = this.Characteristic;
this.service
.getCharacteristic(Characteristic.On)
.on(
CharacteristicEventTypes.SET,
async (yes: boolean, callback: CharacteristicSetCallback) => {
if (this.isOnline) {
try {
Object.assign(this.state, await this.client.setOnState(this.device, yes));
return callback();
} catch (e) {
return callback(e);
}
} else {
return callback(new Error('Device is offline'));
}
}
);
this.service
.getCharacteristic(Characteristic.On)
.on(CharacteristicEventTypes.GET, (callback: CharacteristicGetCallback) => {
if (this.isOnline) {
this.client.getOnOffState(this.device).catch((e) => {
this.log.error(e.message);
});
return callback(null, this.state.state === 'ON');
} else {
return callback(new Error('Device is offline'));
}
});
return this;
}
Example #9
Source File: circuitAccessory.ts From homebridge-screenlogic with MIT License | 6 votes |
/**
* Handle "SET" requests from HomeKit
* These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.
*/
setOn(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.platform.log.debug('setOn:', value, this.context)
this.platform.setCircuitState(this.context, value as boolean)
callback(null, value)
}
Example #10
Source File: abstractCharacteristic.ts From homebridge-lg-thinq-ac with Apache License 2.0 | 6 votes |
/** Handle a "set" command from Homebridge to update this characteristic */
handleSet?(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.logDebug('Triggered SET:', value)
if (!this.thinqApi) {
this.logError('API not initialized yet')
return
}
// Double-transform the value
const targetState = this.getStateFromApiValue(
this.getApiValueFromState(value as State),
)
this.logDebug('targetState', targetState)
if (targetState === this.cachedState) {
// The air conditioner will make a sound every time this API is called.
// To avoid unnecessary chimes, we'll optimistically skip sending the API call.
this.logDebug('State equals cached state. Skipping.', targetState)
callback(null)
return
}
const apiValue = this.getApiValueFromState(targetState)
this.thinqApi
.sendCommand(this.deviceId, this.apiCommand, this.apiDataKey, apiValue)
.then(() => {
this.cachedState = targetState
callback(null)
})
.catch((error) => {
this.logError('Failed to set state', targetState, `${error}`)
callback(error)
})
}
Example #11
Source File: tasmotaLightService.ts From homebridge-tasmota with Apache License 2.0 | 6 votes |
setSaturation(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.platform.log.info('%s Set Characteristic Saturation ->', this.accessory.displayName, value);
this.update.put({
oldHue: this.service.getCharacteristic(this.platform.Characteristic.Hue).value,
oldSaturation: this.service.getCharacteristic(this.platform.Characteristic.Saturation).value,
oldBrightness: this.service.getCharacteristic(this.platform.Characteristic.Brightness).value,
newSaturation: value,
}).then(() => {
// debug("setTargetTemperature", this, thermostat);
callback(null);
}).catch((error) => {
callback(error);
});
}
Example #12
Source File: accessory.ts From homebridge-nest-cam with GNU General Public License v3.0 | 6 votes |
createSwitchService(
name: string,
serviceType: ServiceType,
_key: keyof Properties,
cb: (value: CharacteristicValue) => Promise<void>,
): void {
const service = this.createService(serviceType, name);
this.log.debug(`Creating switch for ${this.accessory.displayName} ${name}.`);
service
.setCharacteristic(this.hap.Characteristic.On, this.camera.info.properties[_key])
.getCharacteristic(this.hap.Characteristic.On)
.on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => {
cb(value);
this.log.info(`Setting ${this.accessory.displayName} ${name} to ${value ? 'on' : 'off'}`);
callback();
})
.on(CharacteristicEventTypes.GET, (callback: CharacteristicGetCallback) => {
callback(undefined, this.camera.info.properties[_key]);
});
}
Example #13
Source File: tasmotaFanService.ts From homebridge-tasmota with Apache License 2.0 | 6 votes |
setOn(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.platform.log.info('%s Set Characteristic On ->', this.accessory.displayName, value);
if (!this.accessory.context.device[this.uniq_id].spds) {
// Not hampton bay fans with speeds rather than on
this.accessory.context.mqttHost.sendMessage(this.accessory.context.device[this.uniq_id].cmd_t, (value ?
this.accessory.context.device[this.uniq_id].pl_on : this.accessory.context.device[this.uniq_id].pl_off));
} else if (!value) {
// Turning off
this.accessory.context.mqttHost.sendMessage(this.accessory.context.device[this.uniq_id].cmd_t, (value ?
this.accessory.context.device[this.uniq_id].pl_on : this.accessory.context.device[this.uniq_id].pl_off));
} else {
// Turning on of Hampton bay RF Fans, they don't have a ON function but can restore previous speed
this.setRotationSpeedFixed(this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed).value || 25, callback);
return;
}
callback(null);
}
Example #14
Source File: platformL530Accessory.ts From homebridge-tapo-p100 with Apache License 2.0 | 6 votes |
/**
* Handle "SET" requests from HomeKit
* These are sent when the user changes the state of an accessory.
*/
setHue(value: CharacteristicValue, callback: CharacteristicSetCallback) {
if(this.l530.getSysInfo().device_on){
this.l530.setColor(Math.round(value as number), this.l530.getSysInfo().saturation).then((result) => {
if(result){
this.l530.getSysInfo().hue = Math.round(value as number);
this.platform.log.debug('Set Characteristic Hue ->', Math.round(value as number));
this.platform.log.debug('With Characteristic Saturation ->', this.l530.getSysInfo().saturation);
// you must call the callback function
callback(null);
} else{
callback(new Error('unreachable'), false);
}
});
} else{
callback(null);
}
}
Example #15
Source File: tasmotaSwitchService.ts From homebridge-tasmota with Apache License 2.0 | 6 votes |
/**
* Handle "SET" requests from HomeKit
* These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.
*/
setOn(value: CharacteristicValue, callback: CharacteristicSetCallback) {
try {
this.platform.log.info('%s Set Characteristic On ->', this.service.displayName, value);
if (typeof this.accessory.context.device[this.uniq_id].pl_on === 'boolean') {
this.accessory.context.mqttHost.sendMessage(this.accessory.context.device[this.uniq_id].cmd_t, (value ?
'true' : 'false'));
} else {
this.accessory.context.mqttHost.sendMessage(this.accessory.context.device[this.uniq_id].cmd_t, (value ?
this.accessory.context.device[this.uniq_id].pl_on : this.accessory.context.device[this.uniq_id].pl_off));
}
if (this.platform.config.history && this.accessory.context.fakegatoService ?.addEntry) {
debug('Updating fakegato', this.service.displayName, {
status: (value ? 1 : 0),
});
this.accessory.context.fakegatoService.appendData({
status: (value ? 1 : 0),
});
} else {
// debug('Not updating fakegato', this.service.displayName);
}
} catch (err) {
this.platform.log.error('ERROR:', err.message);
}
// you must call the callback function
callback(null);
}
Example #16
Source File: platformAccessory.ts From HomebridgeMagicHome-DynamicPlatform with Apache License 2.0 | 6 votes |
//=================================================
// End Constructor //
//=================================================
// Start Setters //
setConfiguredName(value: CharacteristicValue, callback: CharacteristicSetCallback) {
const name: string = value.toString();
this.logs.debug('Renaming device to %o', name);
this.myDevice.displayName = name;
this.platform.api.updatePlatformAccessories([this.accessory]);
callback(null);
}
Example #17
Source File: platformL530Accessory.ts From homebridge-tapo-p100 with Apache License 2.0 | 6 votes |
/**
* Handle "SET" requests from HomeKit
* These are sent when the user changes the state of an accessory.
*/
setColorTemp(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.log.debug('Color Temp Homekit :' + value);
if(this.l530.getSysInfo().device_on){
this.l530.setColorTemp(value as number).then((result) => {
if(result){
this.l530.getSysInfo().color_temp = value as number;
this.platform.log.debug('Set Characteristic Color Temperature ->', value);
// you must call the callback function
callback(null);
} else{
callback(new Error('unreachable'), false);
}
});
} else{
// you must call the callback function
callback(null);
}
}
Example #18
Source File: platformAccessory.ts From HomebridgeMagicHome-DynamicPlatform with Apache License 2.0 | 6 votes |
/*
async setColorTemperature(value: CharacteristicValue, callback: CharacteristicSetCallback){
this.lightState.operatingMode = opMode.temperatureMode;
this.processRequest({msg: `cct=${value}`} );
callback(null);
}*/
setOn(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.lightState.isOn = value as boolean;
this.processRequest();
callback(null);
}
Example #19
Source File: platformL510EAccessory.ts From homebridge-tapo-p100 with Apache License 2.0 | 6 votes |
/**
* Handle "SET" requests from HomeKit
* These are sent when the user changes the state of an accessory.
*/
setOn(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.l510e.setPowerState(value as boolean).then((result) => {
if(result){
this.platform.log.debug('Set Characteristic On ->', value);
this.l510e.getSysInfo().device_on = value as boolean;
// you must call the callback function
callback(null);
} else{
callback(new Error('unreachable'), false);
}
});
}
Example #20
Source File: lighbulb-service-builder.ts From homebridge-zigbee-nt with Apache License 2.0 | 5 votes |
private withHue(): LighbulbServiceBuilder {
const Characteristic = this.Characteristic;
this.state.color = {
...this.state.color,
hue: 360,
};
this.service
.getCharacteristic(Characteristic.Hue)
.on(
CharacteristicEventTypes.SET,
async (hue: number, callback: CharacteristicSetCallback) => {
try {
if (this.isOnline) {
Object.assign(this.state, await this.client.setHue(this.device, hue));
return callback(null, get(this.state, 'color.hue', 360));
} else {
return callback(new Error('Device is offline'));
}
} catch (e) {
return callback(e);
}
}
);
this.service
.getCharacteristic(Characteristic.Hue)
.on(CharacteristicEventTypes.GET, (callback: CharacteristicGetCallback) => {
if (this.isOnline) {
this.log.debug(
`[light-bulb-service] Reading HUE for ${this.friendlyName}: ${this.state.color.hue}`
);
callback(null, get(this.state, 'color.hue', 360));
return this.client
.getHue(this.device)
.catch((e) => this.log.error(`[light-bulb-service] Error reading HUE: ${e.message}`));
} else {
this.log.warn(`[light-bulb-service] ${this.friendlyName} is offline, skipping GET Hue`);
return callback(new Error('Device is offline'));
}
});
return this;
}
Example #21
Source File: thermostatAccessory.ts From homebridge-screenlogic with MIT License | 5 votes |
setTargetHeatingCoolingState(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.platform.log.debug('setTargetHeatingCoolingState:', value, this.context)
this.platform.setTargetHeatingCoolingState(this.context, value as number)
callback(null, value)
}
Example #22
Source File: platform.ts From homebridge-tasmota with Apache License 2.0 | 5 votes |
function setConfiguredName(this: tasmotaSwitchService | tasmotaGarageService | tasmotaLightService | tasmotaFanService | tasmotaSensorService | tasmotaBinarySensorService, value, callback: CharacteristicSetCallback) {
// debug('this', this.service.displayName);
// this.platform.log.debug('setConfiguredName', value, this.service.displayName);
this.service.displayName = value;
this.service.setCharacteristic(this.platform.Characteristic.Name, this.service.displayName);
this.platform.api.updatePlatformAccessories([this.accessory]);
callback();
}
Example #23
Source File: thermostat-service-builder.ts From homebridge-zigbee-nt with Apache License 2.0 | 5 votes |
public withTargetHeatingCoolingState(
asAuto?: [SystemMode],
asOff?: [SystemMode]
): ThermostatServiceBuilder {
const Characteristic = this.platform.Characteristic;
this.service
.getCharacteristic(Characteristic.TargetHeatingCoolingState)
.on(
CharacteristicEventTypes.SET,
async (state: number, callback: CharacteristicSetCallback) => {
let translatedMode: SystemMode = translateTargetStateToSystemMode(state);
if (
asAuto &&
Array.isArray(asAuto) &&
asAuto.length > 0 &&
asAuto.includes(translatedMode)
) {
translatedMode = 'auto';
}
if (asOff && Array.isArray(asOff) && asOff.length > 0 && asOff.includes(translatedMode)) {
translatedMode = 'off';
}
try {
Object.assign(this.state, await this.client.setSystemMode(this.device, translatedMode));
callback();
} catch (e) {
callback(e);
}
}
);
this.service
.getCharacteristic(Characteristic.TargetHeatingCoolingState)
.on(CharacteristicEventTypes.GET, async (callback: CharacteristicGetCallback) => {
try {
callback(null, translateTargetStateFromSystemMode(this.state.system_mode));
} catch (e) {
callback(e);
}
});
return this;
}
Example #24
Source File: tasmotaFanService.ts From homebridge-tasmota with Apache License 2.0 | 5 votes |
setRotationSpeed(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.platform.log.info('%s Set Characteristic RotationSpeed ->', this.accessory.displayName, value);
this.accessory.context.mqttHost.sendMessage(this.accessory.context.device[this.uniq_id].bri_cmd_t, value.toString());
callback(null);
}
Example #25
Source File: platformAccessory.ts From HomebridgeMagicHome-DynamicPlatform with Apache License 2.0 | 5 votes |
setColorTemperature(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.setColortemp = true;
this.lightState.CCT = value as number;
this.colorCommand = true;
this.processRequest();
callback(null);
}
Example #26
Source File: tasmotaLightService.ts From homebridge-tasmota with Apache License 2.0 | 5 votes |
setBrightness(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.platform.log.info('%s Set Characteristic Brightness ->', this.accessory.displayName, value);
this.accessory.context.mqttHost.sendMessage(this.accessory.context.device[this.uniq_id].bri_cmd_t, value.toString());
callback(null);
}
Example #27
Source File: lighbulb-service-builder.ts From homebridge-zigbee-nt with Apache License 2.0 | 5 votes |
public withBrightness(): LighbulbServiceBuilder {
const Characteristic = this.Characteristic;
this.state.brightness_percent = 100;
this.service
.getCharacteristic(Characteristic.Brightness)
.on(
CharacteristicEventTypes.SET,
async (brightnessPercent: number, callback: CharacteristicSetCallback) => {
try {
if (this.isOnline) {
Object.assign(
this.state,
await this.client.setBrightnessPercent(this.device, brightnessPercent)
);
return callback();
} else {
return callback(new Error('Device is offline'));
}
} catch (e) {
return callback(e);
}
}
);
this.service
.getCharacteristic(Characteristic.Brightness)
.on(CharacteristicEventTypes.GET, (callback: CharacteristicGetCallback) => {
if (this.isOnline) {
this.client.getBrightnessPercent(this.device).catch((e) => {
this.log.error(e.message);
});
this.log.debug(
`Reading Brightness for ${this.friendlyName}: ${this.state.brightness_percent}`
);
return callback(null, get(this.state, 'brightness_percent', 100));
} else {
return callback(new Error('Device is offline'));
}
});
return this;
}
Example #28
Source File: tasmotaLightService.ts From homebridge-tasmota with Apache License 2.0 | 5 votes |
setColorTemperature(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.platform.log.info('%s Set Characteristic ColorTemperature ->', this.accessory.displayName, value);
this.accessory.context.mqttHost.sendMessage(this.accessory.context.device[this.uniq_id].clr_temp_cmd_t, value.toString());
callback(null);
}
Example #29
Source File: platformAccessory.ts From HomebridgeMagicHome-DynamicPlatform with Apache License 2.0 | 5 votes |
setHue(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.setColortemp = false;
this.lightState.HSL.hue = value as number;
this.colorCommand = true;
this.processRequest();
callback(null);
}