generated from homebridge/homebridge-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup; Add accessory config; Add internal temperature
- Loading branch information
1 parent
8a92044
commit b843446
Showing
10 changed files
with
226 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,4 +117,6 @@ dist | |
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.pnp.* | ||
.pnp.* | ||
|
||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Service, PlatformAccessory } from 'homebridge'; | ||
import { HomebridgeSems } from './platform'; | ||
import { PowerStationAccessory } from './powerStationAccessory'; | ||
import { dig } from 'dig-ts'; | ||
|
||
|
||
export class ElectricityWattAccessory extends PowerStationAccessory { | ||
private service: Service; | ||
|
||
constructor( | ||
private readonly platform: HomebridgeSems, | ||
private readonly accessory: PlatformAccessory, | ||
) { | ||
super(); | ||
// set accessory information TODO: add model and serialnumber! | ||
this.accessory.getService(this.platform.Service.AccessoryInformation)! | ||
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'GoodWe') | ||
.setCharacteristic(this.platform.Characteristic.Model, 'model') | ||
.setCharacteristic(this.platform.Characteristic.SerialNumber, 'sn'); | ||
|
||
this.service = this.accessory.getService(this.platform.Service.LightSensor) || | ||
this.accessory.addService(this.platform.Service.LightSensor); | ||
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name); | ||
|
||
this.update(accessory.context.device.data); | ||
} | ||
|
||
async update(powerStationData) { | ||
let value = dig(powerStationData, this.accessory.context.device.dataDigPath).get() as number; | ||
const multiplier = this.accessory.context.device.multiplier; | ||
if(multiplier) { | ||
value = value * multiplier; | ||
} | ||
this.setValue(value); | ||
} | ||
|
||
setValue(value) { | ||
this.platform.log.info('New value', this.accessory.context.device.name, value); | ||
if(value < 0.0001) { | ||
value = 0.0001; | ||
} | ||
this.service.getCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel).updateValue(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { API } from 'homebridge'; | ||
|
||
import { PLATFORM_NAME } from './settings'; | ||
import { HomeBridgeSems } from './platform'; | ||
import { HomebridgeSems } from './platform'; | ||
|
||
/** | ||
* This method registers the platform with Homebridge | ||
*/ | ||
export = (api: API) => { | ||
api.registerPlatform(PLATFORM_NAME, HomeBridgeSems); | ||
api.registerPlatform(PLATFORM_NAME, HomebridgeSems); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.