Example #1
0
        public void Initialize(IClientDeviceConnection brokerConnection)
        {
            // Creating a air conditioner device.
            _clientDevice = DeviceFactory.CreateClientDevice("air-conditioner");

            // Creating properties.
            _turnOnOfProperty = _clientDevice.CreateClientChoiceProperty(new ClientPropertyMetadata {
                PropertyType = PropertyType.Command, NodeId = "general", PropertyId = "turn-on-off", Format = "ON,OFF"
            });
            _actualState = _clientDevice.CreateClientChoiceProperty(new ClientPropertyMetadata {
                PropertyType = PropertyType.State, NodeId = "general", PropertyId = "actual-state", Format = "ON,OFF,STARTING", InitialValue = "OFF"
            });
            _actualState.PropertyChanged += (sender, e) => {
                _log.Info($"{_clientDevice.DeviceId}: property {_actualState.PropertyId} changed to {_actualState.Value}.");
            };

            _inletTemperature = _clientDevice.CreateClientNumberProperty(new ClientPropertyMetadata {
                PropertyType = PropertyType.State, NodeId = "general", PropertyId = "actual-air-temperature", DataType = DataType.Float, InitialValue = "0"
            });
            _inletTemperature.PropertyChanged += (sender, e) => {
                // Simulating some overheated dude.
                if (_inletTemperature.Value > 25)
                {
                    _log.Info($"{_clientDevice.Name}: getting hot in here, huh?.. Let's try turning air conditioner on.");
                    if (_actualState.Value != "ON")
                    {
                        _turnOnOfProperty.Value = "ON";
                    }
                }
            };

            // Initializing all the Homie stuff.
            _clientDevice.Initialize(brokerConnection);
        }
Example #2
0
        public void CreateClientDeviceWithIncorrectId()
        {
            foreach (var badTopicLevel in CommonStuff.BadTopicLevels)
            {
                Assert.That(() => DeviceFactory.CreateClientDevice(badTopicLevel), Throws.ArgumentException);
            }

            foreach (var goodTopicLevel in CommonStuff.GoodTopicLevels)
            {
                Assert.DoesNotThrow(() => DeviceFactory.CreateClientDevice(goodTopicLevel));
            }
        }
Example #3
0
        public void Initialize(IClientDeviceConnection brokerConnection, ClientDeviceMetadata deviceMetadata)
        {
            _clientDevice = DeviceFactory.CreateClientDevice(deviceMetadata);

            for (var i = 0; i < _clientDevice.Nodes.Length; i++)
            {
                Debug.Print($"Iterating over nodes. Currently: \"{_clientDevice.Nodes[i].Name}\" with {_clientDevice.Nodes[i].Properties.Length} properties.");

                foreach (var property in _clientDevice.Nodes[i].Properties)
                {
                    property.PropertyChanged += (sender, e) => {
                        Debug.WriteLine($"Value of property \"{property.Name}\" changed to \"{property.RawValue}\".");
                    };
                }
            }

            // Initializing all the Homie stuff.
            _clientDevice.Initialize(brokerConnection);
        }
        public void Initialize(IClientDeviceConnection _brokerConnection)
        {
            // Creating a air conditioner device.
            _clientDevice = DeviceFactory.CreateClientDevice("lightbulb");

            // Creating properties.
            _color = _clientDevice.CreateClientColorProperty(new ClientPropertyMetadata {
                PropertyType = PropertyType.Parameter, NodeId = "general", PropertyId = "color", Format = "rgb", InitialValue = "0,0,0"
            });
            _color.PropertyChanged += (sender, e) => {
                if (_color.Value.RedValue > 0)
                {
                    Console.WriteLine("Me no like red!");
                    _color.Value = HomieColor.FromRgbString("0,128,128");
                }
            };

            // Initializing all the Homie stuff.
            _clientDevice.Initialize(_brokerConnection);
        }
 public void Initialize(string mqttBrokerIpAddress, ClientDeviceMetadata clientDeviceMetadata)
 {
     ClientDevice = DeviceFactory.CreateClientDevice(clientDeviceMetadata);
     _broker.Initialize(mqttBrokerIpAddress);
     ClientDevice.Initialize(_broker, (severity, message) => { Console.WriteLine($"{severity}:{message}"); });
 }