diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..2c29499 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node +{ + "name": "Homebridge", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "homebridge/homebridge:latest", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [8581], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "npm install && npm link" + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f33a02c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.gitignore b/.gitignore index 70882ca..5440541 100644 --- a/.gitignore +++ b/.gitignore @@ -121,3 +121,5 @@ dist # Webstorm .idea + +.homebridge \ No newline at end of file diff --git a/nodemon.json b/nodemon.json index 6dd7df6..220d46f 100644 --- a/nodemon.json +++ b/nodemon.json @@ -1,12 +1,10 @@ { - "watch": [ - "src" - ], + "watch": ["src"], "ext": "ts", "ignore": [], - "exec": "tsc && homebridge -I -D", + "exec": "tsc && homebridge -I -D -U ./.homebridge", "signal": "SIGTERM", "env": { "NODE_OPTIONS": "--trace-warnings" } -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index 8e3e44e..693ac53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1", "license": "Apache-2.0", "dependencies": { - "tesla-fleet-api": "^0.0.8" + "tesla-fleet-api": "^0.0.10" }, "devDependencies": { "@types/node": "^20.12.13", @@ -3139,9 +3139,9 @@ } }, "node_modules/tesla-fleet-api": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/tesla-fleet-api/-/tesla-fleet-api-0.0.8.tgz", - "integrity": "sha512-y83Pkp2mpGU+nolixwdgXYcrOdcefYvGE43pMed5pkrlPTM/ouFTT91UbizIfWy2E5XKI1u6I4DYJMORoQ51Ww==" + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/tesla-fleet-api/-/tesla-fleet-api-0.0.10.tgz", + "integrity": "sha512-2l51RoarovxsG5tUokuvHIweJ/Ie+GqNLJfYphEUQxnmKxFdF+UmmHgo37d8n9Pp2zbd5inMwTwLSvl1jH67cg==" }, "node_modules/text-table": { "version": "0.2.0", diff --git a/package.json b/package.json index 9b2a113..638b431 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,6 @@ "typescript": "^5.4.5" }, "dependencies": { - "tesla-fleet-api": "^0.0.8" + "tesla-fleet-api": "^0.0.10" } } diff --git a/src/settings.ts b/src/settings.ts index 133c1f0..27a02b7 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -7,3 +7,5 @@ export const PLATFORM_NAME = "Teslemetry"; * This must match the name of your plugin as defined the package.json */ export const PLUGIN_NAME = "homebridge-teslemetry"; + +export const REFRESH_INTERVAL = 30000; diff --git a/src/vehicle.ts b/src/vehicle.ts index e5f015a..3bd52a4 100644 --- a/src/vehicle.ts +++ b/src/vehicle.ts @@ -2,6 +2,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from "homebridge"; import VehicleSpecific from "tesla-fleet-api/dist/vehiclespecific.js"; import { TeslaFleetApiPlatform } from "./platform.js"; +import { REFRESH_INTERVAL } from "./settings.js"; /** * Platform Accessory @@ -24,8 +25,6 @@ export class VehicleAccessory { private readonly platform: TeslaFleetApiPlatform, private readonly accessory: PlatformAccessory ) { - // set accessory information - if (!this.platform.TeslaFleetApi?.vehicle) { throw new Error("TeslaFleetApi not initialized"); } @@ -46,6 +45,9 @@ export class VehicleAccessory { this.accessory.context.vin ); + this.refresh(); + setInterval(() => this.refresh(), REFRESH_INTERVAL); + // get the LightBulb service if it exists, otherwise create a new LightBulb service // you can create multiple services for each accessory this.service = @@ -131,6 +133,39 @@ export class VehicleAccessory { }, 10000);*/ } + async refresh() { + this.VehicleSpecific.vehicle_data([ + "charge_state", + "climate_state", + "drive_state", + "location_data", + "vehicle_state", + ]) + .then( + ({ + response: { charge_state, climate_state, drive_state, vehicle_state }, + }) => { + this.accessory.context.data = { + charge_state, + climate_state, + drive_state, + vehicle_state, + }; + this.service.updateCharacteristic( + this.platform.Characteristic.Active, + true + ); + } + ) + .catch((error) => { + this.platform.log.warn(error); + this.service.updateCharacteristic( + this.platform.Characteristic.Active, + false + ); + }); + } + /** * Handle "SET" requests from HomeKit * These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.