Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bugfix/maximum number of device types (#190) #191

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/HAMqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool HAMqtt::isConnected() const

void HAMqtt::addDeviceType(HABaseDeviceType* deviceType)
{
if (_devicesTypesNb + 1 >= _maxDevicesTypesNb) {
if (_devicesTypesNb + 1 > _maxDevicesTypesNb) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/BaseDeviceTypeTest/BaseDeviceTypeTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ AHA_TEST(BaseDeviceTypeTest, register_mqtt_type) {
assertEqual(&deviceType, mqtt.getDevicesTypes()[0]);
}

// TODO it would be better to place this test in HAMqtt related test. Since there is no one yet, I leave it here
AHA_TEST(BaseDeviceTypeTest, maximum_number_of_device_types) {
HADevice device(testDeviceId);
HAMqtt mqtt(nullptr, device, 1);
DummyDeviceType deviceType(AHATOFSTR(ComponentNameStr), testUniqueId);

assertEqual((uint8_t)1, mqtt.getDevicesTypesNb());
assertEqual(&deviceType, mqtt.getDevicesTypes()[0]);
}

AHA_TEST(BaseDeviceTypeTest, default_name) {
DummyDeviceType deviceType(AHATOFSTR(ComponentNameStr), testUniqueId);
assertEqual((const char*)nullptr, deviceType.getName());
Expand Down