UNPKG

homebridge-smartsystem

Version:

SmartServer (Proxy Websockets to TCP sockets, Smappee MQTT, Duotecno IP Nodes, Homekit interface)

49 lines (37 loc) 1.49 kB
import { Accessory } from "./accessory"; import { log } from "../duotecno/logger"; import { Unit } from "../duotecno/protocol"; import { API } from "homebridge"; // Johan Coppieters Jan 2019 // // Temperature Sensor // - only has a "get", not sure if homekit likes this. // export class Temperature extends Accessory { constructor(homebridge: API, unit: Unit) { super(homebridge, unit); } getAccessoryServices() { const temperatureService = this.makeService(this.homebridge.Service.TemperatureSensor); temperatureService .getCharacteristic(this.homebridge.Characteristic.CurrentTemperature) .setProps({ minValue: -100, maxValue: 100 }) .on('get', this.getTemperature.bind(this)); return [temperatureService]; } getTemperature(next) { if (this.unit) { this.unit.reqState(unit => { log("accessory", "reqState/getTemperature returned a value for " + this.unit.node.getName() + " - " + this.unit.getName() + " -> " + this.unit.value); next(null, <number>unit.value / 10.0); }) .catch(err => next(err)); } else { next( new Error("accessory -> getTemperature needs a unit.") ); } } updateState() { this.me.getCharacteristic(this.homebridge.Characteristic.CurrentTemperature).updateValue((<number>this.unit.value) / 10.0); // log("accessory", "Received updateState -> Homekit Temperature -> " + this.unit.getName() + " -> temp = " +(<number>this.unit.value) / 10.0); } }