Skip to content

Commit

Permalink
Yeelight: Wizard now supports more models, workaround for music-mode …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ratawhisk authored Feb 5, 2024
1 parent 58920df commit e1b3287
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 🆕)
Expand Down
2 changes: 1 addition & 1 deletion sources/leddevice/LedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QTimer>(new QTimer());
Expand Down
37 changes: 32 additions & 5 deletions sources/leddevice/dev_net/LedDeviceYeelight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ bool YeelightLight::setPower(bool on, YeelightLight::API_EFFECT effect, int dura
static_cast<int>(_isOn), static_cast<int>(_isInMusicMode));

// Disable music mode to get power-off command executed
setMusicMode(false);
if (!on && _isInMusicMode)
{
if (_tcpStreamSocket != nullptr)
Expand All @@ -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<int>(rc), static_cast<int>(_isOn), static_cast<int>(_isInMusicMode));

return rc;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1516,5 +1538,10 @@ int LedDeviceYeelight::write(const std::vector<ColorRgb>& ledValues)

//DebugIf(verbose, _log, "rc [%d]", rc );

if (_isDeviceInError)
{
setupRetry(3000);
}

return rc;
}
20 changes: 15 additions & 5 deletions sources/leddevice/schemas/schema-yeelight.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down Expand Up @@ -140,8 +151,7 @@
"propertyOrder" : 3
}
}
},
"propertyOrder" : 10
}
},
"quotaWait": {
"type": "integer",
Expand All @@ -152,7 +162,7 @@
"maximum": 10000,
"step": 100,
"access" : "expert",
"propertyOrder" : 11
"propertyOrder" : 12
},
"debugLevel": {
"type": "integer",
Expand Down
2 changes: 1 addition & 1 deletion www/js/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e1b3287

Please sign in to comment.