@@ -164,14 +164,14 @@ CPanasonicNode::~CPanasonicNode(void)
164
164
if (DEBUG_LOGGING) _log.Log (LOG_STATUS, " Panasonic Plugin: (%s) Destroyed." , m_Name.c_str ());
165
165
}
166
166
167
- void CPanasonicNode::UpdateStatus ()
167
+ void CPanasonicNode::UpdateStatus (bool forceupdate )
168
168
{
169
169
std::vector<std::vector<std::string> > result;
170
170
m_CurrentStatus.LastOK (mytime (NULL ));
171
171
172
172
// 1: Update the DeviceStatus
173
173
174
- if (m_CurrentStatus.UpdateRequired (m_PreviousStatus))
174
+ if (m_CurrentStatus.UpdateRequired (m_PreviousStatus) || forceupdate )
175
175
{
176
176
result = m_sql.safe_query (" UPDATE DeviceStatus SET nValue=%d, sValue='%q', LastUpdate='%q' WHERE (HardwareID == %d) AND (DeviceID == '%q') AND (Unit == 1) AND (SwitchType == %d)" ,
177
177
int (m_CurrentStatus.Status ()), m_CurrentStatus.StatusMessage ().c_str (), m_CurrentStatus.LastOK ().c_str (), m_HwdID, m_szDevID, STYPE_Media);
@@ -180,15 +180,15 @@ void CPanasonicNode::UpdateStatus()
180
180
// 2: Log the event if the actual status has changed
181
181
std::string sLogText = m_CurrentStatus.StatusText ();
182
182
183
- if (m_CurrentStatus.LogRequired (m_PreviousStatus))
183
+ if (m_CurrentStatus.LogRequired (m_PreviousStatus) || forceupdate )
184
184
{
185
185
if (m_CurrentStatus.IsOn ()) sLogText += " - " + m_CurrentStatus.LogMessage ();
186
186
result = m_sql.safe_query (" INSERT INTO LightingLog (DeviceRowID, nValue, sValue) VALUES (%d, %d, '%q')" , m_ID, int (m_CurrentStatus.Status ()), sLogText .c_str ());
187
187
_log.Log (LOG_NORM, " Panasonic: (%s) Event: '%s'." , m_Name.c_str (), sLogText .c_str ());
188
188
}
189
189
190
190
// 3: Trigger On/Off actions
191
- if (m_CurrentStatus.OnOffRequired (m_PreviousStatus))
191
+ if (m_CurrentStatus.OnOffRequired (m_PreviousStatus) || forceupdate )
192
192
{
193
193
result = m_sql.safe_query (" SELECT StrParam1,StrParam2 FROM DeviceStatus WHERE (HardwareID==%d) AND (ID = '%q') AND (Unit == 1)" , m_HwdID, m_szDevID);
194
194
if (result.size () > 0 )
@@ -199,7 +199,7 @@ void CPanasonicNode::UpdateStatus()
199
199
200
200
// 4: Trigger Notifications & events on status change
201
201
202
- if (m_CurrentStatus.Status () != m_PreviousStatus.Status ())
202
+ if (m_CurrentStatus.Status () != m_PreviousStatus.Status () || forceupdate )
203
203
{
204
204
m_notifications.CheckAndHandleNotification (m_ID, m_Name, m_CurrentStatus.NotificationType (), sLogText );
205
205
m_mainworker.m_eventsystem .ProcessDevice (m_HwdID, m_ID, 1 , int (pTypeLighting2), int (sTypeAC ), 12 , 100 , int (m_CurrentStatus.Status ()), m_CurrentStatus.StatusMessage ().c_str (), m_Name.c_str (), 0 );
@@ -215,11 +215,10 @@ bool CPanasonicNode::handleConnect(boost::asio::ip::tcp::socket& socket, boost::
215
215
if (!m_stoprequested)
216
216
{
217
217
socket.connect (endpoint, ec);
218
-
219
218
if (!ec)
220
219
{
221
220
if (DEBUG_LOGGING) _log.Log (LOG_NORM, " Panasonic Plugin: (%s) Connected to '%s:%s'." , m_Name.c_str (), m_IP.c_str (), (m_Port[0 ] != ' -' ? m_Port.c_str () : m_Port.substr (1 ).c_str ()));
222
- if (m_CurrentStatus.Status () == MSTAT_OFF )
221
+ if (m_CurrentStatus.Status () != MSTAT_ON )
223
222
{
224
223
m_CurrentStatus.Clear ();
225
224
m_CurrentStatus.Status (MSTAT_ON);
@@ -250,6 +249,7 @@ bool CPanasonicNode::handleConnect(boost::asio::ip::tcp::socket& socket, boost::
250
249
251
250
}
252
251
252
+
253
253
std::string CPanasonicNode::handleWriteAndRead (std::string pMessageToSend)
254
254
{
255
255
@@ -451,9 +451,16 @@ void CPanasonicNode::Do_Work()
451
451
452
452
void CPanasonicNode::SendCommand (const std::string command)
453
453
{
454
- std::string sPanasonicCall ;
455
- std::string sPanasonicParam = " " ;
454
+ std::string sPanasonicCall = " " ;
456
455
456
+ if (m_CurrentStatus.Status () == MSTAT_OFF)
457
+ {
458
+ // no point trying to send a command if we know the device is off
459
+ // no network on Panasonic TV's when it's in the off state
460
+ _log.Log (LOG_ERROR, " Panasonic Plugin: (%s) Device is Off, cannot send command." , m_Name.c_str ());
461
+ return ;
462
+ }
463
+
457
464
if (command == " Home" )
458
465
sPanasonicCall = buildXMLStringNetCtl (" CANCEL-ONOFF" );
459
466
else if (command == " Up" )
@@ -490,7 +497,7 @@ void CPanasonicNode::SendCommand(const std::string command)
490
497
sPanasonicCall = buildXMLStringNetCtl (" MENU-ONOFF" );
491
498
else if (command == " Channels" || command == " guide" )
492
499
sPanasonicCall = buildXMLStringNetCtl (" EPG-ONOFF" );
493
- else if (command == " Back" || command == " return " )
500
+ else if (command == " Back" || command == " Return " )
494
501
sPanasonicCall = buildXMLStringNetCtl (" RETURN-ONOFF" );
495
502
else if (command == " Select" )
496
503
sPanasonicCall = buildXMLStringNetCtl (" ENTER-ONOFF" );
@@ -534,10 +541,18 @@ void CPanasonicNode::SendCommand(const std::string command)
534
541
sPanasonicCall = buildXMLStringNetCtl (" STOP-ONOFF" );
535
542
else if (command == " pause" )
536
543
sPanasonicCall = buildXMLStringNetCtl (" PAUSE-ONOFF" );
537
- else if (command == " Power" || command == " power" || command == " off" )
544
+ else if (command == " Power" || command == " power" || command == " off" || command == " Off " )
538
545
sPanasonicCall = buildXMLStringNetCtl (" POWER-ONOFF" );
539
546
else if (command == " ShowSubtitles" )
540
547
sPanasonicCall = buildXMLStringNetCtl (" STTL-ONOFF" );
548
+ else if (command == " On" || command == " on" )
549
+ {
550
+ _log.Log (LOG_NORM, " Panasonic Plugin: (%s) Can't use command: '%s'." , m_Name.c_str (), command.c_str ());
551
+ // Workaround to get the plugin to reset device status, otherwise the UI goes out of sync with plugin
552
+ m_CurrentStatus.Clear ();
553
+ m_CurrentStatus.Status (MSTAT_UNKNOWN);
554
+ UpdateStatus (true );
555
+ }
541
556
else
542
557
_log.Log (LOG_NORM, " Panasonic Plugin: (%s) Unknown command: '%s'." , m_Name.c_str (), command.c_str ());
543
558
@@ -721,6 +736,9 @@ bool CPanasonic::WriteToHardware(const char *pdata, const unsigned char length)
721
736
int iParam = pSen->LIGHTING2 .level ;
722
737
switch (pSen->LIGHTING2 .cmnd )
723
738
{
739
+ case light2_sOn:
740
+ (*itt)->SendCommand (" On" );
741
+ return true ;
724
742
case light2_sOff:
725
743
(*itt)->SendCommand (" Off" );
726
744
return true ;
0 commit comments