add beaconScanner

This commit is contained in:
Stephan Mühl
2023-04-03 12:13:11 +02:00
parent a4f14a58c1
commit 6deaadeb62
15 changed files with 401 additions and 46 deletions

View File

@@ -220,7 +220,7 @@ void MatrixDisplayUi::tick()
if (this->AppCount > 0)
this->drawApp();
this->drawOverlays();
this->matrix->show();
//this->matrix->show();
}
void MatrixDisplayUi::drawApp()

View File

@@ -6,7 +6,7 @@
#define HADEVICE_INIT \
_ownsUniqueId(false), \
_serializer(new HASerializer(nullptr, 5)), \
_serializer(new HASerializer(nullptr, 6)), \
_availabilityTopic(nullptr), \
_sharedAvailability(false), \
_available(true) // device will be available by default
@@ -68,6 +68,11 @@ void HADevice::setModel(const char* model)
_serializer->set(AHATOFSTR(HADeviceModelProperty), model);
}
void HADevice::setURL(const char* url)
{
_serializer->set(AHATOFSTR(HAIPProperty), url);
}
void HADevice::setName(const char* name)
{
_serializer->set(AHATOFSTR(HANameProperty), name);

View File

@@ -25,7 +25,7 @@ public:
*
* @param uniqueId String with the null terminator.
*/
HADevice(const char* uniqueId);
HADevice(const char *uniqueId);
/**
* Constructs HADevice using the given byte array as the unique ID.
@@ -34,7 +34,7 @@ public:
* @param uniqueId Bytes array that's going to be converted into the string.
* @param length Number of bytes in the array.
*/
HADevice(const byte* uniqueId, const uint16_t length);
HADevice(const byte *uniqueId, const uint16_t length);
/**
* Deletes HASerializer and the availability topic if the shared availability was enabled.
@@ -44,34 +44,44 @@ public:
/**
* Returns pointer to the unique ID. It can be nullptr if the device has no ID assigned.
*/
inline const char* getUniqueId() const
{ return _uniqueId; }
inline const char *getUniqueId() const
{
return _uniqueId;
}
/**
* Returns the instance of the HASerializer used by the device.
* This method is used by all entities to serialize device's representation.
*/
inline const HASerializer* getSerializer() const
{ return _serializer; }
inline const HASerializer *getSerializer() const
{
return _serializer;
}
/**
* Returns true if the shared availability is enabled for the device.
*/
inline bool isSharedAvailabilityEnabled() const
{ return _sharedAvailability; }
{
return _sharedAvailability;
}
/**
* Returns availability topic generated by the HADevice::enableSharedAvailability method.
* It can be nullptr if the shared availability is not enabled.
*/
inline const char* getAvailabilityTopic() const
{ return _availabilityTopic; }
inline const char *getAvailabilityTopic() const
{
return _availabilityTopic;
}
/**
* Returns online/offline state of the device.
*/
inline bool isAvailable() const
{ return _available; }
{
return _available;
}
/**
* Sets unique ID of the device based on the given byte array.
@@ -81,35 +91,36 @@ public:
* @param length Number of bytes in the array.
* @note The unique ID can be set only once (via constructor or using this method).
*/
bool setUniqueId(const byte* uniqueId, const uint16_t length);
bool setUniqueId(const byte *uniqueId, const uint16_t length);
/**
* Sets the "manufacturer" property that's going to be displayed in the Home Assistant.
*
* @param manufacturer Any string. Keep it short to save the memory.
*/
void setManufacturer(const char* manufacturer);
void setManufacturer(const char *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);
void setModel(const char *model);
void setURL(const char *url);
/**
* 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);
void setName(const char *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);
void setSoftwareVersion(const char *softwareVersion);
/**
* Sets device's availability and publishes MQTT message on the availability topic.
@@ -139,16 +150,16 @@ public:
private:
/// The unique ID of the device. It can be a memory allocated by HADevice::setUniqueId method.
const char* _uniqueId;
const char *_uniqueId;
/// Specifies whether HADevice class owns the _uniqueId pointer.
bool _ownsUniqueId;
/// JSON serializer of the HADevice class. It's allocated in the constructor.
HASerializer* _serializer;
HASerializer *_serializer;
/// The availability topic allocated by HADevice::enableSharedAvailability method.
char* _availabilityTopic;
char *_availabilityTopic;
/// Specifies whether the shared availability is enabled.
bool _sharedAvailability;

View File

@@ -37,6 +37,7 @@ const char HADeviceManufacturerProperty[] PROGMEM = {"mf"};
const char HADeviceModelProperty[] PROGMEM = {"mdl"};
const char HADeviceSoftwareVersionProperty[] PROGMEM = {"sw"};
const char HANameProperty[] PROGMEM = {"name"};
const char HAIPProperty[] PROGMEM = {"cu"};
const char HAUniqueIdProperty[] PROGMEM = {"uniq_id"};
const char HADeviceProperty[] PROGMEM = {"dev"};
const char HADeviceClassProperty[] PROGMEM = {"dev_cla"};

View File

@@ -35,6 +35,7 @@ extern const char HASerializerUnderscore[];
extern const char HADeviceIdentifiersProperty[];
extern const char HADeviceManufacturerProperty[];
extern const char HADeviceModelProperty[];
extern const char HAIPProperty[];
extern const char HADeviceSoftwareVersionProperty[];
extern const char HANameProperty[];
extern const char HAUniqueIdProperty[];

View File

@@ -199,7 +199,6 @@
}
#preview img {
width: 200px;
height: 200px;
image-rendering: pixelated;
}