Beispiel #1
0
        public Task SetState(AdapterPowerState powerState, AdapterColor color, params IHardwareParameter[] hardwareParameters)
        {
            if (!SupportsColor && color != null)
            {
                throw new InvalidOperationException("Color is not supported by adapter.");
            }

            var r = 0;
            var g = 0;
            var b = 0;

            if (powerState == AdapterPowerState.On && color == null)
            {
                r = 1023;
                g = 1023;
                b = 1023;
            }
            else if (powerState == AdapterPowerState.On && color != null)
            {
                r = color.Red;
                g = color.Green;
                b = color.Blue;
            }

            var topic = OutpostTopicBuilder.BuildCommandTopic(_deviceName, "RGB/Set");
            var json  = new JObject
            {
                ["r"] = r,
                ["g"] = g,
                ["b"] = b
            };

            _deviceMessageBroker.Publish(topic, json, MqttQosLevel.AtMostOnce);
            return(Task.FromResult(0));
        }
        public void SendCode(Lpd433MhzCode code)
        {
            var topic = OutpostTopicBuilder.BuildCommandTopic(_deviceName, "LPD/Send");
            var json  = new JObject
            {
                ["value"]    = code.Value,
                ["length"]   = code.Length,
                ["protocol"] = code.Protocol,
                ["repeats"]  = code.Repeats
            };

            _deviceMessageBroker.Publish(topic, json, MqttQosLevel.AtMostOnce);
        }