homebridge#CharacteristicValue TypeScript Examples
The following examples show how to use
homebridge#CharacteristicValue.
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: accessory.ts From homebridge-vieramatic with Apache License 2.0 | 6 votes |
private async setInput(value: CharacteristicValue): Promise<void> {
const fn = async (): Promise<Outcome<void>> => {
let app: VieraApp, real: number
switch (true) {
case value < 100:
this.log.debug('(setInput) switching to HDMI INPUT ', value)
return await this.device.switchToHDMI((value as number).toString())
case value > 999:
real = (value as number) - 1000
app = this.storage.data.inputs.applications[real]
this.log.debug('(setInput) switching to App', app.name)
return await this.device.launchApp(app.id)
// case value === 500:
default:
this.log.debug('(setInput) switching to internal TV tunner')
return await this.device.sendKey('AD_CHANGE')
}
}
const cmd = await fn()
if (Abnormal(cmd)) this.log.error('setInput', value, cmd.error)
}
Example #2
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 #3
Source File: index.ts From homebridge-philips-air with BSD 2-Clause "Simplified" License | 6 votes |
async setBrightness(accessory: PlatformAccessory, state: CharacteristicValue): Promise<void> {
const purifier = this.purifiers.get(accessory.displayName);
if (purifier) {
const values = {
aqil: state,
uil: state ? '1' : '0'
};
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await this.enqueuePromise(CommandType.SetData, purifier, values);
} catch (err) {
this.log.error('[' + purifier.config.name + '] Error setting brightness: ' + err);
}
}
}
Example #4
Source File: TasmotaService.ts From homebridge-tasmota with Apache License 2.0 | 6 votes |
/**
* Handle "LWT" Last Will and Testament messages from Tasmota
* These are sent when the device is no longer available from the MQTT server.
*/
availabilityUpdate(topic, message) {
// debug("availabilityUpdate", this, topic, message.toString());
this.platform.log.info('Marking accessory \'%s\' to %s', this.service.displayName, message);
if (message.toString() === this.accessory.context.device[this.uniq_id].pl_not_avail) {
const availability: Nullable<CharacteristicValue> | Error = new Error(this.accessory.displayName + ' ' + message.toString());
this.characteristic.updateValue(availability);
} else {
// debug("availabilityUpdate", this.characteristic);
this.characteristic.updateValue(this.characteristic.value);
}
}
Example #5
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 #6
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 #7
Source File: index.ts From homebridge-electrolux-wellbeing with Apache License 2.0 | 6 votes |
async sendCommand(
pncId: string,
command: string,
value: CharacteristicValue,
) {
this.log.debug('sending command', {
[command]: value,
});
try {
const response = await this.client!.put(`/Appliances/${pncId}/Commands`, {
[command]: value,
});
this.log.debug('command responded', response.data);
} catch (err) {
this.log.info('Could run command', err);
}
}
Example #8
Source File: platformAccessory.ts From homebridge-iRobot with Apache License 2.0 | 6 votes |
/**
* Handle the "GET" requests from HomeKit
* These are sent when HomeKit wants to know the current state of the accessory, for example, checking if a Light bulb is on.
*
* GET requests should return as fast as possbile. A long delay here will result in
* HomeKit being unresponsive and a bad user experience in general.
*
* If your device takes time to respond you should update the status of your device
* asynchronously instead using the `updateCharacteristic` method instead.
* @example
* this.service.updateCharacteristic(this.platform.Characteristic.On, true)
*/
async get(): Promise<CharacteristicValue> {
if (this.accessory.context.connected) {
this.platform.log.debug('Updating', this.device.name, 'To', this.active ? 'On' : 'Off');
return this.active ? 1 : 0;
} else {
throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
}
}
Example #9
Source File: platformAccessory.ts From homebridge-plugin-template 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.
*/
async setOn(value: CharacteristicValue) {
// implement your own code to turn your device on/off
this.exampleStates.On = value as boolean;
this.platform.log.debug('Set Characteristic On ->', value);
}
Example #10
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 #11
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 #12
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 #13
Source File: AirConditionerAccessory.d.ts From homebridge-tuya-ir with Apache License 2.0 | 6 votes |
/**
* Handle the "GET" requests from HomeKit
* These are sent when HomeKit wants to know the current state of the accessory, for example, checking if a Light bulb is on.
*
* GET requests should return as fast as possbile. A long delay here will result in
* HomeKit being unresponsive and a bad user experience in general.
*
* If your device takes time to respond you should update the status of your device
* asynchronously instead using the `updateCharacteristic` method instead.
* @example
* this.service.updateCharacteristic(this.platform.Characteristic.On, true)
*/
getOn(): Promise<CharacteristicValue>;
Example #14
Source File: CameraAccessory.ts From homebridge-eufy-security with Apache License 2.0 | 6 votes |
async handleMotionDetectedGet(): Promise<CharacteristicValue> {
try {
const currentValue = this.Camera.getPropertyValue(PropertyName.DeviceMotionDetected);
this.platform.log.debug(this.accessory.displayName, 'GET DeviceMotionDetected:', currentValue);
return currentValue.value as boolean;
} catch {
this.platform.log.error(this.accessory.displayName, 'handleMotionDetectedGet', 'Wrong return value');
return false;
}
}
Example #15
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 #16
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 #17
Source File: accessory.ts From homebridge-vieramatic with Apache License 2.0 | 5 votes |
private configureInputSource(type: InputType, configuredName: string, identifier: number): void {
const fn = (element: HdmiInput): boolean => element.id === identifier.toString()
const visibility = (): string => {
let idx: number
let hidden: number
const { inputs } = this.storage.data
switch (type) {
case 'HDMI':
idx = inputs.hdmi.findIndex((x: HdmiInput) => fn(x))
// by default all hdmiInputs will be visible
hidden = inputs.hdmi[idx].hidden ?? 0
break
case 'APPLICATION':
idx = identifier - 1000
// by default all apps will be hidden
hidden = inputs.applications[idx].hidden ?? 1
break
// case 'TUNER':
default:
// by default TUNER is visible
hidden = inputs.TUNER.hidden ?? 0
}
return hidden.toFixed(0)
}
const source = this.accessory.addService(
this.Service.InputSource,
configuredName.toLowerCase().replace(/\s/gu, ''),
identifier
)
const visibilityState = (state: CharacteristicValue): void => {
let idx: number
const id = source.getCharacteristic(this.Characteristic.Identifier).value ?? 500
const { inputs } = this.storage.data
switch (true) {
case id < 100:
// hdmi input
idx = inputs.hdmi.findIndex((x: HdmiInput) => fn(x))
inputs.hdmi[idx].hidden = state as InputVisibility
break
case id > 999:
// APP
idx = (id as number) - 1000
inputs.applications[idx].hidden = state as InputVisibility
break
// case id === 500:
default:
inputs.TUNER.hidden = state as InputVisibility
break
}
source.updateCharacteristic(this.Characteristic.CurrentVisibilityState, state)
}
const hidden = visibility()
source
.setCharacteristic(
this.Characteristic.InputSourceType,
this.Characteristic.InputSourceType[type]
)
.setCharacteristic(this.Characteristic.CurrentVisibilityState, hidden)
.setCharacteristic(this.Characteristic.TargetVisibilityState, hidden)
.setCharacteristic(this.Characteristic.Identifier, identifier)
.setCharacteristic(this.Characteristic.ConfiguredName, configuredName)
.setCharacteristic(
this.Characteristic.IsConfigured,
this.Characteristic.IsConfigured.CONFIGURED
)
source.getCharacteristic(this.Characteristic.TargetVisibilityState).onSet(visibilityState)
const svc = this.accessory.getService(this.Service.Television)
if (svc) svc.addLinkedService(source)
}
Example #18
Source File: index.ts From homebridge-philips-air with BSD 2-Clause "Simplified" License | 5 votes |
async setPower(accessory: PlatformAccessory, state: CharacteristicValue): Promise<void> {
const purifier = this.purifiers.get(accessory.displayName);
if (purifier) {
const values = {
pwr: (state as boolean).toString()
};
try {
const status: PurifierStatus = await purifier.client?.getStatus();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
purifier.laststatus = Date.now();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await this.storeKey(purifier);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
let water_level = 100;
if (status.func == 'PH' && status.wl == 0) {
water_level = 0;
}
const purifierService = accessory.getService(hap.Service.AirPurifier);
if (purifierService) {
purifierService.updateCharacteristic(hap.Characteristic.CurrentAirPurifierState, state as number * 2);
}
if (purifier.config.humidifier) {
if (water_level == 0) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
values['func'] = 'P';
}
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await this.enqueuePromise(CommandType.SetData, purifier, values);
if (purifier.config.light_control) {
const lightsService = accessory.getService('Lights');
if (lightsService) {
if (state) {
lightsService
.updateCharacteristic(hap.Characteristic.On, status.aqil > 0)
.updateCharacteristic(hap.Characteristic.Brightness, status.aqil);
} else {
lightsService
.updateCharacteristic(hap.Characteristic.On, 0)
.updateCharacteristic(hap.Characteristic.Brightness, 0);
}
}
}
if (purifier.config.humidifier) {
const Humidifier = accessory.getService('Humidifier');
let state_ph = 0;
if (status.func == 'PH' && water_level == 100) {
state_ph = 1;
}
if (Humidifier) {
Humidifier.updateCharacteristic(hap.Characteristic.TargetHumidifierDehumidifierState, 1);
if (state) {
Humidifier
.updateCharacteristic(hap.Characteristic.Active, state_ph)
.updateCharacteristic(hap.Characteristic.CurrentHumidifierDehumidifierState, state_ph * 2);
} else {
Humidifier
.updateCharacteristic(hap.Characteristic.Active, 0)
.updateCharacteristic(hap.Characteristic.CurrentHumidifierDehumidifierState, 0)
.updateCharacteristic(hap.Characteristic.RelativeHumidityHumidifierThreshold, 0);
}
}
}
} catch (err) {
this.log.error('[' + purifier.config.name + '] Error setting power: ' + err);
}
}
}
Example #19
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 #20
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);
}
Example #21
Source File: platformAccessory.ts From homebridge-iRobot with Apache License 2.0 | 5 votes |
async getState(): Promise<CharacteristicValue> {
if (this.accessory.context.connected) {
this.platform.log.debug('Updating', this.device.name, 'Mode To', this.state === 0 ? 'Off' : this.state === 1 ? 'Idle' : 'On');
return this.state;
} else {
throw new this.platform.api.hap.HapStatusError(this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE);
}
}
Example #22
Source File: platformAccessory.ts From homebridge-konnected with MIT License | 5 votes |
/**
* Handle the "GET" & "SET" requests from HomeKit
*/
async getSecuritySystemCurrentState(): Promise<CharacteristicValue> {
const state = this.getSecuritySystemState('current');
return state as number;
}