diff --git a/README.md b/README.md index 281bb52..a7146f1 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Devices commonly consist of multiple services: for example, a presence sensor mi Some services are more common than others. Some are deprecated entirely. todo periodical refresh of devices -todo periodical refresh of state +todo links to the .ts service implementations below | Service | Example device | Implementation status | | --- | --- | --- | diff --git a/futurehome/src/index.ts b/futurehome/src/index.ts index 4b5de41..beea1e0 100644 --- a/futurehome/src/index.ts +++ b/futurehome/src/index.ts @@ -175,15 +175,20 @@ import { delay } from "./utils"; } }); + const pollState = () => { + sendFimpMsg({ + address: '/rt:app/rn:vinculum/ad:1', + service: 'vinculum', + cmd: 'cmd.pd7.request', + val: { cmd: "get", component: null, param: { components: ['state'] } }, + val_t: 'object', + timeoutMs: 30000, + }).catch(e => log.warn("Failed to request state", e)); + }; // Request initial state - await sendFimpMsg({ - address: '/rt:app/rn:vinculum/ad:1', - service: 'vinculum', - cmd: 'cmd.pd7.request', - val: { cmd: "get", component: null, param: { components: ['state'] } }, - val_t: 'object', - timeoutMs: 30000, - }); + pollState(); + // Then poll every 30 seconds + setInterval(pollState, 30000); ha.on('message', (topic, buf) => { // Handle Home Assistant command messages