Light Service

The Knut light service is represented by the Room and Light objects. Each light is assigned to a room and can therefore be overwritten by this room. The incoming communication from the server is handled by the LightClient which calls a corresponding handler method. Each light however can communicate directly with the KnutClient and therefore with the Knut server. The all light state and room states are updated by the feedback loop from the server.

class Light : public QObject

An implementation of the Knut light service.

This class implements the Knut light service and communicates any changes through the KnutClient client to the Knut server.

Public Functions

void setAll(const bool &lightState, const qint16 &temperature, const qint8 &dimlevel, const QColor &color)

Sets all properties of the Light at once.

Sets the lightState, temperature, dimlevel and color at once.

void handleStatusResponse(const QJsonObject &message)

Handles a status response for a Light.

Applies the new status parsed by the message to the Light. The JSON message must contain the keys state, temperature dimlevel and color.

See

LightClient::STATUS_RESPONSE

Property

property Light::lightColor

The current light color.

property Light::colorCold

The hex color code that represents the light when the temperature is 0.

property Light::colorWarm

The hex color code that represents the light when the temperature is 100.

property Light::location

The location of the light inside the room.

property Light::room

The room where the light is located.

property Light::hasColor

Whether the light has a light color or not.

property Light::hasDimlevel

Whether the light can be dimmed or not.

property Light::hasTemperature

Whether the light has a light temperature or not.

property Light::lightState

The current state of the light.

property Light::temperature

This property holds the light temperature.

The value is in the range from 0 to 100 where 0 is cold and 100 warm.

property Light::dimlevel

This property holds the dim-level of the light.

The value is in the range from 0 to 100 where 0 is off and 100 full on.

class LightClient : public QObject

Handles all Light services and related Room settings.

Public Types

enum MessageId

Message ID used to communicate with the Knut server via the KnutClient::writeRequest().

Values:

STATUS_REQUEST = 1

Requests the status of a Light. The message must have the key uniqueName.

STATUS_RESPONSE = 2

The status of a Light.

LIGHTS_REQUEST = 3

Requests the status of all Light.

LIGHTS_RESPONSE = 4

A STATUS_RESPONSE for all Light services registered by the Knut server.

ALL_LIGHTS_REQUEST = 5

Requests the combined state of all lights.

ALL_LIGHTS_RESPONSE = 6

The state of all Light services combined.

See

lightStateAll

ROOMS_LIST_REQUEST = 7

Request a list of all registered Room.

ROOMS_LIST_RESPONSE = 8

The list of all registered Room.

ROOM_REQUEST = 9

Requests the state of a single Room.

ROOM_RESPONSE = 10

The state of a single Room where the state value is analog to the lightStateAll value.

Public Functions

void connectToClient(KnutClient *knutClient)

Connects to the KnutClient knutClient.

Connects the onKnutConnected() slot to the KnutClient::knutConnected() signal and the onReadyRead() slot to the signal KnutClient::receivedMessage() signal.

void setLightStateAll(const float &lightStateAll)

Sends the lightStateAll as LightClient::ALL_LIGHTS_RESPONSE to the Knut server.

Public Slots

void onReadyRead(const QJsonObject &message, const quint8 &serviceId, const quint16 &messageId)

Slot called when a message is available.

If a message is received by the KnutClient, this slot is called. If the serviceId is 0x02, a corresponding response handle method is called for the messageId.

See

LightClient::MessageId

Property

property LightClient::lightModel

The model of all lights with the roles location, room and light where light references to a Light service.

property LightClient::roomModel

The model of all rooms with the roles roomName and room where room references to a Room.

property LightClient::lightStateAll

The state of all lights where -1 is all off, 1 all on and 0 neither all on nor off.

class Room : public QObject

Public Slots

void handleRoomResponse(const int &roomState)

Handles a ROOM_RESPONSE message.

Handles a ROOM_RESPONSE message and updates the roomState if it changed.

See

Room::setRoomState()