xRegistry Codegen
  • Home
  • Gallery
← Back

Lightbulb → MQTT Client

lightbulb.xreg.json with Avro schema → Python MQTT Client

xrcg generate --language py --style mqttclient -d lightbulb.xreg.json --output ./output --projectname Lightbulb
📄 Source
📄 Source: lightbulb.xreg.json
{
  "messagegroups": {
    "Fabrikam.Lumen": {
      "envelope": "CloudEvents/1.0",
      "description": "State change events for a Fabrikam smart lightbulb",
      "messages": {
        "Fabrikam.Lumen.TurnedOn": {
          "description": "Event for when the bulb is turned on",
          "envelope": "CloudEvents/1.0",
          "envelopemetadata": {
            "id": {
              "required": true
            },
            "type": {
              "value": "Fabrikam.Lumen.TurnedOn",
              "description": "Event raised when the bulb is turned on"
            },
            "source": {
              "type": "uritemplate",
              "description": "source of the event",
              "value": "{tenantid}/{deviceid}"
            },
            "time": {
              "required": true
            },
            "datacontenttype": {
              "value": "application/json"
            }
          },
          "dataschemaformat": "Avro/1.11.1",
          "dataschemauri": "#/schemagroups/Fabrikam.Lumen/schemas/Fabrikam.Lumen.TurnedOnEventData"
        },
        "Fabrikam.Lumen.TurnedOff": {
          "description": "Event for when the bulb is turned off",
          "envelope": "CloudEvents/1.0",
          "envelopemetadata": {
            "id": {
              "required": true
            },
            "type": {
              "value": "Fabrikam.Lumen.TurnedOff",
              "description": "Event raised when the bulb is turned off"
            },
            "source": {
              "type": "uritemplate",
              "description": "source of the event",
              "value": "{tenantid}/{deviceid}"
            },
            "time": {
              "required": true
            },
            "datacontenttype": {
              "value": "application/json"
            }
          },
          "dataschemaformat": "Avro/1.11.1",
          "dataschemauri": "#/schemagroups/Fabrikam.Lumen/schemas/Fabrikam.Lumen.TurnedOffEventData"
        },
        "Fabrikam.Lumen.BrightnessChanged": {
          "description": "Event for when the bulb's brightness changes",
          "envelope": "CloudEvents/1.0",
          "envelopemetadata": {
            "id": {
              "required": true
            },
            "type": {
              "value": "Fabrikam.Lumen.BrightnessChanged",
              "description": "Event raised when the bulb's brightness changes"
            },
            "source": {
              "type": "uritemplate",
              "description": "source of the event",
              "value": "{tenantid}/{deviceid}"
            },
            "datacontenttype": {
              "value": "application/json"
            }
          },
          "dataschemaformat": "Avro/1.11.1",
          "dataschemauri": "#/schemagroups/Fabrikam.Lumen/schemas/Fabrikam.Lumen.BrightnessChangedEventData"
        },
        "Fabrikam.Lumen.ColorChanged": {
          "description": "Event for when the bulb's color changes",
          "envelope": "CloudEvents/1.0",
          "envelopemetadata": {
            "id": {
              "required": true
            },
            "type": {
              "value": "Fabrikam.Lumen.ColorChanged",
              "description": "Event raised when the bulb's color changes"
            },
            "source": {
              "type": "uritemplate",
              "description": "source of the event",
              "value": "{tenantid}/{deviceid}"
            },
            "time": {
              "required": true
            },
            "datacontenttype": {
              "value": "application/json"
            }
          },
          "dataschemaformat": "Avro/1.11.1",
          "dataschemauri": "#/schemagroups/Fabrikam.Lumen/schemas/Fabrikam.Lumen.ColorChangedEventData"
        }
      }
    }
  },
  "schemagroups": {
    "Fabrikam.Lumen": {
      "schemas": {
        "Fabrikam.Lumen.TurnedOnEventData": {
          "format": "Avro/1.11.1",
          "versions": {
            "1": {
              "format": "Avro/1.11.1",
              "schema": {
                "type": "record",
                "name": "TurnedOnEventData",
                "namespace": "Fabrikam.Lumen",
                "doc": "Data schema for bulb turned on event",
                "fields": [
                  {
                    "name": "tenantid",
                    "doc": "Tenant identifier",
                    "type": "string"
                  },
                  {
                    "name": "deviceid",
                    "doc": "Device identifier",
                    "type": "string"
                  },
                  {
                    "name": "switchSource",
                    "doc": "Source of the switch event",
                    "type": {
                      "type": "enum",
                      "name": "SwitchSource",
                      "symbols": [
                        "PhysicalSwitch",
                        "AppSwitch",
                        "VoiceSwitch"
                      ]
                    }
                  },
                  {
                    "name": "brightness",
                    "doc": "Brightness level (in Lumen)",
                    "unit": "lm",
                    "type": "int"
                  },
                  {
                    "name": "color",
                    "doc": "Color of the light (in RGB hex format)",
                    "type": "string"
                  },
                  {
                    "name": "colorTemperature",
                    "doc": "Color temperature of the light (in Kelvin)",
                    "unit": "K",
                    "type": "int"
                  },
                  {
                    "name": "powerConsumption",
                    "doc": "Power consumption of the light (in Watts)",
                    "unit": "W",
                    "type": "float"
                  }
                ]
              }
            }
          }
        },
        "Fabrikam.Lumen.TurnedOffEventData": {
          "format": "Avro/1.11.1",
          "versions": {
            "1": {
              "format": "Avro/1.11.1",
              "schema": {
                "type": "record",
                "name": "TurnedOffEventData",
                "namespace": "Fabrikam.Lumen",
                "doc": "Data schema for bulb turned off event",
                "fields": [
                  {
                    "name": "tenantid",
                    "doc": "Tenant identifier",
                    "type": "string"
                  },
                  {
                    "name": "deviceid",
                    "doc": "Device identifier",
                    "type": "string"
                  },
                  {
                    "name": "powerConsumption",
                    "doc": "Power consumption of the light (in Watts)",
                    "unit": "W",
                    "type": "float"
                  }
                ]
              }
            }
          }
        },
        "Fabrikam.Lumen.BrightnessChangedEventData": {
          "format": "Avro/1.11.1",
          "versions": {
            "1": {
              "format": "Avro/1.11.1",
              "schema": {
                "type": "record",
                "name": "BrightnessChangedEventData",
                "namespace": "Fabrikam.Lumen",
                "doc": "Data schema for brightness change event",
                "fields": [
                  {
                    "name": "tenantid",
                    "doc": "Tenant identifier",
                    "type": "string"
                  },
                  {
                    "name": "deviceid",
                    "doc": "Device identifier",
                    "type": "string"
                  },
                  {
                    "name": "brightness",
                    "doc": "Brightness level (in Lumen)",
                    "unit": "lm",
                    "type": "int"
                  },
                  {
                    "name": "color",
                    "doc": "Color of the light (in RGB hex format)",
                    "type": "string"
                  },
                  {
                    "name": "colorTemperature",
                    "doc": "Color temperature of the light (in Kelvin)",
                    "unit": "K",
                    "type": "int"
                  },
                  {
                    "name": "powerConsumption",
                    "doc": "Power consumption of the light (in Watts)",
                    "unit": "W",
                    "type": "float"
                  }
                ]
              }
            }
          }
        },
        "Fabrikam.Lumen.ColorChangedEventData": {
          "format": "Avro/1.11.1",
          "versions": {
            "1": {
              "format": "Avro/1.11.1",
              "schema": {
                "type": "record",
                "name": "ColorChangedEventData",
                "namespace": "Fabrikam.Lumen",
                "doc": "Data schema for color change event",
                "fields": [
                  {
                    "name": "tenantid",
                    "doc": "Tenant identifier",
                    "type": "string"
                  },
                  {
                    "name": "deviceid",
                    "doc": "Device identifier",
                    "type": "string"
                  },
                  {
                    "name": "brightness",
                    "doc": "Brightness level (in Lumen)",
                    "unit": "lm",
                    "type": "int"
                  },
                  {
                    "name": "color",
                    "doc": "Color of the light (in RGB hex format)",
                    "type": "string",
                    "unit": "RGB"
                  },
                  {
                    "name": "colorTemperature",
                    "doc": "Color temperature of the light (in Kelvin)",
                    "unit": "K",
                    "type": "int"
                  },
                  {
                    "name": "powerConsumption",
                    "doc": "Power consumption of the light (in Watts)",
                    "unit": "W",
                    "type": "float"
                  }
                ]
              }
            }
          }
        }
      }
    }
  }
}
📁 Files
📁 Output Files
  • ▶lightbulb_data/
    • ▶src/
      • ▶lightbulb_data/
        • ▶fabrikam/
          • ▶lumen/
            • __init__.py
            • brightnesschangedeventdata.py
            • colorchangedeventdata.py
            • switchsource.py
            • turnedoffeventdata.py
            • turnedoneventdata.py
          • __init__.py
        • __init__.py
    • ▶tests/
      • test_lightbulb_data_fabrikam_lumen_brightnesschangedeventdata.py
      • test_lightbulb_data_fabrikam_lumen_colorchangedeventdata.py
      • test_lightbulb_data_fabrikam_lumen_switchsource.py
      • test_lightbulb_data_fabrikam_lumen_turnedoffeventdata.py
      • test_lightbulb_data_fabrikam_lumen_turnedoneventdata.py
    • pyproject.toml
  • ▶lightbulb_mqtt_client/
    • ▶src/
      • ▶lightbulb_mqtt_client/
        • __init__.py
        • client.py
    • ▶tests/
      • test_client.py
    • pyproject.toml
  • ▶samples/
    • sample.py
  • ▶scripts/
    • build.py
  • Makefile
  • README.md
  • install.bat
  • install.sh
📄 Output
📄 Select a file to view
Download ZIP
Select a file from the tree to view its contents.