Skip to content

Ability to use strings stored in flash. #267

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions src/HADevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,31 @@ void HADevice::setManufacturer(const char* manufacturer)
_serializer->set(AHATOFSTR(HADeviceManufacturerProperty), manufacturer);
}

void HADevice::setManufacturer(const __FlashStringHelper* manufacturer)
{
_serializer->set(AHATOFSTR(HADeviceManufacturerProperty), manufacturer, HASerializer::ProgmemPropertyValue);
}

void HADevice::setModel(const char* model)
{
_serializer->set(AHATOFSTR(HADeviceModelProperty), model);
}

void HADevice::setModel(const __FlashStringHelper* model)
{
_serializer->set(AHATOFSTR(HADeviceModelProperty), model, HASerializer::ProgmemPropertyValue);
}

void HADevice::setName(const char* name)
{
_serializer->set(AHATOFSTR(HANameProperty), name);
}

void HADevice::setName(const __FlashStringHelper* name)
{
_serializer->set(AHATOFSTR(HANameProperty), name, HASerializer::ProgmemPropertyValue);
}

void HADevice::setSoftwareVersion(const char* softwareVersion)
{
_serializer->set(
Expand All @@ -82,6 +97,15 @@ void HADevice::setSoftwareVersion(const char* softwareVersion)
);
}

void HADevice::setSoftwareVersion(const __FlashStringHelper* softwareVersion)
{
_serializer->set(
AHATOFSTR(HADeviceSoftwareVersionProperty),
softwareVersion,
HASerializer::ProgmemPropertyValue
);
}

void HADevice::setConfigurationUrl(const char* url)
{
_serializer->set(
Expand All @@ -90,6 +114,15 @@ void HADevice::setConfigurationUrl(const char* url)
);
}

void HADevice::setConfigurationUrl(const __FlashStringHelper* url)
{
_serializer->set(
AHATOFSTR(HADeviceConfigurationUrlProperty),
url,
HASerializer::ProgmemPropertyValue
);
}

void HADevice::setAvailability(bool online)
{
_available = online;
Expand Down
35 changes: 35 additions & 0 deletions src/HADevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,69 @@ class HADevice
*/
void setManufacturer(const char* manufacturer);

/**
* Sets the "manufacturer" property that's going to be displayed in the Home Assistant.
*
* @param manufacturer Any string. Data must reside in flash. Use PROGMEM or 'F()' macro.
*/
void setManufacturer(const __FlashStringHelper* manufacturer);

/**
* Sets the "model" property that's going to be displayed in the Home Assistant.
*
* @param model Any string. Keep it short to save the memory.
*/
void setModel(const char* model);

/**
* Sets the "model" property that's going to be displayed in the Home Assistant.
*
* @param model Any string. Data must reside in flash. Use PROGMEM or 'F()' macro.
*/
void setModel(const __FlashStringHelper* model);

/**
* Sets the "name" property that's going to be displayed in the Home Assistant.
*
* @param name Any string. Keep it short to save the memory.
*/
void setName(const char* name);

/**
* Sets the "name" property that's going to be displayed in the Home Assistant.
*
* @param name Any string. Data must reside in flash. Use PROGMEM or 'F()' macro.
*/
void setName(const __FlashStringHelper* name);

/**
* Sets the "software version" property that's going to be displayed in the Home Assistant.
*
* @param softwareVersion Any string. Keep it short to save the memory.
*/
void setSoftwareVersion(const char* softwareVersion);

/**
* Sets the "software version" property that's going to be displayed in the Home Assistant.
*
* @param softwareVersion Any string. Data must reside in flash. Use PROGMEM or 'F()' macro.
*/
void setSoftwareVersion(const __FlashStringHelper* softwareVersion);

/**
* Sets the "configuration URL" property that's going to be used by the Home Assistant.
*
* @param url Configuration URL to publish.
*/
void setConfigurationUrl(const char* url);

/**
* Sets the "configuration URL" property that's going to be used by the Home Assistant.
*
* @param url Configuration URL to publish. Data must reside in flash. Use PROGMEM or 'F()' macro.
*/
void setConfigurationUrl(const __FlashStringHelper* url);

/**
* Sets device's availability and publishes MQTT message on the availability topic.
* If the device is not connected to an MQTT broker or the shared availability is not enabled then nothing happens.
Expand Down