mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Fix/Workaround set-music error when music is already off (#1379)
* Fix/Workaround set-music error when music is already off * Do not ignore error when setting music mode
This commit is contained in:
parent
a0d4efc10d
commit
442fab9c59
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Yeelight - Workaround: Ignore error when setting music mode = off, but the music-mode is already off (#1372)
|
||||||
- Standalone grabbers: Improved fps help/error text, fixed default address and port
|
- Standalone grabbers: Improved fps help/error text, fixed default address and port
|
||||||
|
|
||||||
## Removed
|
## Removed
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "LedDeviceYeelight.h"
|
#include "LedDeviceYeelight.h"
|
||||||
|
|
||||||
#include <ssdp/SSDPDiscover.h>
|
#include <ssdp/SSDPDiscover.h>
|
||||||
#include <utils/QStringUtils.h>
|
#include <utils/QStringUtils.h>
|
||||||
@ -202,13 +202,13 @@ bool YeelightLight::close()
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int YeelightLight::writeCommand( const QJsonDocument &command )
|
int YeelightLight::writeCommand( const QJsonDocument &command, bool ignoreErrors )
|
||||||
{
|
{
|
||||||
QJsonArray result;
|
QJsonArray result;
|
||||||
return writeCommand(command, result );
|
return writeCommand(command, result, ignoreErrors );
|
||||||
}
|
}
|
||||||
|
|
||||||
int YeelightLight::writeCommand( const QJsonDocument &command, QJsonArray &result )
|
int YeelightLight::writeCommand( const QJsonDocument &command, QJsonArray &result, bool ignoreErrors )
|
||||||
{
|
{
|
||||||
log( 3,
|
log( 3,
|
||||||
"writeCommand()",
|
"writeCommand()",
|
||||||
@ -277,11 +277,19 @@ int YeelightLight::writeCommand( const QJsonDocument &command, QJsonArray &resul
|
|||||||
result = yeeResponse.getResult();
|
result = yeeResponse.getResult();
|
||||||
QString errorReason = QString ("(%1) %2").arg(yeeResponse.getErrorCode()).arg( yeeResponse.getErrorReason() );
|
QString errorReason = QString ("(%1) %2").arg(yeeResponse.getErrorCode()).arg( yeeResponse.getErrorReason() );
|
||||||
if ( yeeResponse.getErrorCode() != -1)
|
if ( yeeResponse.getErrorCode() != -1)
|
||||||
|
{
|
||||||
|
if (!ignoreErrors)
|
||||||
{
|
{
|
||||||
this->setInError ( errorReason );
|
this->setInError ( errorReason );
|
||||||
rc =-1;
|
rc =-1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
log ( 1, "writeCommand():", "Ignore Error: %s", QSTRING_CSTR(errorReason) );
|
||||||
|
rc = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
//(-1) client quota exceeded
|
//(-1) client quota exceeded
|
||||||
log ( 1, "writeCommand():", "%s", QSTRING_CSTR(errorReason) );
|
log ( 1, "writeCommand():", "%s", QSTRING_CSTR(errorReason) );
|
||||||
@ -693,6 +701,13 @@ bool YeelightLight::setPower(bool on, YeelightLight::API_EFFECT effect, int dura
|
|||||||
_tcpStreamSocket->close();
|
_tcpStreamSocket->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( !_isInMusicMode && isInMusicMode(true) )
|
||||||
|
{
|
||||||
|
setMusicMode(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString powerParam = on ? API_METHOD_POWER_ON : API_METHOD_POWER_OFF;
|
QString powerParam = on ? API_METHOD_POWER_ON : API_METHOD_POWER_OFF;
|
||||||
QString effectParam = effect == YeelightLight::API_EFFECT_SMOOTH ? API_PARAM_EFFECT_SMOOTH : API_PARAM_EFFECT_SUDDEN;
|
QString effectParam = effect == YeelightLight::API_EFFECT_SMOOTH ? API_PARAM_EFFECT_SMOOTH : API_PARAM_EFFECT_SUDDEN;
|
||||||
@ -711,7 +726,7 @@ bool YeelightLight::setPower(bool on, YeelightLight::API_EFFECT effect, int dura
|
|||||||
}
|
}
|
||||||
log( 2,
|
log( 2,
|
||||||
"setPower() rc",
|
"setPower() rc",
|
||||||
"%d, isON[%d], isInMusicMode[)%d]",
|
"%d, isON[%d], isInMusicMode[%d]",
|
||||||
static_cast<int>(rc), static_cast<int>( _isOn ), static_cast<int>( _isInMusicMode ) );
|
static_cast<int>(rc), static_cast<int>( _isOn ), static_cast<int>( _isInMusicMode ) );
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -930,7 +945,6 @@ bool YeelightLight::setMusicMode(bool on, const QHostAddress &hostAddress, int p
|
|||||||
if ( on )
|
if ( on )
|
||||||
{
|
{
|
||||||
paramlist << hostAddress.toString() << port;
|
paramlist << hostAddress.toString() << port;
|
||||||
}
|
|
||||||
|
|
||||||
// Music Mode is only on, if write did not fail nor quota was exceeded
|
// Music Mode is only on, if write did not fail nor quota was exceeded
|
||||||
if ( writeCommand( getCommand( API_METHOD_MUSIC_MODE, paramlist ) ) > -1 )
|
if ( writeCommand( getCommand( API_METHOD_MUSIC_MODE, paramlist ) ) > -1 )
|
||||||
@ -938,6 +952,16 @@ bool YeelightLight::setMusicMode(bool on, const QHostAddress &hostAddress, int p
|
|||||||
_isInMusicMode = on;
|
_isInMusicMode = on;
|
||||||
rc = true;
|
rc = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QJsonArray offParams = { API_METHOD_MUSIC_MODE_OFF };
|
||||||
|
if ( writeCommand( getCommand( API_METHOD_MUSIC_MODE, offParams ) ) > -1 )
|
||||||
|
{
|
||||||
|
_isInMusicMode = false;
|
||||||
|
rc = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log( 2,
|
log( 2,
|
||||||
"setMusicMode() rc", "%d, isInMusicMode[%d]", static_cast<int>( rc ), static_cast<int>( _isInMusicMode ) );
|
"setMusicMode() rc", "%d, isInMusicMode[%d]", static_cast<int>( rc ), static_cast<int>( _isInMusicMode ) );
|
||||||
|
@ -151,18 +151,20 @@ public:
|
|||||||
/// @brief Execute a Yeelight-API command
|
/// @brief Execute a Yeelight-API command
|
||||||
///
|
///
|
||||||
/// @param[in] command The API command request in JSON
|
/// @param[in] command The API command request in JSON
|
||||||
|
/// @param[in] ignoreErrors Return success, even if errors occured
|
||||||
/// @return 0: success, -1: error, -2: command quota exceeded
|
/// @return 0: success, -1: error, -2: command quota exceeded
|
||||||
///
|
///
|
||||||
int writeCommand( const QJsonDocument &command );
|
int writeCommand( const QJsonDocument &command, bool ignoreErrors = false );
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Execute a Yeelight-API command
|
/// @brief Execute a Yeelight-API command
|
||||||
///
|
///
|
||||||
/// @param[in] command The API command request in JSON
|
/// @param[in] command The API command request in JSON
|
||||||
/// @param[out] result The response to the command in JSON
|
/// @param[out] result The response to the command in JSON
|
||||||
|
/// @param[in] ignoreErrors Return success, even if errors occured
|
||||||
/// @return 0: success, -1: error, -2: command quota exceeded
|
/// @return 0: success, -1: error, -2: command quota exceeded
|
||||||
///
|
///
|
||||||
int writeCommand( const QJsonDocument &command, QJsonArray &result );
|
int writeCommand( const QJsonDocument &command, QJsonArray &result, bool ignoreErrors = false );
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @brief Stream a Yeelight-API command
|
/// @brief Stream a Yeelight-API command
|
||||||
|
Loading…
Reference in New Issue
Block a user