-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
system to make adding configuration easy #11
base: master
Are you sure you want to change the base?
Conversation
@@ -28,6 +28,23 @@ | |||
"type": "string", | |||
"required": true | |||
}, | |||
"ignitionOnDuration": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will always need to add any new configuration option to this file. This is what Homebridge uses to create the UI.
@@ -69,7 +69,16 @@ export class Platform implements DynamicPlatformPlugin { | |||
|
|||
// create the accessory handler for the restored accessory | |||
// this is imported from `platformAccessory.ts` | |||
new Car(this, existingAccessory, this.kiaConnect, car.name, car.vin, car.targetTemperature, car.refreshInterval); | |||
new Car( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will pass all other fields in the car object from the configuration to new Car
. This will ensure that the Car
class is receiving everything, it will just be up to us to interpret it.
@@ -84,7 +93,17 @@ export class Platform implements DynamicPlatformPlugin { | |||
|
|||
// create the accessory handler for the newly create accessory | |||
// this is imported from `platformAccessory.ts` | |||
new Car(this, accessory, this.kiaConnect, car.name, car.vin, car.targetTemperature, car.refreshInterval); | |||
new Car( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here!
import { KiaConnect } from './kiaconnect/client'; | ||
|
||
type CarConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a typed version of what we expect.
) { | ||
// Initialize config to default values | ||
this.config = initializeConfig(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will take the input from the user specified config, and make sure every option is either set to the user provided value, or some default.
@@ -287,7 +296,7 @@ export class Car { | |||
if (value) { | |||
// Turn on the engine | |||
this.platform.log.info('Turning on the engine'); | |||
xid = await this.kiaConnect.startClimate(this.vin, this.targetTemperature); | |||
xid = await this.kiaConnect.startClimate(this.vin, this.config.targetTemperature, this.config.ignitionOnDuration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use this.config
anywhere where we would want a user-overidable value.
This adds some plumbing to make adding more configuration options easier. If this seems okay, I'll add some tests for sane defaults and provide some more complicated examples of how we can enable / disable sensors for instance.