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 String
icon
private final String
statusTopic
private final String
uniqueId
private final String
name
private final DeviceIdentifier
deviceIdentifier
private final String
component
-
Constructor Summary
Constructors Constructor Description AbstractKobotEntity(String uniqueId, String name, DeviceIdentifier deviceIdentifier)
-
Method Summary
Modifier and Type Method Description String
getIcon()
The icon HA will use to display this entity. String
getStatusTopic()
The MQTT topic for the devices state (send). final String
getUniqueId()
The unique ID of the device. final String
getName()
The friendly name of the device. final DeviceIdentifier
getDeviceIdentifier()
More detailed information about the device. 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. <Error class: unknown class>
start()
Unit
sendCurrentState(String state)
Send the current state message for this device, if HA is available. Unit
remove()
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.
-
-
-
-