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.
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
to100
where0
is cold and100
warm.
-
property
Light::dimlevel
This property holds the dim-level of the light.
The value is in the range from
0
to100
where0
is off and100
full on.
-
void
-
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:
-
ALL_LIGHTS_REQUEST
= 5¶ Requests the combined state of all lights.
-
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.
Property
-
property
LightClient::lightModel
The model of all lights with the roles
location
,room
andlight
wherelight
references to a Light service.
-
property
LightClient::roomModel
The model of all rooms with the roles
roomName
androom
whereroom
references to a Room.
-
property
LightClient::lightStateAll
The state of all lights where
-1
is all off,1
all on and0
neither all on nor off.
-
enum