Skip to content

Commit d3b8fea

Browse files
committed
Fix for "Off" command
1 parent 4ab7980 commit d3b8fea

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

hardware/PanasonicTV.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ CPanasonicNode::~CPanasonicNode(void)
164164
if (DEBUG_LOGGING) _log.Log(LOG_STATUS, "Panasonic Plugin: (%s) Destroyed.", m_Name.c_str());
165165
}
166166

167-
void CPanasonicNode::UpdateStatus()
167+
void CPanasonicNode::UpdateStatus(bool forceupdate)
168168
{
169169
std::vector<std::vector<std::string> > result;
170170
m_CurrentStatus.LastOK(mytime(NULL));
171171

172172
// 1: Update the DeviceStatus
173173

174-
if (m_CurrentStatus.UpdateRequired(m_PreviousStatus))
174+
if (m_CurrentStatus.UpdateRequired(m_PreviousStatus) || forceupdate)
175175
{
176176
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)",
177177
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()
180180
// 2: Log the event if the actual status has changed
181181
std::string sLogText = m_CurrentStatus.StatusText();
182182

183-
if (m_CurrentStatus.LogRequired(m_PreviousStatus))
183+
if (m_CurrentStatus.LogRequired(m_PreviousStatus) || forceupdate)
184184
{
185185
if (m_CurrentStatus.IsOn()) sLogText += " - " + m_CurrentStatus.LogMessage();
186186
result = m_sql.safe_query("INSERT INTO LightingLog (DeviceRowID, nValue, sValue) VALUES (%d, %d, '%q')", m_ID, int(m_CurrentStatus.Status()), sLogText.c_str());
187187
_log.Log(LOG_NORM, "Panasonic: (%s) Event: '%s'.", m_Name.c_str(), sLogText.c_str());
188188
}
189189

190190
// 3: Trigger On/Off actions
191-
if (m_CurrentStatus.OnOffRequired(m_PreviousStatus))
191+
if (m_CurrentStatus.OnOffRequired(m_PreviousStatus) || forceupdate)
192192
{
193193
result = m_sql.safe_query("SELECT StrParam1,StrParam2 FROM DeviceStatus WHERE (HardwareID==%d) AND (ID = '%q') AND (Unit == 1)", m_HwdID, m_szDevID);
194194
if (result.size() > 0)
@@ -199,7 +199,7 @@ void CPanasonicNode::UpdateStatus()
199199

200200
// 4: Trigger Notifications & events on status change
201201

202-
if (m_CurrentStatus.Status() != m_PreviousStatus.Status())
202+
if (m_CurrentStatus.Status() != m_PreviousStatus.Status() || forceupdate)
203203
{
204204
m_notifications.CheckAndHandleNotification(m_ID, m_Name, m_CurrentStatus.NotificationType(), sLogText);
205205
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::
215215
if (!m_stoprequested)
216216
{
217217
socket.connect(endpoint, ec);
218-
219218
if (!ec)
220219
{
221220
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)
223222
{
224223
m_CurrentStatus.Clear();
225224
m_CurrentStatus.Status(MSTAT_ON);
@@ -250,6 +249,7 @@ bool CPanasonicNode::handleConnect(boost::asio::ip::tcp::socket& socket, boost::
250249

251250
}
252251

252+
253253
std::string CPanasonicNode::handleWriteAndRead(std::string pMessageToSend)
254254
{
255255

@@ -451,9 +451,16 @@ void CPanasonicNode::Do_Work()
451451

452452
void CPanasonicNode::SendCommand(const std::string command)
453453
{
454-
std::string sPanasonicCall;
455-
std::string sPanasonicParam = "";
454+
std::string sPanasonicCall = "";
456455

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+
457464
if (command == "Home")
458465
sPanasonicCall = buildXMLStringNetCtl("CANCEL-ONOFF");
459466
else if (command == "Up")
@@ -490,7 +497,7 @@ void CPanasonicNode::SendCommand(const std::string command)
490497
sPanasonicCall = buildXMLStringNetCtl("MENU-ONOFF");
491498
else if (command == "Channels" || command == "guide")
492499
sPanasonicCall = buildXMLStringNetCtl("EPG-ONOFF");
493-
else if (command == "Back" || command == "return")
500+
else if (command == "Back" || command == "Return")
494501
sPanasonicCall = buildXMLStringNetCtl("RETURN-ONOFF");
495502
else if (command == "Select")
496503
sPanasonicCall = buildXMLStringNetCtl("ENTER-ONOFF");
@@ -534,10 +541,18 @@ void CPanasonicNode::SendCommand(const std::string command)
534541
sPanasonicCall = buildXMLStringNetCtl("STOP-ONOFF");
535542
else if (command == "pause")
536543
sPanasonicCall = buildXMLStringNetCtl("PAUSE-ONOFF");
537-
else if (command == "Power" || command == "power" || command == "off")
544+
else if (command == "Power" || command == "power" || command == "off" || command == "Off")
538545
sPanasonicCall = buildXMLStringNetCtl("POWER-ONOFF");
539546
else if (command == "ShowSubtitles")
540547
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+
}
541556
else
542557
_log.Log(LOG_NORM, "Panasonic Plugin: (%s) Unknown command: '%s'.", m_Name.c_str(), command.c_str());
543558

@@ -721,6 +736,9 @@ bool CPanasonic::WriteToHardware(const char *pdata, const unsigned char length)
721736
int iParam = pSen->LIGHTING2.level;
722737
switch (pSen->LIGHTING2.cmnd)
723738
{
739+
case light2_sOn:
740+
(*itt)->SendCommand("On");
741+
return true;
724742
case light2_sOff:
725743
(*itt)->SendCommand("Off");
726744
return true;

hardware/PanasonicTV.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CPanasonicNode //: public boost::enable_shared_from_this<CPanasonicNode>
5151
bool SendShutdown();
5252
void StopRequest() { m_stoprequested = true; };
5353
bool IsBusy() { return m_Busy; };
54-
bool IsOn() { return (m_CurrentStatus.Status() != MSTAT_OFF); };
54+
bool IsOn() { return (m_CurrentStatus.Status() == MSTAT_ON); };
5555

5656
int m_ID;
5757
int m_DevID;
@@ -69,15 +69,16 @@ class CPanasonicNode //: public boost::enable_shared_from_this<CPanasonicNode>
6969
std::string buildXMLStringRendCtl(std::string, std::string);
7070
std::string buildXMLStringRendCtl(std::string, std::string, std::string);
7171
std::string buildXMLStringNetCtl(std::string);
72-
72+
7373
int m_HwdID;
7474
char m_szDevID[40];
7575
std::string m_IP;
7676
std::string m_Port;
7777

7878
CPanasonicStatus m_PreviousStatus;
7979
CPanasonicStatus m_CurrentStatus;
80-
void UpdateStatus();
80+
//void UpdateStatus();
81+
void UpdateStatus(bool force = false);
8182

8283
std::string m_ExecuteCommand;
8384

0 commit comments

Comments
 (0)