Skip to content

Conversation

@skotl
Copy link
Contributor

@skotl skotl commented Jun 18, 2022

Support MqttNet v4

Non-breaking change

Proposed change

Based on dependabot/nuget/MQTTnet-4.0.1.184 branch

  1. IMqttFactory removed so substituted an internal version that is only called in our UseNetDaemonMqttEntityManagement DI setup method
  2. Multiple MQTTnet.* namespaces collapsed to fewer
  3. PublishAsync() is now EnqueueAsync()
  4. EnqueueAsync() does not support a CancellationToken and does not return a success / fail status
  5. UseApplicationMessageReceivedHander() has been replaced with event subscriptions OnMessageReceivedAsync
  6. Managed Mqtt Client connection/disconnection have changed from delegates to events

The public interfaces to the IMQTTEntityManager are unchanged so there should be no updates to client code required.

[ugliness warning] The upstream library retains MqttFactory but deleted IMqttFactory. To make things even more challenging they sealed MqttFactory...
So I have created our own IMqttFactory to retain current workflow, however there is now a new class called MqttFactoryFactory, which calls into the original MqttFactory to create the client. It's an ugly name but is descriptive(!) and is internal to the extension so users shouldn't see it.
Open to alternative suggestions though!

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request: no doc changes necessary

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the [development checklist][dev-checklist]
  • The code compiles without warnings (code quality chek)
  • Tests have been added updated to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

dependabot bot and others added 2 commits June 16, 2022 23:11
Bumps [MQTTnet](https://github.com/dotnet/MQTTnet) from 3.1.2 to 4.0.1.184.
- [Release notes](https://github.com/dotnet/MQTTnet/releases)
- [Commits](dotnet/MQTTnet@v3.1.2...v4.0.1.184)

---
updated-dependencies:
- dependency-name: MQTTnet
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
1. IMqttFactory removed so substituted an internal version that is only called in our `UseNetDaemonMqttEntityManagement` DI setup method
2. Multiple `MQTTnet.*` namespaces collapsed to fewer
3. PublishAsync() is now EnqueueAsync()
4. EnqueueAsync() does not support a CancellationToken and does not return a success / fail status
5. UseApplicationMessageReceivedHander() has been replaced with event subscriptions `OnMessageReceivedAsync`
6. Managed Mqtt Client connection/disconnection have changed from delegates to events
@codecov-commenter
Copy link

Codecov Report

Merging #721 (6214487) into dev (3aae064) will increase coverage by 0.16%.
The diff coverage is 57.57%.

@@            Coverage Diff             @@
##              dev     #721      +/-   ##
==========================================
+ Coverage   79.44%   79.60%   +0.16%     
==========================================
  Files         137      138       +1     
  Lines        3503     3516      +13     
  Branches      356      356              
==========================================
+ Hits         2783     2799      +16     
+ Misses        576      573       -3     
  Partials      144      144              
Flag Coverage Δ
unittests 79.60% <57.57%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ions.MqttEntityManager/DependencyInjectionSetup.cs 0.00% <0.00%> (ø)
....Extensions.MqttEntityManager/MessageSubscriber.cs 0.00% <0.00%> (ø)
...Extensions.MqttEntityManager/MqttFactoryFactory.cs 0.00% <0.00%> (ø)
...ensions.MqttEntityManager/AssuredMqttConnection.cs 61.36% <40.00%> (-2.93%) ⬇️
...ns.MqttEntityManager/Helpers/MqttFactoryWrapper.cs 58.33% <50.00%> (+3.78%) ⬆️
...emon.Extensions.MqttEntityManager/MessageSender.cs 83.33% <100.00%> (-16.67%) ⬇️
....HassModel.CodeGenerator/AttributeTypeGenerator.cs 93.44% <100.00%> (+0.58%) ⬆️
...ttEntityManager/Exceptions/MqttPublishException.cs 0.00% <0.00%> (-100.00%) ⬇️
...mon.HassClient/Internal/HomeAssistantConnection.cs 88.79% <0.00%> (+1.72%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e183f3...6214487. Read the comment docs.

@helto4real
Copy link
Collaborator

Man they really messed this one up. Removng the IMqttFactory was a weird one! I will try to review it but even better try to test it too.

Copy link
Collaborator

@helto4real helto4real left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no suggestions for changes. Good job with this But I would want someone to test it manually before I merge this. I will try to find time this weekend.

/// MqttNet removed the IMqttFactory interface at v4 which breaks our DI
/// So this is a factory for the MqttFactory to satisfy our use case
/// </summary>
internal class MqttFactoryFactory : IMqttFactory
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sad that they removed the IMqttFactory interface. This is the way we can deal with it and still use DI.

Copy link
Collaborator

@helto4real helto4real left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find time to test manually but code looks good to me.

@helto4real helto4real merged commit 66c2de3 into dev Jul 4, 2022
@helto4real helto4real deleted the mqttnet-4 branch July 4, 2022 05:54
Ikcelaks pushed a commit to Ikcelaks/netdaemon that referenced this pull request Dec 23, 2022
* Bump MQTTnet from 3.1.2 to 4.0.1.184

Bumps [MQTTnet](https://github.com/dotnet/MQTTnet) from 3.1.2 to 4.0.1.184.
- [Release notes](https://github.com/dotnet/MQTTnet/releases)
- [Commits](dotnet/MQTTnet@v3.1.2...v4.0.1.184)

---
updated-dependencies:
- dependency-name: MQTTnet
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Support MqttNet v4:

1. IMqttFactory removed so substituted an internal version that is only called in our `UseNetDaemonMqttEntityManagement` DI setup method
2. Multiple `MQTTnet.*` namespaces collapsed to fewer
3. PublishAsync() is now EnqueueAsync()
4. EnqueueAsync() does not support a CancellationToken and does not return a success / fail status
5. UseApplicationMessageReceivedHander() has been replaced with event subscriptions `OnMessageReceivedAsync`
6. Managed Mqtt Client connection/disconnection have changed from delegates to events

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tomas Hellström <tomas.hellstrom@yahoo.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants