mirror of
https://github.com/adrianjagielak/home-assistant-futurehome.git
synced 2025-09-13 15:47:08 +00:00
Get HA MQTT Broker values from bashio
This commit is contained in:
parent
15e74690fa
commit
206140f922
@ -1,6 +1,6 @@
|
|||||||
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
|
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
|
||||||
name: Futurehome
|
name: Futurehome
|
||||||
version: "0.0.6"
|
version: "0.0.7"
|
||||||
slug: futurehome
|
slug: futurehome
|
||||||
description: Local Futurehome Smarthub integration
|
description: Local Futurehome Smarthub integration
|
||||||
url: "https://github.com/adrianjagielak/home-assistant-futurehome"
|
url: "https://github.com/adrianjagielak/home-assistant-futurehome"
|
||||||
|
@ -8,6 +8,12 @@ set -e
|
|||||||
export FH_HUB_IP=$(bashio::config 'hub_ip')
|
export FH_HUB_IP=$(bashio::config 'hub_ip')
|
||||||
export FH_USERNAME=$(bashio::config 'username')
|
export FH_USERNAME=$(bashio::config 'username')
|
||||||
export FH_PASSWORD=$(bashio::config 'password')
|
export FH_PASSWORD=$(bashio::config 'password')
|
||||||
|
|
||||||
|
export MQTT_HOST=$(bashio::services mqtt "host")
|
||||||
|
export MQTT_PORT=$(bashio::services mqtt "port")
|
||||||
|
export MQTT_USER=$(bashio::services mqtt "username")
|
||||||
|
export MQTT_PWD=$(bashio::services mqtt "password")
|
||||||
|
|
||||||
export LOG_LEVEL=${LOG_LEVEL:-info}
|
export LOG_LEVEL=${LOG_LEVEL:-info}
|
||||||
|
|
||||||
/usr/bin/node /usr/src/app/dist/index.js
|
/usr/bin/node /usr/src/app/dist/index.js
|
||||||
|
@ -2,17 +2,17 @@ import mqtt, { MqttClient } from "mqtt";
|
|||||||
|
|
||||||
export function connectHub(opts: { hubIp: string; username: string; password: string; }): Promise<MqttClient> {
|
export function connectHub(opts: { hubIp: string; username: string; password: string; }): Promise<MqttClient> {
|
||||||
const url = `mqtt://${opts.hubIp || "futurehome-smarthub.local"}`;
|
const url = `mqtt://${opts.hubIp || "futurehome-smarthub.local"}`;
|
||||||
return makeClient(url, opts.username, opts.password);
|
return makeClient(url, 1884, opts.username, opts.password);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function connectHA(): Promise<MqttClient> {
|
export function connectHA(opts: { mqttHost: string; mqttPort: number; mqttUsername: string; mqttPassword: string; }): Promise<MqttClient> {
|
||||||
const url = "mqtt://homeassistant";
|
const url = `mqtt://${opts.mqttHost}`;
|
||||||
return makeClient(url);
|
return makeClient(url, opts.mqttPort, opts.mqttUsername, opts.mqttPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeClient(url: string, username = "", password = ""): Promise<MqttClient> {
|
function makeClient(url: string, port: number, username: string, password: string): Promise<MqttClient> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const client = mqtt.connect(url, { username, password, protocolVersion: 4 });
|
const client = mqtt.connect(url, { port, username, password, protocolVersion: 4 });
|
||||||
client.once("connect", () => resolve(client));
|
client.once("connect", () => resolve(client));
|
||||||
client.once("error", reject);
|
client.once("error", reject);
|
||||||
});
|
});
|
||||||
|
@ -6,8 +6,14 @@ import { publishDiscovery } from "./discovery";
|
|||||||
const user = process.env.FH_USERNAME || "";
|
const user = process.env.FH_USERNAME || "";
|
||||||
const pass = process.env.FH_PASSWORD || "";
|
const pass = process.env.FH_PASSWORD || "";
|
||||||
|
|
||||||
|
const mqttHost = process.env.MQTT_HOST || "";
|
||||||
|
const mqttPort = Number(process.env.MQTT_PORT || "1883");
|
||||||
|
const mqttUsername = process.env.MQTT_USER || "";
|
||||||
|
const mqttPassword = process.env.MQTT_PWD || "";
|
||||||
|
|
||||||
|
|
||||||
// 1) Connect to HA broker (for discovery + state)
|
// 1) Connect to HA broker (for discovery + state)
|
||||||
const ha = await connectHA();
|
const ha = await connectHA({ mqttHost, mqttPort, mqttUsername, mqttPassword, });
|
||||||
|
|
||||||
// 2) Connect to Futurehome hub (FIMP traffic)
|
// 2) Connect to Futurehome hub (FIMP traffic)
|
||||||
const fimp = await connectHub({ hubIp, username: user, password: pass });
|
const fimp = await connectHub({ hubIp, username: user, password: pass });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user