-
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.
- Loading branch information
1 parent
bd3c4cb
commit 474d29d
Showing
7 changed files
with
92 additions
and
56 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
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 |
---|---|---|
@@ -1,25 +1,13 @@ | ||
import dotenv from 'dotenv'; | ||
import { filter, take, tap } from 'rxjs/operators'; | ||
import { filter, switchMap, take, tap } from 'rxjs/operators'; | ||
import { HomeAssistantRXJS } from '../lib'; | ||
|
||
dotenv.config(); | ||
const host = process.env.HOST ?? 'http://homeassistant:8123'; | ||
const token = process.env.ACCESS_TOKEN; | ||
|
||
if (!token) { | ||
throw new Error( | ||
'No access token (SUPERVISOR_TOKEN or ACCESS_TOKEN) found in environment variables.', | ||
); | ||
} | ||
|
||
console.log(`Initializing HA with ${token} at ${host}`); | ||
const harxjs = new HomeAssistantRXJS(host, token); | ||
const harxjs = new HomeAssistantRXJS(); | ||
|
||
harxjs.services$ | ||
.pipe( | ||
filter(config => Object.keys(config).length > 0), | ||
filter(x => !!x), | ||
take(1), | ||
tap(console.log), | ||
tap(() => harxjs.destroy()), | ||
tap(x => console.log('connected')), | ||
switchMap(() => harxjs.destroy()), | ||
) | ||
.subscribe(); |
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
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