HADeviceTracker class¶
-
class HADeviceTracker : public HABaseDeviceType¶
HADeviceTracker allows to implement a custom device’s tracker.
Note
You can find more information about this entity in the Home Assistant documentation: https://www.home-assistant.io/integrations/device_tracker.mqtt/
Public Types
Public Functions
-
HADeviceTracker(const char *uniqueId)¶
- Parameters
uniqueId – The unique ID of the tracker. It needs to be unique in a scope of your device.
-
bool setState(const TrackerState state, const bool force = false)¶
Changes the state of the tracker and publishes MQTT message. Please note that if a new value is the same as previous one, the MQTT message won’t be published.
- Parameters
state – The new state of the tracker.
force – Forces to update the state without comparing it to a previous known state.
- Returns
Returns
true
if MQTT message has been published successfully.
-
inline void setCurrentState(const TrackerState state)¶
Sets the current state of the tracker without publishing it to Home Assistant. This method may be useful if you want to change the state before connection with MQTT broker is acquired.
- Parameters
state – The new state of the tracker.
-
inline TrackerState getState() const¶
Returns the last known state of the tracker. If setState method wasn’t called the initial value will be returned.
-
inline void setIcon(const char *icon)¶
Sets icon of the tracker. Any icon from MaterialDesignIcons.com (for example:
mdi:home
).- Parameters
icon – The icon name.
-
inline void setSourceType(const SourceType type)¶
Sets the source type of the tracker.
- Parameters
type – The source type (gps, router, bluetooth, bluetooth LE).
Protected Functions
-
virtual void buildSerializer() override¶
-
virtual void onMqttConnected() override¶
Private Functions
-
bool publishState(TrackerState state)¶
Publishes the MQTT message with the given state.
- Parameters
state – The state to publish.
- Returns
Returns
true
if the MQTT message has been published successfully.
-
const __FlashStringHelper *getSourceTypeProperty() const¶
Returns progmem string representing source type of the tracker.
Private Members
-
const char *_icon¶
The icon of the tracker. It can be nullptr.
-
SourceType _sourceType¶
The source type of the tracker. By default it’s
HADeviceTracker::SourceTypeUnknown
.
-
TrackerState _currentState¶
The current state of the device’s tracker. By default its
HADeviceTracker::StateUnknown
.
-
HADeviceTracker(const char *uniqueId)¶