Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

huttotw
Copy link
Owner

@huttotw huttotw commented Mar 13, 2024

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.

@@ -28,6 +28,23 @@
"type": "string",
"required": true
},
"ignitionOnDuration": {
Copy link
Owner Author

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(
Copy link
Owner Author

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(
Copy link
Owner Author

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 = {
Copy link
Owner Author

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);
Copy link
Owner Author

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);
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant