Skip to content

Commit

Permalink
Add experimental support for eltako_fhk
Browse files Browse the repository at this point in the history
  • Loading branch information
awaescher committed Jan 8, 2024
1 parent bb2a636 commit 48cbafc
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/EltakoBlindsAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class EltakoBlindsAccessory implements IUpdatableAccessory {

// https://developers.homebridge.io/#/service/WindowCovering
const serviceType = this.platform.Service.WindowCovering;

this.service = this.accessory.getService(serviceType) || this.accessory.addService(serviceType);

this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
Expand Down
1 change: 0 additions & 1 deletion src/EltakoDimmerAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class EltakoDimmerAccessory implements IUpdatableAccessory {

// https://developers.homebridge.io/#/service/Lightbulb
const serviceType = this.platform.Service.Lightbulb;

this.service = this.accessory.getService(serviceType) || this.accessory.addService(serviceType);

this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
Expand Down
1 change: 0 additions & 1 deletion src/EltakoSwitchAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class EltakoSwitchAccessory implements IUpdatableAccessory {
// https://developers.homebridge.io/#/service/Lightbulb
// https://developers.homebridge.io/#/service/Switch
const serviceType = accessory.context.device.info._target === 'light' ? this.platform.Service.Lightbulb : this.platform.Service.Switch;

this.service = this.accessory.getService(serviceType) || this.accessory.addService(serviceType);

this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
Expand Down
71 changes: 71 additions & 0 deletions src/EltakoThermostatAccessory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
import { EltakoMiniSafe2Platform } from './platform';
import { IUpdatableAccessory } from './IUpdatableAccessory';

export class EltakoThermostatAccessory implements IUpdatableAccessory {
private service: Service;

constructor(
private readonly platform: EltakoMiniSafe2Platform,
public readonly accessory: PlatformAccessory,
) {

this.accessory.getService(this.platform.Service.AccessoryInformation)!
.setCharacteristic(this.platform.Characteristic.Manufacturer, accessory.context.device.info.vendor)
.setCharacteristic(this.platform.Characteristic.Model, accessory.context.device.info.data)
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.device.info.address);

// https://developers.homebridge.io/#/service/Thermostat
const serviceType = this.platform.Service.Thermostat;
this.service = this.accessory.getService(serviceType) || this.accessory.addService(serviceType);

this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);

this.service.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
.onGet(this.getCurrentTemperature.bind(this));

this.service.getCharacteristic(this.platform.Characteristic.CurrentHeatingCoolingState)
.onGet(this.getCurrentHeatingCoolingState.bind(this));

this.service.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits)
.onGet(this.getTemperatureDisplayUnits.bind(this));
}

getCurrentTemperature(): CharacteristicValue {
const state = this.platform.deviceStateCache.find(s => s.sid === this.accessory.context.device.info.sid);
return state?.state?.temperature ?? 0;
}

getCurrentHeatingCoolingState(): CharacteristicValue {

const state = this.platform.deviceStateCache.find(s => s.sid === this.accessory.context.device.info.sid);
const mode = state?.state?.operation_mode ?? '';

// return OFF/HEAT/COOL
// possible states? What about COOL?!

if (mode === 'off') {
return this.platform.Characteristic.CurrentHeatingCoolingState.OFF;
}

return this.platform.Characteristic.CurrentHeatingCoolingState.HEAT;
}

getTemperatureDisplayUnits(): CharacteristicValue {
return this.platform.Characteristic.TemperatureDisplayUnits.CELSIUS;
}

update() {
this.service
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
.updateValue(this.getCurrentTemperature());

this.service
.getCharacteristic(this.platform.Characteristic.CurrentHeatingCoolingState)
.updateValue(this.getCurrentHeatingCoolingState());

this.service
.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits)
.updateValue(this.getTemperatureDisplayUnits());
}
}
1 change: 1 addition & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class DeviceState {
s3?: number;
level?: number;
state?: string;
operation_mode?: string;
}

export interface Device {
Expand Down
9 changes: 9 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MiniSafe2Api } from './MiniSafe2Api';
import { Device } from './models';
import { getChangedDeviceAddresses } from './StateChangeDetector';
import { IUpdatableAccessory } from './IUpdatableAccessory';
import { EltakoThermostatAccessory } from './EltakoThermostatAccessory';

/**
* HomebridgePlatform
Expand Down Expand Up @@ -189,6 +190,10 @@ export class EltakoMiniSafe2Platform implements DynamicPlatformPlugin {
instance = new EltakoLightSensorAccessory(this, existingAccessory);
break;
}
case 'eltako_fhk': {
instance = new EltakoThermostatAccessory(this, existingAccessory);
break;
}
}

if (instance) {
Expand Down Expand Up @@ -238,6 +243,10 @@ export class EltakoMiniSafe2Platform implements DynamicPlatformPlugin {
instance = new EltakoLightSensorAccessory(this, accessory);
break;
}
case 'eltako_fhk': {
instance = new EltakoThermostatAccessory(this, accessory);
break;
}
}

if (instance) {
Expand Down

0 comments on commit 48cbafc

Please sign in to comment.