Skip to content

Commit

Permalink
Merge pull request #117 from home-assistant/add-state-to-hass-config
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored May 28, 2020
2 parents b9fa5c1 + ef670b2 commit 4f378db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function processComponentLoaded(
if (state === undefined) return null;

return {
components: state.components.concat(event.data.component)
components: state.components.concat(event.data.component),
};
}

Expand All @@ -29,10 +29,10 @@ const subscribeUpdates = (conn: Connection, store: Store<HassConfig>) =>
"component_loaded"
),
conn.subscribeEvents(
() => fetchConfig(conn).then(config => store.setState(config, true)),
() => fetchConfig(conn).then((config) => store.setState(config, true)),
"core_config_updated"
)
]).then(unsubs => () => unsubs.forEach(unsub => unsub()));
),
]).then((unsubs) => () => unsubs.forEach((unsub) => unsub()));

const configColl = (conn: Connection) =>
getCollection(conn, "_cnf", fetchConfig, subscribeUpdates);
Expand All @@ -41,3 +41,9 @@ export const subscribeConfig = (
conn: Connection,
onChange: (state: HassConfig) => void
): UnsubscribeFunc => configColl(conn).subscribe(onChange);

export const STATE_NOT_RUNNING = "NOT_RUNNING";
export const STATE_STARTING = "STARTING";
export const STATE_RUNNING = "RUNNING";
export const STATE_STOPPING = "STOPPING";
export const STATE_FINAL_WRITE = "FINAL_WRITE";
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type HassConfig = {
version: string;
config_source: string;
safe_mode: boolean;
state: "NOT_RUNNING" | "STARTING" | "RUNNING" | "STOPPING" | "FINAL_WRITE";
external_url: string | null;
internal_url: string | null;
};
Expand Down

0 comments on commit 4f378db

Please sign in to comment.