The configured maximum number of device types _maxDevicesTypesNb doesn't represent the actual maximum of device types you can add. The exact number of devices is always one less than the configured value.
Root of the bug:
The condition that checks if it is possible to add more devices is incorrect.
Let's say I want only 1 device type, so I pass maxDevicesTypesNb = 1 to the HAMqtt's constructor. Then I won't be able to add the device due to the incorrect if-check above. 0 + 1 >= 1 => true. The same is true for other numbers, having a maximum set to 7, you can add only 6 devices.
The bug:
The configured maximum number of device types
_maxDevicesTypesNb
doesn't represent the actual maximum of device types you can add. The exact number of devices is always one less than the configured value.Root of the bug:
The condition that checks if it is possible to add more devices is incorrect.
The condition: https://github.com/dawidchyrzynski/arduino-home-assistant/blob/0fc32a5bad861ca76767ff13187f8afabcc4f9a0/src/HAMqtt.cpp#L188-L190
Initial values: https://github.com/dawidchyrzynski/arduino-home-assistant/blob/0fc32a5bad861ca76767ff13187f8afabcc4f9a0/src/HAMqtt.cpp#L21-L23
Simple example to understand why it's incorrect
Let's say I want only 1 device type, so I pass
maxDevicesTypesNb = 1
to theHAMqtt
's constructor. Then I won't be able to add the device due to the incorrect if-check above.0 + 1 >= 1
=>true
. The same is true for other numbers, having a maximum set to 7, you can add only 6 devices.