public abstract class PeriodicPublisherCloud extends CloudConnector
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
TOPIC_IP
Topic used when the temperature is IP address is updated.
|
static java.lang.String |
TOPIC_SET
Topic used to set the target.
|
static java.lang.String |
TOPIC_TARGET
Topic used when the target is updated.
|
static java.lang.String |
TOPIC_TEMPERATURE
Topic used when the temperature is updated.
|
Constructor and Description |
---|
PeriodicPublisherCloud() |
Modifier and Type | Method and Description |
---|---|
protected void |
disconnect()
Disconnects from the cloud.
|
protected abstract void |
doConnect()
Connects to the cloud.
|
protected abstract void |
doDisconnect()
Disconnects from the cloud.
|
protected abstract void |
doPublish(java.lang.String topic,
java.lang.String message)
Publishes to a topic.
|
boolean |
isConnected()
Checks whether the listener is connected.
|
boolean |
isReady()
Checks whether the listener is ready to be connected.
|
void |
onTargetChange(float newTarget)
Callback function when the target temperature is changed.
|
void |
onTemperatureChange(float newTemperature)
Callback function when the temperature is changed.
|
protected void |
publishIP()
Request a publication of the IP address.
|
protected void |
receive(java.lang.String json)
Parse a JSON string to update the thermostat.
|
protected void |
setIsConnected(boolean isConnected)
Sets the cloud connector to be connected.
|
void |
setThermostat(HeadlessThermostat thermostat)
Sets the thermostat.
|
void |
start()
Starts the connector behaviour.
|
void |
stop()
Stops the publishing.
|
protected abstract void |
subscribe(java.lang.String topic)
Subscribes to a topic.
|
getName, isError
public static final java.lang.String TOPIC_IP
public static final java.lang.String TOPIC_TEMPERATURE
public static final java.lang.String TOPIC_TARGET
public static final java.lang.String TOPIC_SET
public void start()
CloudConnector
start
in class CloudConnector
public void stop()
stop
in class CloudConnector
public void setThermostat(HeadlessThermostat thermostat)
thermostat
- the thermostat to set.public void onTargetChange(float newTarget)
ThermostatListener
newTarget
- the new target value.public void onTemperatureChange(float newTemperature)
ThermostatListener
newTemperature
- the new temperature value.public boolean isConnected()
CloudConnector
isConnected
in class CloudConnector
true
if the connector is connected.protected void receive(java.lang.String json)
json
- a JSON with parameters target, temperature and/or unit
{target=20,temperature=25,unit="°C"}
protected void setIsConnected(boolean isConnected)
isConnected
- true
if the connector is connected.protected void disconnect() throws java.io.IOException
java.io.IOException
- if an IOException
occurred.protected abstract void subscribe(java.lang.String topic) throws java.io.IOException
topic
- the topic to subscribe to, cannot be null
.java.io.IOException
- if an IOException
occurred.protected abstract void doPublish(java.lang.String topic, java.lang.String message) throws java.io.IOException
topic
- the topic to subscribe to.message
- the message to publish.java.io.IOException
- if an IOException
occurred.protected abstract void doDisconnect() throws java.io.IOException
java.io.IOException
- when the disconnect failed.protected abstract void doConnect() throws java.io.IOException
java.io.IOException
- when the connect failed.protected void publishIP()
public boolean isReady()
true
if the connector is ready to be connected.