Update Elgato (avea) plugin
This commit is contained in:
parent
0283001acb
commit
f299653607
@ -395,26 +395,56 @@ void DevicePluginElgato::init()
|
|||||||
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginElgato::onPluginTimer);
|
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginElgato::onPluginTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::DeviceError DevicePluginElgato::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
void DevicePluginElgato::discoverDevices(DeviceDiscoveryInfo *info)
|
||||||
{
|
{
|
||||||
Q_UNUSED(params)
|
DeviceClassId deviceClassId = info->deviceClassId();
|
||||||
|
|
||||||
if (deviceClassId != aveaDeviceClassId)
|
if (deviceClassId != aveaDeviceClassId)
|
||||||
return Device::DeviceErrorDeviceClassNotFound;
|
return info->finish(Device::DeviceErrorDeviceClassNotFound);
|
||||||
|
|
||||||
if (!hardwareManager()->bluetoothLowEnergyManager()->available())
|
if (!hardwareManager()->bluetoothLowEnergyManager()->available())
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
if (!hardwareManager()->bluetoothLowEnergyManager()->enabled())
|
if (!hardwareManager()->bluetoothLowEnergyManager()->enabled())
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices();
|
BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices();
|
||||||
connect(reply, &BluetoothDiscoveryReply::finished, this, &DevicePluginElgato::onBluetoothDiscoveryFinished);
|
connect(reply, &BluetoothDiscoveryReply::finished, info, [this, info, reply]{
|
||||||
return Device::DeviceErrorAsync;
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != BluetoothDiscoveryReply::BluetoothDiscoveryReplyErrorNoError) {
|
||||||
|
qCWarning(dcElgato()) << "Bluetooth discovery error:" << reply->error();
|
||||||
|
info->finish(Device::DeviceErrorHardwareFailure);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const QBluetoothDeviceInfo &deviceInfo, reply->discoveredDevices()) {
|
||||||
|
if (deviceInfo.name().contains("Avea")) {
|
||||||
|
if (!verifyExistingDevices(deviceInfo)) {
|
||||||
|
DeviceDescriptor descriptor(aveaDeviceClassId, "Avea", deviceInfo.address().toString());
|
||||||
|
ParamList params;
|
||||||
|
params.append(Param(aveaDeviceNameParamTypeId, deviceInfo.name()));
|
||||||
|
params.append(Param(aveaDeviceMacAddressParamTypeId, deviceInfo.address().toString()));
|
||||||
|
descriptor.setParams(params);
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(aveaDeviceMacAddressParamTypeId).toString() == deviceInfo.address().toString()) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
info->addDeviceDescriptor(descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info->finish(Device::DeviceErrorNoError);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::DeviceSetupStatus DevicePluginElgato::setupDevice(Device *device)
|
void DevicePluginElgato::setupDevice(DeviceSetupInfo *info)
|
||||||
{
|
{
|
||||||
|
Device *device = info->device();
|
||||||
|
|
||||||
qCDebug(dcElgato()) << "Setup device" << device->name() << device->params();
|
qCDebug(dcElgato()) << "Setup device" << device->name() << device->params();
|
||||||
|
|
||||||
if (device->deviceClassId() == aveaDeviceClassId) {
|
if (device->deviceClassId() == aveaDeviceClassId) {
|
||||||
@ -427,9 +457,9 @@ Device::DeviceSetupStatus DevicePluginElgato::setupDevice(Device *device)
|
|||||||
AveaBulb *bulb = new AveaBulb(device, bluetoothDevice, this);
|
AveaBulb *bulb = new AveaBulb(device, bluetoothDevice, this);
|
||||||
m_bulbs.insert(device, bulb);
|
m_bulbs.insert(device, bulb);
|
||||||
|
|
||||||
return Device::DeviceSetupStatusSuccess;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
}
|
}
|
||||||
return Device::DeviceSetupStatusFailure;
|
return info->finish(Device::DeviceErrorDeviceClassNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginElgato::postSetupDevice(Device *device)
|
void DevicePluginElgato::postSetupDevice(Device *device)
|
||||||
@ -446,8 +476,11 @@ void DevicePluginElgato::postSetupDevice(Device *device)
|
|||||||
bulb->bluetoothDevice()->connectDevice();
|
bulb->bluetoothDevice()->connectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::DeviceError DevicePluginElgato::executeAction(Device *device, const Action &action)
|
void DevicePluginElgato::executeAction(DeviceActionInfo *info)
|
||||||
{
|
{
|
||||||
|
Device *device = info->device();
|
||||||
|
Action action = info->action();
|
||||||
|
|
||||||
if (device->deviceClassId() == aveaDeviceClassId) {
|
if (device->deviceClassId() == aveaDeviceClassId) {
|
||||||
AveaBulb *bulb = m_bulbs.value(device);
|
AveaBulb *bulb = m_bulbs.value(device);
|
||||||
|
|
||||||
@ -455,22 +488,22 @@ Device::DeviceError DevicePluginElgato::executeAction(Device *device, const Acti
|
|||||||
bool power = action.param(aveaPowerActionPowerParamTypeId).value().toBool();
|
bool power = action.param(aveaPowerActionPowerParamTypeId).value().toBool();
|
||||||
device->setStateValue(aveaPowerStateTypeId, power);
|
device->setStateValue(aveaPowerStateTypeId, power);
|
||||||
if (!bulb->setPower(power))
|
if (!bulb->setPower(power))
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (action.actionTypeId() == aveaBrightnessActionTypeId) {
|
} else if (action.actionTypeId() == aveaBrightnessActionTypeId) {
|
||||||
int percentage = action.param(aveaBrightnessActionBrightnessParamTypeId).value().toInt();
|
int percentage = action.param(aveaBrightnessActionBrightnessParamTypeId).value().toInt();
|
||||||
if (!bulb->setBrightness(percentage))
|
if (!bulb->setBrightness(percentage))
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (action.actionTypeId() == aveaColorActionTypeId) {
|
} else if (action.actionTypeId() == aveaColorActionTypeId) {
|
||||||
QColor color = action.param(aveaColorActionColorParamTypeId).value().value<QColor>();
|
QColor color = action.param(aveaColorActionColorParamTypeId).value().value<QColor>();
|
||||||
color.setAlpha(0); // Alpha is white
|
color.setAlpha(0); // Alpha is white
|
||||||
if (!bulb->setColor(color))
|
if (!bulb->setColor(color))
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (action.actionTypeId() == aveaColorTemperatureActionTypeId) {
|
} else if (action.actionTypeId() == aveaColorTemperatureActionTypeId) {
|
||||||
int ctValue = action.param(aveaColorTemperatureActionColorTemperatureParamTypeId).value().toInt();
|
int ctValue = action.param(aveaColorTemperatureActionColorTemperatureParamTypeId).value().toInt();
|
||||||
// normalize from 0 to 347 instead of 153 to 500
|
// normalize from 0 to 347 instead of 153 to 500
|
||||||
@ -488,45 +521,45 @@ Device::DeviceError DevicePluginElgato::executeAction(Device *device, const Acti
|
|||||||
color.setBlue(blue);
|
color.setBlue(blue);
|
||||||
color.setAlpha(255); // Alpha is white
|
color.setAlpha(255); // Alpha is white
|
||||||
if (!bulb->setColor(color)) {
|
if (!bulb->setColor(color)) {
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
}
|
}
|
||||||
device->setStateValue(aveaColorTemperatureStateTypeId, ctValue);
|
device->setStateValue(aveaColorTemperatureStateTypeId, ctValue);
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (action.actionTypeId() == aveaWhiteActionTypeId) {
|
} else if (action.actionTypeId() == aveaWhiteActionTypeId) {
|
||||||
int whiteValue = action.param(aveaWhiteActionWhiteParamTypeId).value().toInt();
|
int whiteValue = action.param(aveaWhiteActionWhiteParamTypeId).value().toInt();
|
||||||
if (!bulb->setWhite(whiteValue))
|
if (!bulb->setWhite(whiteValue))
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (action.actionTypeId() == aveaGreenActionTypeId) {
|
} else if (action.actionTypeId() == aveaGreenActionTypeId) {
|
||||||
int greenValue = action.param(aveaGreenActionGreenParamTypeId).value().toInt();
|
int greenValue = action.param(aveaGreenActionGreenParamTypeId).value().toInt();
|
||||||
if (!bulb->setGreen(greenValue))
|
if (!bulb->setGreen(greenValue))
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (action.actionTypeId() == aveaRedActionTypeId) {
|
} else if (action.actionTypeId() == aveaRedActionTypeId) {
|
||||||
int redValue = action.param(aveaRedActionRedParamTypeId).value().toInt();
|
int redValue = action.param(aveaRedActionRedParamTypeId).value().toInt();
|
||||||
if (!bulb->setRed(redValue))
|
if (!bulb->setRed(redValue))
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (action.actionTypeId() == aveaBlueActionTypeId) {
|
} else if (action.actionTypeId() == aveaBlueActionTypeId) {
|
||||||
int blueValue = action.param(aveaBlueActionBlueParamTypeId).value().toInt();
|
int blueValue = action.param(aveaBlueActionBlueParamTypeId).value().toInt();
|
||||||
if (!bulb->setBlue(blueValue))
|
if (!bulb->setBlue(blueValue))
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
} else if (action.actionTypeId() == aveaFadeActionTypeId) {
|
} else if (action.actionTypeId() == aveaFadeActionTypeId) {
|
||||||
int fadeValue = action.param(aveaFadeActionFadeParamTypeId).value().toInt();
|
int fadeValue = action.param(aveaFadeActionFadeParamTypeId).value().toInt();
|
||||||
if (!bulb->setFade(fadeValue))
|
if (!bulb->setFade(fadeValue))
|
||||||
return Device::DeviceErrorHardwareNotAvailable;
|
return info->finish(Device::DeviceErrorHardwareNotAvailable);
|
||||||
|
|
||||||
return Device::DeviceErrorNoError;
|
return info->finish(Device::DeviceErrorNoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Device::DeviceErrorActionTypeNotFound;
|
return info->finish(Device::DeviceErrorActionTypeNotFound);
|
||||||
}
|
}
|
||||||
return Device::DeviceErrorDeviceClassNotFound;
|
return info->finish(Device::DeviceErrorDeviceClassNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginElgato::deviceRemoved(Device *device)
|
void DevicePluginElgato::deviceRemoved(Device *device)
|
||||||
@ -559,38 +592,3 @@ void DevicePluginElgato::onPluginTimer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginElgato::onBluetoothDiscoveryFinished()
|
|
||||||
{
|
|
||||||
BluetoothDiscoveryReply *reply = static_cast<BluetoothDiscoveryReply *>(sender());
|
|
||||||
if (reply->error() != BluetoothDiscoveryReply::BluetoothDiscoveryReplyErrorNoError) {
|
|
||||||
qCWarning(dcElgato()) << "Bluetooth discovery error:" << reply->error();
|
|
||||||
reply->deleteLater();
|
|
||||||
emit devicesDiscovered(aveaDeviceClassId, QList<DeviceDescriptor>());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<DeviceDescriptor> deviceDescriptors;
|
|
||||||
foreach (const QBluetoothDeviceInfo &deviceInfo, reply->discoveredDevices()) {
|
|
||||||
if (deviceInfo.name().contains("Avea")) {
|
|
||||||
if (!verifyExistingDevices(deviceInfo)) {
|
|
||||||
DeviceDescriptor descriptor(aveaDeviceClassId, "Avea", deviceInfo.address().toString());
|
|
||||||
ParamList params;
|
|
||||||
params.append(Param(aveaDeviceNameParamTypeId, deviceInfo.name()));
|
|
||||||
params.append(Param(aveaDeviceMacAddressParamTypeId, deviceInfo.address().toString()));
|
|
||||||
descriptor.setParams(params);
|
|
||||||
foreach (Device *existingDevice, myDevices()) {
|
|
||||||
if (existingDevice->paramValue(aveaDeviceMacAddressParamTypeId).toString() == deviceInfo.address().toString()) {
|
|
||||||
descriptor.setDeviceId(existingDevice->id());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deviceDescriptors.append(descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
reply->deleteLater();
|
|
||||||
|
|
||||||
emit devicesDiscovered(aveaDeviceClassId, deviceDescriptors);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@ -40,10 +40,10 @@ public:
|
|||||||
~DevicePluginElgato();
|
~DevicePluginElgato();
|
||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
void discoverDevices(DeviceDiscoveryInfo *info) override;
|
||||||
Device::DeviceSetupStatus setupDevice(Device *device) override;
|
void setupDevice(DeviceSetupInfo *info) override;
|
||||||
void postSetupDevice(Device *device) override;
|
void postSetupDevice(Device *device) override;
|
||||||
Device::DeviceError executeAction(Device *device, const Action &action) override;
|
void executeAction(DeviceActionInfo *info) override;
|
||||||
void deviceRemoved(Device *device) override;
|
void deviceRemoved(Device *device) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -54,7 +54,6 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPluginTimer();
|
void onPluginTimer();
|
||||||
void onBluetoothDiscoveryFinished();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
"id": "164f9602-90ee-4693-bda3-9cafae37603e",
|
"id": "164f9602-90ee-4693-bda3-9cafae37603e",
|
||||||
"name": "avea",
|
"name": "avea",
|
||||||
"displayName": "Avea",
|
"displayName": "Avea",
|
||||||
"interfaces": ["connectable", "light", "colorlight", "colortemperaturelight"],
|
"interfaces": ["light", "colorlight", "colortemperaturelight", "connectable"],
|
||||||
"createMethods": ["discovery"],
|
"createMethods": ["discovery"],
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user