Ejemplo n.º 1
0
        /// <summary>
        /// Creates an instance of a Home Assistant hub which will use MQTT state stream
        /// (cf. <seealso cref="https://www.home-assistant.io/components/mqtt_statestream/"/>) to read states of devices,
        /// and the REST API (cf. <seealso cref="https://developers.home-assistant.io/docs/en/external_api_rest.html"/>)
        /// to write state / execute services on the hub.
        /// </summary>
        /// <param name="scheduler">The scheduler used to run scripts, automations and manage devices of this Home Assistant</param>
        /// <param name="apiHostName">The host name (and port) of the Home Assistant API (&lt;host&gt;[:port])</param>
        /// <param name="apiPassword">The API password defined in Home Assistant configuration</param>
        /// <param name="mqtt">A client to the MQTT broker used by Home Assistant</param>
        /// <param name="homeTopic">Defines the base topic that will be used for to publish scenes and automations</param>
        /// <param name="hassTopic">Defines the base topic used by home assistant state stream</param>
        public HomeAssistantHub(
            IScheduler scheduler,
            string apiHostName,
            string apiPassword,
            MqttClient mqtt,
            string homeTopic = DefaultHomeTopic,
            string hassTopic = DefaultTopic)
        {
            homeTopic = homeTopic.Trim('/', '#', '*');
            hassTopic = hassTopic.Trim('/', '#', '*');

            var api             = new HomeAssistantApi(apiHostName, apiPassword);
            var mqttStateStream = new HomeAssistantDeviceHost(mqtt, hassTopic, api, scheduler);

            Devices     = new HomeDevicesManager(mqttStateStream);
            Scenes      = new MqttSceneHost(mqtt, homeTopic, scheduler);
            Automations = new MqttAutomationHost(mqtt, homeTopic, scheduler);
            Api         = api;
        }
Ejemplo n.º 2
0
        public HomeAssistantHub(
            IScheduler scheduler,
            string apiHostName,
            string apiToken,
            MqttClient mqtt,
            string homeTopic = DefaultHomeTopic,
            string hassTopic = DefaultTopic)
        {
            homeTopic = homeTopic.Trim('/', '#', '*');
            hassTopic = hassTopic.Trim('/', '#', '*');

            var api = new HomeAssistantHttpApi(apiHostName, apiToken);

            _mqttStateStream = new HomeAssistantDeviceHost(mqtt, hassTopic, api, scheduler);

            Devices     = new HomeDevicesManager(_mqttStateStream);
            Scenes      = new MqttSceneHost(mqtt, homeTopic, scheduler);
            Automations = new MqttAutomationHost(mqtt, homeTopic, scheduler);
            Api         = api;

            _ws = new HomeAssistantWebSocketApi(new Uri($"ws://{apiHostName}"), apiToken);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an instance of a Zigbee 2 MQTT hub
        /// </summary>
        /// <param name="mqtt">A client to the MQTT broker used by Zigbee 2 MQTT</param>
        /// <param name="scheduler">The scheduler used to run scripts, automations and manage devices of this Home Assistant</param>
        public Zigbee2MqttHub(MqttClient mqtt, IScheduler scheduler, string topic = DefaultTopic)
        {
            var deviceHost = new Zigbee2MqttDeviceHost(mqtt, topic, scheduler);

            Devices = new HomeDevicesManager(deviceHost);
        }