Net2HassMqtt - .NET to HASS mapping via MQTT

Hi, I’ve published an experimental release of an .NET library that hopefully makes it easier to connect .NET apps to Home Assistant via MQTT. It is not another MQTT transport layer, but a Home Assistant centric fluent configuration interface to map an application’s models to Home Assistant entities.

If this is of interest to anybody I would love feedback. Currently experimental/alpha (pre-1.0.0).

If you have read this far … a code fragment gives an idea of its intent:

    // Map model property to an entity
    device.HasBatteryChargingBinarySensor(config => 
               config.OnModel(model)
                          .WithStatusProperty(nameof(QuickStartDemoModel.BatteryChaging))
                          .WithUnitOfMeasurement(BatteryChargingBinarySensorUoM.None)
                          .WithFriendlyName("Battery Charging Status")
                          .WithNodeId("battery_1_charging"));

Version 0.3.1 published. Early development.

Now has support for Even entity (thanks to another who did most of the work).

It feels like it will go 1.0.0 (first stable) in September.

Example code for implementing event in application model:

    public enum VolumeEventTypes
    {
        Mute,
        LowerVolume,
        RaiseVolume
    }

    public event EventHandler<HassEventArgs>? VolumeEvent;

    // Example model method firing event
    public void OnKeyPressed(char keyChar)
    {
        if (keyChar == '+')
        {
            EfEvent?.Invoke(this, HassEventArgs.From(VolumeEventTypes.RaiseVolume));
        }

        if (keyChar == '-')
        {
            EfEvent?.Invoke(this, HassEventArgs.From(VolumeEventTypes.LowerVolume));
        }

        if (keyChar == 'm')
        {
            EfEvent?.Invoke(this, HassEventArgs.From(VolumeEventTypes.Mute));
        }
    }

The Net2HassMqtt configuration will look something like:

        device.HasEvent(config => config.OnModel(model)
                                        .WithEvent(nameof(MyModel.VolumeEvent))
                                        .WithEventTypes<VolumeEventTypes>()
                                        .WithEventTypeToSendAfterEachEvent("Clear")
                                        .WithFriendlyName("Volume control event")
                                        .WithNodeId("volume_event"));

WithEventTypeToSendAfterEachEvent adds an event type to send immediately after each other event. Work around to prevent HASS resending events on device reconnect and HASS start-up.