gateway now inherits connectable

master
Michael Zanetti 2018-10-25 12:07:38 +02:00
parent cd34fd80a2
commit ff6c8f1ce0
10 changed files with 35 additions and 23 deletions

View File

@ -66,13 +66,13 @@ void DevicePluginNetatmo::init()
DeviceManager::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device)
{
if (device->deviceClassId() == connectionDeviceClassId) {
if (device->deviceClassId() == netatmoConnectionDeviceClassId) {
qCDebug(dcNetatmo) << "Setup netatmo connection" << device->name() << device->params();
OAuth2 *authentication = new OAuth2("561c015d49c75f0d1cce6e13", "GuvKkdtu7JQlPD47qTTepRR9hQ0CUPAj4Tae3Ohcq", this);
authentication->setUrl(QUrl("https://api.netatmo.net/oauth2/token"));
authentication->setUsername(device->paramValue(connectionDeviceUsernameParamTypeId).toString());
authentication->setPassword(device->paramValue(connectionDevicePasswordParamTypeId).toString());
authentication->setUsername(device->paramValue(netatmoConnectionDeviceUsernameParamTypeId).toString());
authentication->setPassword(device->paramValue(netatmoConnectionDevicePasswordParamTypeId).toString());
authentication->setScope("read_station read_thermostat write_thermostat");
m_authentications.insert(authentication, device);
@ -109,7 +109,7 @@ DeviceManager::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device
void DevicePluginNetatmo::deviceRemoved(Device *device)
{
if (device->deviceClassId() == connectionDeviceClassId) {
if (device->deviceClassId() == netatmoConnectionDeviceClassId) {
OAuth2 * authentication = m_authentications.key(device);
m_authentications.remove(authentication);
authentication->deleteLater();
@ -252,7 +252,7 @@ void DevicePluginNetatmo::onNetworkReplyFinished()
// check HTTP status code
if (status != 200) {
qCWarning(dcNetatmo) << "Device list reply HTTP error:" << status << reply->errorString();
device->setStateValue(connectionAvailableStateTypeId, false);
device->setStateValue(netatmoConnectionConnectedStateTypeId, false);
reply->deleteLater();
return;
}
@ -282,7 +282,7 @@ void DevicePluginNetatmo::onAuthenticationChanged()
return;
// set the available state
device->setStateValue(connectionAvailableStateTypeId, authentication->authenticated());
device->setStateValue(netatmoConnectionConnectedStateTypeId, authentication->authenticated());
// check if this is was a setup athentication
if (m_asyncSetups.contains(device)) {

View File

@ -10,7 +10,7 @@
"deviceClasses": [
{
"id": "728d5a67-27a3-400e-b83c-2765f5196f69",
"name": "connection",
"name": "netatmoConnection",
"displayName": "Netatmo Connection",
"criticalStateTypeId": "2f79bc1d-27ed-480a-b583-728363c83ea6",
"deviceIcon": "Network",
@ -40,7 +40,7 @@
"stateTypes": [
{
"id": "2f79bc1d-27ed-480a-b583-728363c83ea6",
"name": "available",
"name": "connected",
"displayName": "available",
"displayNameEvent": "available changed",
"type": "bool",

View File

@ -122,7 +122,7 @@ DeviceManager::DeviceError DevicePluginOrderButton::executeAction(Device *device
qCDebug(dcOrderButton) << "Execute action" << device->name() << action.params();
// Check if the device is reachable
if (!device->stateValue(orderbuttonReachableStateTypeId).toBool()) {
if (!device->stateValue(orderbuttonConnectedStateTypeId).toBool()) {
qCWarning(dcOrderButton) << "Device not reachable.";
return DeviceManager::DeviceErrorHardwareNotAvailable;
}
@ -273,7 +273,7 @@ void DevicePluginOrderButton::enableNotifications(Device *device)
void DevicePluginOrderButton::setReachable(Device *device, const bool &reachable)
{
if (device->stateValue(orderbuttonReachableStateTypeId).toBool() != reachable) {
if (device->stateValue(orderbuttonConnectedStateTypeId).toBool() != reachable) {
if (!reachable) {
// Warn just once that the device is not reachable
qCWarning(dcOrderButton()) << device->name() << "reachable changed" << reachable;
@ -291,7 +291,7 @@ void DevicePluginOrderButton::setReachable(Device *device, const bool &reachable
}
}
device->setStateValue(orderbuttonReachableStateTypeId, reachable);
device->setStateValue(orderbuttonConnectedStateTypeId, reachable);
}
bool DevicePluginOrderButton::deviceAlreadyAdded(const QHostAddress &address)
@ -377,7 +377,7 @@ void DevicePluginOrderButton::coapReplyFinished(CoapReply *reply)
// Check CoAP reply error
if (reply->error() != CoapReply::NoError) {
if (device->stateValue(orderbuttonReachableStateTypeId).toBool())
if (device->stateValue(orderbuttonConnectedStateTypeId).toBool())
qCWarning(dcOrderButton) << "Ping device" << reply->request().url().toString() << "reply finished with error" << reply->errorString();
setReachable(device, false);

View File

@ -58,7 +58,7 @@
},
{
"id": "783e74ee-ffd6-4dd7-ade5-3a961452cf15",
"name": "reachable",
"name": "connected",
"displayNameEvent": "reachable changed",
"displayName": "reachable",
"type": "bool",

View File

@ -34,6 +34,17 @@
"type": "QString",
"inputType": "IPv6Address"
}
],
"stateTypes": [
{
"id": "2389b6c4-31ad-4058-bcc9-c2feb0c041d8",
"name": "connected",
"displayName": "Connected",
"displayNameEvent": "Connected changed",
"type": "bool",
"defaultValue": true
}
]
},
{

View File

@ -123,7 +123,7 @@ DeviceManager::DeviceError DevicePluginPlantCare::executeAction(Device *device,
qCDebug(dcPlantCare) << "Execute action" << device->name() << action.params();
// Check if the device is reachable
if (!device->stateValue(plantCareReachableStateTypeId).toBool()) {
if (!device->stateValue(plantCareConnectedStateTypeId).toBool()) {
qCWarning(dcPlantCare) << "Device not reachable.";
return DeviceManager::DeviceErrorHardwareNotAvailable;
}
@ -316,7 +316,7 @@ void DevicePluginPlantCare::enableNotifications(Device *device)
void DevicePluginPlantCare::setReachable(Device *device, const bool &reachable)
{
if (device->stateValue(plantCareReachableStateTypeId).toBool() != reachable) {
if (device->stateValue(plantCareConnectedStateTypeId).toBool() != reachable) {
if (!reachable) {
// Warn just once that the device is not reachable
qCWarning(dcPlantCare()) << device->name() << "reachable changed" << reachable;
@ -335,7 +335,7 @@ void DevicePluginPlantCare::setReachable(Device *device, const bool &reachable)
}
}
device->setStateValue(plantCareReachableStateTypeId, reachable);
device->setStateValue(plantCareConnectedStateTypeId, reachable);
}
bool DevicePluginPlantCare::deviceAlreadyAdded(const QHostAddress &address)
@ -421,7 +421,7 @@ void DevicePluginPlantCare::coapReplyFinished(CoapReply *reply)
// Check CoAP reply error
if (reply->error() != CoapReply::NoError) {
if (device->stateValue(plantCareReachableStateTypeId).toBool())
if (device->stateValue(plantCareConnectedStateTypeId).toBool())
qCWarning(dcPlantCare) << "Ping device" << reply->request().url().toString() << "reply finished with error" << reply->errorString();
setReachable(device, false);

View File

@ -88,7 +88,7 @@
},
{
"id": "8384e07b-8b91-492a-b6c8-e72b325ba0b4",
"name": "reachable",
"name": "connected",
"displayName": "reachable",
"displayNameEvent": "reachable changed",
"type": "bool",

View File

@ -115,6 +115,7 @@
"displayName": "Snap",
"createMethods": [ "auto" ],
"basicTags": [ "Gateway" ],
"interfaces": ["system"],
"deviceIcon": "Network",
"paramTypes": [
{

View File

@ -128,7 +128,7 @@ DeviceManager::DeviceError DevicePluginWs2812::executeAction(Device *device, con
qCDebug(dcWs2812) << "Execute action" << device->name() << action.params();
// Check if the device is reachable
if (!device->stateValue(ws2812ReachableStateTypeId).toBool()) {
if (!device->stateValue(ws2812ConnectedStateTypeId).toBool()) {
qCWarning(dcWs2812) << "Device not reachable.";
return DeviceManager::DeviceErrorHardwareNotAvailable;
}
@ -468,7 +468,7 @@ void DevicePluginWs2812::enableNotifications(Device *device)
void DevicePluginWs2812::setReachable(Device *device, const bool &reachable)
{
if (device->stateValue(ws2812ReachableStateTypeId).toBool() != reachable) {
if (device->stateValue(ws2812ConnectedStateTypeId).toBool() != reachable) {
if (!reachable) {
// Warn just once that the device is not reachable
qCWarning(dcWs2812()) << device->name() << "reachable changed" << reachable;
@ -487,7 +487,7 @@ void DevicePluginWs2812::setReachable(Device *device, const bool &reachable)
}
}
device->setStateValue(ws2812ReachableStateTypeId, reachable);
device->setStateValue(ws2812ConnectedStateTypeId, reachable);
}
bool DevicePluginWs2812::deviceAlreadyAdded(const QHostAddress &address)
@ -573,7 +573,7 @@ void DevicePluginWs2812::coapReplyFinished(CoapReply *reply)
// Check CoAP reply error
if (reply->error() != CoapReply::NoError) {
if (device->stateValue(ws2812ReachableStateTypeId).toBool())
if (device->stateValue(ws2812ConnectedStateTypeId).toBool())
qCWarning(dcWs2812) << "Ping device" << reply->request().url().toString() << "reply finished with error" << reply->errorString();
setReachable(device, false);

View File

@ -50,7 +50,7 @@
},
{
"id": "08091cde-983d-42f7-bdd7-d89c312ccbed",
"name": "reachable",
"name": "connected",
"displayName": "reachable",
"displayNameEvent": "reachable changed",
"type": "bool",