public void 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; } _deviceMessageBroker.Publish($"HA4IoT/Device/{_deviceName}/Command/RGB/Set", Encoding.UTF8.GetBytes(r + "," + g + "," + b), MqttQosLevel.AtMostOnce); }
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 Task SetState(AdapterPowerState powerState, AdapterColor color, params IHardwareParameter[] hardwareParameters) { var r = 0; var g = 0; var b = 0; if (powerState == AdapterPowerState.On && color != null) { r = color.Red; g = color.Green; b = color.Blue; } if (powerState == AdapterPowerState.On && color == null) { r = 1023; g = 1023; b = 1023; } var value = new JObject { ["r"] = r, ["g"] = g, ["b"] = b }; _messageBroker.Publish(_topic, value, MqttQosLevel.AtMostOnce, true); return(Task.CompletedTask); }
public void SendCode(Lpd433MhzCode code) { // TODO: Add protocol to code class. var payload = Encoding.UTF8.GetBytes($"{code.Value},{code.Length},2,{code.Repeats}"); _deviceMessageBroker.Publish($"HA4IoT/Device/{_deviceName}/Command/LPD/Send", payload, MqttQosLevel.AtMostOnce); }
public static void Publish(this IDeviceMessageBrokerService deviceMessageBrokerService, DeviceMessage deviceMessage) { if (deviceMessageBrokerService == null) { throw new ArgumentNullException(nameof(deviceMessageBrokerService)); } if (deviceMessage == null) { throw new ArgumentNullException(nameof(deviceMessage)); } deviceMessageBrokerService.Publish(deviceMessage.Topic, deviceMessage.Payload, deviceMessage.QosLevel); }
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); }
public static void Publish(this IDeviceMessageBrokerService deviceMessageBrokerService, string topic, string payload, MqttQosLevel qosLevel, bool retain) { if (deviceMessageBrokerService == null) { throw new ArgumentNullException(nameof(deviceMessageBrokerService)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (payload == null) { throw new ArgumentNullException(nameof(payload)); } deviceMessageBrokerService.Publish(topic, Encoding.UTF8.GetBytes(payload), qosLevel, retain); }
public static void Publish(this IDeviceMessageBrokerService deviceMessageBrokerService, string topic, JObject payload, MqttQosLevel qosLevel, bool retain) { if (deviceMessageBrokerService == null) { throw new ArgumentNullException(nameof(deviceMessageBrokerService)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (payload == null) { throw new ArgumentNullException(nameof(payload)); } deviceMessageBrokerService.Publish(topic, payload.ToString(Formatting.None), qosLevel, retain); }
public static void Publish(this IDeviceMessageBrokerService deviceMessageBrokerService, string topic, string message, MqttQosLevel qosLevel) { if (deviceMessageBrokerService == null) { throw new ArgumentNullException(nameof(deviceMessageBrokerService)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } deviceMessageBrokerService.Publish(topic, Encoding.UTF8.GetBytes(message), qosLevel); }
public void Write(BinaryState state, WriteBinaryStateMode mode = WriteBinaryStateMode.Commit) { if (_state == state) { return; } var payload = "off"; if (state == BinaryState.High) { payload = "on"; } _messageBroker.Publish(_topic, Encoding.UTF8.GetBytes(payload), MqttQosLevel.AtMostOnce, true); StateChanged?.Invoke(this, new BinaryStateChangedEventArgs(_state, state)); _state = state; }
public static void PublishDeviceMessage(this IDeviceMessageBrokerService deviceMessageBrokerService, string deviceId, string notificationId, string payload) { if (deviceMessageBrokerService == null) { throw new ArgumentNullException(nameof(deviceMessageBrokerService)); } if (deviceId == null) { throw new ArgumentNullException(nameof(deviceId)); } if (notificationId == null) { throw new ArgumentNullException(nameof(notificationId)); } var topic = GenerateDeviceNotificationTopic(deviceId, notificationId); deviceMessageBrokerService.Publish(topic, Encoding.UTF8.GetBytes(payload), MqttQosLevel.AtMostOnce); }
private void OnStateChanged(object sender, ComponentFeatureStateChangedEventArgs e) { try { var topic = "garden_controller/$STATUS/"; string payload; if (e.NewState.Supports <ButtonState>()) { topic += "button.default"; payload = e.NewState.Extract <ButtonState>().Value == ButtonStateValue.Pressed ? "pressed" : "released"; } else if (e.NewState.Supports <PowerState>()) { var powerState = e.NewState.Extract <PowerState>(); payload = powerState.Value == PowerStateValue.On ? "on" : "off"; } else { return; } var message = new DeviceMessage { Topic = topic, Payload = Encoding.ASCII.GetBytes(payload), Retain = true }; _deviceMessageBrokerService.Publish(message); } catch (Exception exception) { Log.Default.Error(exception, "Errow while sending state."); } }
public void SetState(AdapterPowerState powerState, params IHardwareParameter[] parameters) { _deviceMessageBrokerService.Publish(_topic, powerState == AdapterPowerState.On ? "ON" : "OFF", MqttQosLevel.ExactlyOnce); }
public void Publish(string topic, string message) { _deviceMessageBrokerService.Publish(topic, message, MqttQosLevel.AtMostOnce, false); }
public Task SetState(AdapterPowerState powerState, params IHardwareParameter[] parameters) { _deviceMessageBrokerService.Publish(_topic, powerState == AdapterPowerState.On ? "ON" : "OFF", MqttQosLevel.ExactlyOnce); return(Task.FromResult(0)); }
public Task SetState(AdapterPowerState powerState, params IHardwareParameter[] parameters) { _deviceMessageBrokerService.Publish(_topic, Encoding.UTF8.GetBytes(powerState.ToString()), MqttQosLevel.AtMostOnce, true); return(Task.FromResult(0)); }
public Task SetState(AdapterPowerState powerState, params IHardwareParameter[] parameters) { _deviceMessageBrokerService.Publish(_topic, powerState == AdapterPowerState.On ? "ON" : "OFF", MqttQosLevel.AtMostOnce, true); return(Task.CompletedTask); }