Class AbstractKobotEntity
-
- All Implemented Interfaces:
-
crackers.kobots.mqtt.homeassistant.KobotHAEntity,kotlin.Comparable
public abstract class AbstractKobotEntity implements KobotHAEntity
Abstraction for common attributes and methods for all Kobot entities for integration with Home Assistant via MQTT. Because its part of this package, it assumes usage of the mqttClient singleton.
Devices and entities may be removed from HomeAssistant at any time, so the discovery message is sent on every connection. Birth and last-will messages, and retention flags are not used because the client can be used for other things besides HA and it assumes these devices are "smart enough" to
Note the uniqueId and name properties are the name of the entity, not the device (see DeviceIdentifier -- a device may have several entities). The entityId in Home Assistant will be constructed from the component, uniqueId, and name -- e.g.
light.sparkle_night_light.
-
-
Field Summary
Fields Modifier and Type Field Description private final Stringiconprivate final StringstatusTopicprivate final StringuniqueIdprivate final Stringnameprivate final DeviceIdentifierdeviceIdentifierprivate final Stringcomponent
-
Constructor Summary
Constructors Constructor Description AbstractKobotEntity(String uniqueId, String name, DeviceIdentifier deviceIdentifier)
-
Method Summary
Modifier and Type Method Description StringgetIcon()The icon HA will use to display this entity. StringgetStatusTopic()The MQTT topic for the devices state (send). final StringgetUniqueId()The unique ID of the device. final StringgetName()The friendly name of the device. final DeviceIdentifiergetDeviceIdentifier()More detailed information about the device. JSONObjectdiscovery()A generic configuration for the device, which can be used to generate the discovery message because there are too many "base" configuration parameters to be able to handle them cleanly, so just dump it on the child class to figure it out. <Error class: unknown class>start()UnitsendCurrentState(String state)Send the current state message for this device, if HA is available. Unitremove()Removes the entity from HA: sends an empty configuration, if HA is available. -
-
Constructor Detail
-
AbstractKobotEntity
AbstractKobotEntity(String uniqueId, String name, DeviceIdentifier deviceIdentifier)
-
-
Method Detail
-
getStatusTopic
String getStatusTopic()
The MQTT topic for the devices state (send). Allows for over-rides.
-
getUniqueId
final String getUniqueId()
The unique ID of the device. NOTE If this is not unique across all devices, then HomeAssistant will throw an error on discovery, but it wont be seen here.
-
getName
final String getName()
The friendly name of the device. This may be renamed in the HomeAssistant UI.
-
getDeviceIdentifier
final DeviceIdentifier getDeviceIdentifier()
More detailed information about the device.
-
discovery
JSONObject discovery()
A generic configuration for the device, which can be used to generate the discovery message because there are too many "base" configuration parameters to be able to handle them cleanly, so just dump it on the child class to figure it out.
-
start
<Error class: unknown class> start()
-
sendCurrentState
Unit sendCurrentState(String state)
Send the current state message for this device, if HA is available. This is a public method so that it can be triggered externally, such as in the case of effects running.
-
-
-
-