From e1b328743c597b2133778b9b957da16a11288a92 Mon Sep 17 00:00:00 2001 From: ratawhisk <83418788+ratawhisk@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:14:55 +0100 Subject: [PATCH] Yeelight: Wizard now supports more models, workaround for music-mode reset, auto-resume support (Fixes: #748) (#750) * Update LedDeviceYeelight.cpp * Update LedDeviceYeelight.cpp * Update LedDeviceYeelight.h * Update wizard.js * Update wizard.js * Revert before merge * Fix Yeelight * Add autoresume for Yeelight --- CHANGELOG.md | 1 + sources/leddevice/LedDevice.cpp | 2 +- .../leddevice/dev_net/LedDeviceYeelight.cpp | 37 ++++++++++++++++--- .../leddevice/schemas/schema-yeelight.json | 20 +++++++--- www/js/wizard.js | 2 +- 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b69b04838..48261685a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- Yeelight: Wizard now supports more models, workaround for music-mode reset, auto-resume support #750 Thanks @ratawhisk (v20 beta2 🆕) - Fix verbose command line option #737 (v20 beta2 🆕) - Add native build for Apple M1 / M2 (arm64) architecture #973 (v20 beta2 🆕) - New features: disable LEDs/components on startup #737 (v20 beta2 🆕) diff --git a/sources/leddevice/LedDevice.cpp b/sources/leddevice/LedDevice.cpp index 210e5a3dd..c5b55b597 100644 --- a/sources/leddevice/LedDevice.cpp +++ b/sources/leddevice/LedDevice.cpp @@ -166,7 +166,7 @@ int LedDevice::close() void LedDevice::setupRetry(int interval) { - if (_retryTimer == nullptr) + if (_retryTimer == nullptr && _maxRetry > 0) { _currentRetry = _maxRetry; _retryTimer = std::unique_ptr(new QTimer()); diff --git a/sources/leddevice/dev_net/LedDeviceYeelight.cpp b/sources/leddevice/dev_net/LedDeviceYeelight.cpp index 127a65270..cd49ec45f 100644 --- a/sources/leddevice/dev_net/LedDeviceYeelight.cpp +++ b/sources/leddevice/dev_net/LedDeviceYeelight.cpp @@ -684,6 +684,7 @@ bool YeelightLight::setPower(bool on, YeelightLight::API_EFFECT effect, int dura static_cast(_isOn), static_cast(_isInMusicMode)); // Disable music mode to get power-off command executed + setMusicMode(false); if (!on && _isInMusicMode) { if (_tcpStreamSocket != nullptr) @@ -709,7 +710,7 @@ bool YeelightLight::setPower(bool on, YeelightLight::API_EFFECT effect, int dura } log(2, "setPower() rc", - "%d, isON[%d], isInMusicMode[)%d]", + "%d, isON[%d], isInMusicMode[%d]", static_cast(rc), static_cast(_isOn), static_cast(_isInMusicMode)); return rc; @@ -928,12 +929,24 @@ bool YeelightLight::setMusicMode(bool on, const QHostAddress& hostAddress, int p if (on) { paramlist << hostAddress.toString() << port; + + // Music Mode is only on, if write did not fail nor quota was exceeded + if ( writeCommand( getCommand( API_METHOD_MUSIC_MODE, paramlist ) ) > -1 ) + { + _isInMusicMode = on; + rc = true; + } } - - // Music Mode is only on, if write did not fail nor quota was exceeded - if (writeCommand(getCommand(API_METHOD_MUSIC_MODE, paramlist)) > -1) + else { - _isInMusicMode = on; + auto wasInError = _isInError; + writeCommand( getCommand( API_METHOD_MUSIC_MODE, paramlist )); + if (_isInError && !wasInError) + { + Warning(_log, "Ignoring Yeelight error when turning off music mode"); + _isInError = false; + } + _isInMusicMode = false; rc = true; } @@ -1063,6 +1076,9 @@ bool LedDeviceYeelight::init(const QJsonObject& deviceConfig) _isRestoreOrigState = _devConfig[CONFIG_RESTORE_STATE].toBool(false); Debug(_log, "RestoreOrigState : %d", _isRestoreOrigState); + _maxRetry = deviceConfig["maxRetry"].toInt(60); + Debug(_log, "Max retry : %d", _maxRetry); + _waitTimeQuota = _devConfig[CONFIG_QUOTA_WAIT_TIME].toInt(0); Debug(_log, "Wait time (quota) : %d", _waitTimeQuota); @@ -1252,6 +1268,12 @@ int LedDeviceYeelight::open() } DebugIf(verbose, _log, "retval [%d], enabled [%d], _isDeviceReady [%d]", retval, _isEnabled, _isDeviceReady); + + if (!_isDeviceReady) + { + setupRetry(3000); + } + return retval; } @@ -1516,5 +1538,10 @@ int LedDeviceYeelight::write(const std::vector& ledValues) //DebugIf(verbose, _log, "rc [%d]", rc ); + if (_isDeviceInError) + { + setupRetry(3000); + } + return rc; } diff --git a/sources/leddevice/schemas/schema-yeelight.json b/sources/leddevice/schemas/schema-yeelight.json index d15f029b6..65e3d8fa7 100644 --- a/sources/leddevice/schemas/schema-yeelight.json +++ b/sources/leddevice/schemas/schema-yeelight.json @@ -100,11 +100,22 @@ "title":"edt_dev_spec_restoreOriginalState_title", "default" : false, "propertyOrder" : 9 - }, + }, + "maxRetry": { + "type" : "integer", + "format" : "stepper", + "step" : 1, + "title" : "edt_dev_max_retry", + "minimum" : 0, + "maximum" : 300, + "default" : 60, + "required" : true, + "propertyOrder" : 10 + }, "lights": { "type": "array", "title":"edt_dev_spec_lights_title", - "propertyOrder" : 9, + "propertyOrder" : 11, "minimum" : 1, "uniqueItems" : true, "items" : { @@ -140,8 +151,7 @@ "propertyOrder" : 3 } } - }, - "propertyOrder" : 10 + } }, "quotaWait": { "type": "integer", @@ -152,7 +162,7 @@ "maximum": 10000, "step": 100, "access" : "expert", - "propertyOrder" : 11 + "propertyOrder" : 12 }, "debugLevel": { "type": "integer", diff --git a/www/js/wizard.js b/www/js/wizard.js index a69f0fbf1..161cd9852 100644 --- a/www/js/wizard.js +++ b/www/js/wizard.js @@ -1781,7 +1781,7 @@ async function discover_yeelight_lights() function assign_yeelight_lights() { - var models = ['color', 'color1', 'color2', 'color4', 'stripe', 'strip1']; + var models = ['color', 'color1', 'YLDP02YL', 'YLDP02YL', 'color2', 'YLDP06YL', 'color4', 'YLDP13YL', 'color6', 'YLDP13AYL', 'colorc', "YLDP004-A", 'stripe', 'YLDD04YL', 'strip1', 'YLDD01YL', 'YLDD02YL', 'strip4', 'YLDD05YL', 'strip6', 'YLDD05YL']; // If records are left for configuration if (Object.keys(lights).length > 0)