mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
split out from net and misc module namespaces
This commit is contained in:
@@ -22,43 +22,43 @@ type MQTTClient struct {
|
||||
|
||||
func init() {
|
||||
RegisterModule(ModuleRegistration{
|
||||
Type: "net.mqtt.client",
|
||||
Type: "mqtt.client",
|
||||
New: func(ctx context.Context, config config.ModuleConfig, router route.RouteIO) (Module, error) {
|
||||
params := config.Params
|
||||
broker, ok := params["broker"]
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client requires a broker parameter")
|
||||
return nil, fmt.Errorf("mqtt.client requires a broker parameter")
|
||||
}
|
||||
|
||||
brokerString, ok := broker.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client broker must be string")
|
||||
return nil, fmt.Errorf("mqtt.client broker must be string")
|
||||
}
|
||||
|
||||
topic, ok := params["topic"]
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client requires a topic parameter")
|
||||
return nil, fmt.Errorf("mqtt.client requires a topic parameter")
|
||||
}
|
||||
|
||||
topicString, ok := topic.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client topic must be string")
|
||||
return nil, fmt.Errorf("mqtt.client topic must be string")
|
||||
}
|
||||
|
||||
clientId, ok := params["clientId"]
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client requires a clientId parameter")
|
||||
return nil, fmt.Errorf("mqtt.client requires a clientId parameter")
|
||||
}
|
||||
|
||||
clientIdString, ok := clientId.(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("net.mqtt.client clientId must be string")
|
||||
return nil, fmt.Errorf("mqtt.client clientId must be string")
|
||||
}
|
||||
|
||||
return &MQTTClient{config: config, Broker: brokerString, Topic: topicString, ClientID: clientIdString, ctx: ctx, router: router}, nil
|
||||
@@ -109,15 +109,15 @@ func (mc *MQTTClient) Output(payload any) error {
|
||||
fmt.Printf("payload type: %T\n", payload)
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("net.mqtt.client is only able to output a MQTTMessage")
|
||||
return fmt.Errorf("mqtt.client is only able to output a MQTTMessage")
|
||||
}
|
||||
|
||||
if mc.client == nil {
|
||||
return fmt.Errorf("net.mqtt.client client is not setup")
|
||||
return fmt.Errorf("mqtt.client client is not setup")
|
||||
}
|
||||
|
||||
if !mc.client.IsConnected() {
|
||||
return fmt.Errorf("net.mqtt.client is not connected")
|
||||
return fmt.Errorf("mqtt.client is not connected")
|
||||
}
|
||||
|
||||
token := mc.client.Publish(payloadMessage.Topic(), payloadMessage.Qos(), payloadMessage.Retained(), payloadMessage.Payload())
|
||||
|
||||
Reference in New Issue
Block a user