fix handling DeviceChanged notification
This commit is contained in:
parent
dbe793a471
commit
1d1424f52f
@ -121,7 +121,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
|||||||
device->deleteLater();
|
device->deleteLater();
|
||||||
} else if (notification == "Devices.DeviceChanged") {
|
} else if (notification == "Devices.DeviceChanged") {
|
||||||
QUuid deviceId = data.value("params").toMap().value("device").toMap().value("id").toUuid();
|
QUuid deviceId = data.value("params").toMap().value("device").toMap().value("id").toUuid();
|
||||||
qDebug() << "Device changed notification" << deviceId;
|
qDebug() << "Device changed notification" << deviceId << data.value("params").toMap();
|
||||||
Device *oldDevice = m_devices->getDevice(deviceId);
|
Device *oldDevice = m_devices->getDevice(deviceId);
|
||||||
if (!oldDevice) {
|
if (!oldDevice) {
|
||||||
qWarning() << "Received a device changed notification for a device we don't know";
|
qWarning() << "Received a device changed notification for a device we don't know";
|
||||||
@ -131,6 +131,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
|||||||
qWarning() << "Error parsing device changed notification";
|
qWarning() << "Error parsing device changed notification";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
qDebug() << "*** device unpacked" << oldDevice->stateValue("98e4476f-e745-4a7f-b795-19269cb70c40");
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "DeviceManager unhandled device notification received" << notification;
|
qWarning() << "DeviceManager unhandled device notification received" << notification;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -232,10 +232,18 @@ Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *dev
|
|||||||
}
|
}
|
||||||
device->setParams(params);
|
device->setParams(params);
|
||||||
|
|
||||||
States *states = new States(device);
|
States *states = device->states();
|
||||||
foreach (StateType *stateType, deviceClass->stateTypes()->stateTypes()) {
|
if (!states) {
|
||||||
State *state = new State(device->id(), stateType->id(), stateType->defaultValue(), states);
|
states = new States(device);
|
||||||
states->addState(state);
|
}
|
||||||
|
foreach (const QVariant &stateVariant, deviceMap.value("states").toList()) {
|
||||||
|
State *state = states->getState(stateVariant.toMap().value("stateTypeId").toUuid());
|
||||||
|
if (!state) {
|
||||||
|
state = new State(device->id(), stateVariant.toMap().value("stateTypeId").toUuid(), stateVariant.toMap().value("value"), states);
|
||||||
|
states->addState(state);
|
||||||
|
} else {
|
||||||
|
state->setValue(stateVariant.toMap().value("value"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
device->setStates(states);
|
device->setStates(states);
|
||||||
|
|
||||||
|
|||||||
@ -75,8 +75,13 @@ Params *Device::params() const
|
|||||||
|
|
||||||
void Device::setParams(Params *params)
|
void Device::setParams(Params *params)
|
||||||
{
|
{
|
||||||
m_params = params;
|
if (m_params != params) {
|
||||||
emit paramsChanged();
|
if (m_params) {
|
||||||
|
m_params->deleteLater();
|
||||||
|
}
|
||||||
|
m_params = params;
|
||||||
|
emit paramsChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
States *Device::states() const
|
States *Device::states() const
|
||||||
@ -86,8 +91,13 @@ States *Device::states() const
|
|||||||
|
|
||||||
void Device::setStates(States *states)
|
void Device::setStates(States *states)
|
||||||
{
|
{
|
||||||
m_states = states;
|
if (m_states != states) {
|
||||||
emit statesChanged();
|
if (m_states) {
|
||||||
|
m_states->deleteLater();
|
||||||
|
}
|
||||||
|
m_states = states;
|
||||||
|
emit statesChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceClass *Device::deviceClass() const
|
DeviceClass *Device::deviceClass() const
|
||||||
|
|||||||
@ -76,6 +76,7 @@ QVariant States::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
void States::addState(State *state)
|
void States::addState(State *state)
|
||||||
{
|
{
|
||||||
|
state->setParent(this);
|
||||||
beginInsertRows(QModelIndex(), m_states.count(), m_states.count());
|
beginInsertRows(QModelIndex(), m_states.count(), m_states.count());
|
||||||
//qDebug() << "States: loaded state" << state->stateTypeId();
|
//qDebug() << "States: loaded state" << state->stateTypeId();
|
||||||
m_states.append(state);
|
m_states.append(state);
|
||||||
|
|||||||
Reference in New Issue
Block a user