public abstract class PeriodicPublisherCloud extends CloudConnector
Modifier and Type | Field and Description |
---|---|
static String |
TOPIC_IP
Topic used when the temperature is IP address is updated.
|
static String |
TOPIC_SET
Topic used to set the target.
|
static String |
TOPIC_TARGET
Topic used when the target is updated.
|
static 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(String topic,
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(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(String topic)
Subscribes to a topic.
|
getName, isError
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
public static final String TOPIC_IP
public static final String TOPIC_SET
public static final String TOPIC_TARGET
public static final String TOPIC_TEMPERATURE
protected void disconnect() throws IOException
IOException
- if an IOException
occurred.protected abstract void doConnect() throws IOException
IOException
- when the connect failed.protected abstract void doDisconnect() throws IOException
IOException
- when the disconnect failed.protected abstract void doPublish(String topic, String message) throws IOException
topic
- the topic to subscribe to.message
- the message to publish.IOException
- if an IOException
occurred.public boolean isConnected()
CloudConnector
isConnected
in class CloudConnector
true
if the connector is connected.public boolean isReady()
true
if the connector is ready to be connected.public void onTargetChange(float newTarget)
ThermostatListener
newTarget
- the new target value.public void onTemperatureChange(float newTemperature)
ThermostatListener
newTemperature
- the new temperature value.protected void publishIP()
protected void receive(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.public void setThermostat(HeadlessThermostat thermostat)
thermostat
- the thermostat to set.public void start()
CloudConnector
start
in class CloudConnector
public void stop()
stop
in class CloudConnector
protected abstract void subscribe(String topic) throws IOException
topic
- the topic to subscribe to, cannot be null
.IOException
- if an IOException
occurred.