Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function is_on() always return True #44

Open
Blackbox-git opened this issue Jul 7, 2020 · 5 comments
Open

The function is_on() always return True #44

Blackbox-git opened this issue Jul 7, 2020 · 5 comments

Comments

@Blackbox-git
Copy link

Blackbox-git commented Jul 7, 2020

Hello,

i am not good in programming and C is the hardest language is see.

I used the function is_on() for my Samsung TV. This function returns always True, even the TV is on Standby.

Can anyone help? You need more information i can give you input.

Here the ouptut of the testscript in your repro. You can see if the script send the TV to Standby the state become False.

Using Adapter RPI  
Devices: {0: Device(0), 1: Device(1), 8: Device(8)}
Address: 0
Physical Address: 0.0.0.0
Vendor ID: 0000F0
OSD: TV
CEC Version: Unknown
Language: ger
ON: True                <- THE TV was in STANDBY
Powering device on
True
Sleeping to allow device to power on
True                       <- THE TV was in ON
Powering device off
True
Sleeping to allow device to power off
False                     <- THE TV was in STANDBY
Success!

Thx

@trainman419
Copy link
Owner

By default, the test script uses the broadcast address (0). Try using the TV address instead:

import time
import cec

cec.init()

tv = cec.Device(cec.CECDEVICE_TV)
print "Powering TV off"
print tv.standby()
print "Sleeping to allow device to power off"
time.sleep(30)
print tv.is_on()

@Blackbox-git
Copy link
Author

Blackbox-git commented Jul 7, 2020

thx for your answer.

I added some lines to show you the issue. The TV was for more than 5 minutes in standby before i execute this script:

import time
import cec

cec.init()

tv = cec.Device(cec.CECDEVICE_TV)
print "State:", tv.is_on()         <- In reality the TV was in standby
time.sleep(5)
print "State:", tv.is_on()         <- In reality the TV was in standby
time.sleep(5)
print "Powering TV on"       
print tv.power_on()               <- TV starting
print "Sleeping to allow device to power on"
time.sleep(30)
print "Powering TV off"
print tv.standby()                 <- TV goes to standby
print "Sleeping to allow device to power off"
time.sleep(30)
print tv.is_on()                     <-TV is in standby

This is the output. You can see, aftter i have done the init i ask the power-state of the tv and the output is True, but the tv is in standby. If i started the tv and turn it of with the method the output is right.

State: True                         <- In reality the TV was in standby
State: True                         <- In reality the TV was in standby
Powering TV on                
True                                   <- TV starting
Sleeping to allow device to power on
Powering TV off
True                                    <- TV goes to standby
Sleeping to allow device to power off
False                                   <-TV is in standby

Here you can see the output of the monitoring:

pi@raspberrypi:~ $ cec-client -m
starting a monitor-only client. use 'mon 0' to switch to normal mode
No device type given. Using 'recording device'
CEC Parser created - libCEC version 4.0.4
no serial port given. trying autodetect:
 path:     Raspberry Pi
 com port: RPI

opening a connection to the CEC adapter...
DEBUG:   [            2602]     Broadcast (F): osd name set to 'Broadcast'
DEBUG:   [            2611]     logical address changed to Free use (e)
DEBUG:   [            2615]     Open - vc_cec initialised
NOTICE:  [            2618]     connection opened
waiting for input
DEBUG:   [            2621]     processor thread started
DEBUG:   [           12815]     logical address changed to Free use (e)
WARNING: [           12848]     unhandled response received: opcode=0 initiator=e destination=0 response=0
WARNING: [           12940]     unhandled response received: opcode=8c initiator=e destination=0 response=0
TRAFFIC: [           13049]     >> 0f:87:00:00:f0
DEBUG:   [           13049]     TV (0): vendor = Samsung (0000f0)
DEBUG:   [           13049]     device TV (0) status changed to present after command device vendor id
DEBUG:   [           13049]     replacing the command handler for device 'TV' (0)
DEBUG:   [           13049]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [           13052]     logical address changed to Broadcast (f)
DEBUG:   [           13292]     logical address changed to Free use (e)
DEBUG:   [           13383]     logical address changed to Broadcast (f)
DEBUG:   [           13563]     logical address changed to Free use (e)
DEBUG:   [           13654]     logical address changed to Recorder 1 (1)
WARNING: [           13812]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [           14117]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
WARNING: [           14270]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
WARNING: [           15333]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [           15416]     >> 01:90:01
DEBUG:   [           15416]     TV (0): power status changed from 'unknown' to 'standby'
WARNING: [           15479]     unhandled response received: opcode=9f initiator=1 destination=0 response=0
WARNING: [           16541]     unhandled response received: opcode=9f initiator=1 destination=0 response=0
TRAFFIC: [           16622]     >> 01:90:01
WARNING: [           17603]     unhandled response received: opcode=91 initiator=1 destination=0 response=0
TRAFFIC: [           17731]     >> 0f:32:67:65:72
DEBUG:   [           17731]     TV (0): power status changed from 'standby' to 'on'
DEBUG:   [           17731]     TV (0): menu language set to 'ger'
DEBUG:   [           17734]     >> TV (0) -> Broadcast (F): set menu language (32)
WARNING: [           27808]     unhandled response received: opcode=4 initiator=1 destination=0 response=0
DEBUG:   [           29453]     GetPhysicalAddress - physical address = 3000
TRAFFIC: [           29964]     >> 8f:84:10:00:04
DEBUG:   [           29964]     Playback 2 (8): physical address changed from ffff to 1000
DEBUG:   [           29964]     device Playback 2 (8) status changed to present after command report physical address
DEBUG:   [           29967]     >> Playback 2 (8) -> Broadcast (F): report physical address (84)
TRAFFIC: [           30124]     >> 8f:87:00:0c:e7
DEBUG:   [           30124]     Playback 2 (8): vendor = Toshiba (000ce7)
DEBUG:   [           30125]     replacing the command handler for device 'Playback 2' (8)
DEBUG:   [           30125]     >> Playback 2 (8) -> Broadcast (F): device vendor id (87)
TRAFFIC: [           32199]     >> 0f:86:30:00
DEBUG:   [           32199]     >> TV (0) sets stream path to physical address 3000
DEBUG:   [           32200]     >> TV (0) -> Broadcast (F): set stream path (86)
WARNING: [           32289]     unhandled response received: opcode=4 initiator=1 destination=0 response=0
WARNING: [           32442]     unhandled response received: opcode=82 initiator=1 destination=f response=0
WARNING: [           32685]     unhandled response received: opcode=8e initiator=1 destination=0 response=0
TRAFFIC: [           33222]     >> 01:1a:01
WARNING: [           33313]     unhandled response received: opcode=1b initiator=1 destination=0 response=0
TRAFFIC: [           35465]     >> 01:8c
WARNING: [           35620]     unhandled response received: opcode=87 initiator=1 destination=f response=0
TRAFFIC: [           35666]     >> 01:8f
WARNING: [           35761]     unhandled response received: opcode=90 initiator=1 destination=0 response=0
TRAFFIC: [           35829]     >> 01:46
WARNING: [           36166]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
TRAFFIC: [           36296]     >> 01:a0:00:00:f0:23
WARNING: [           36511]     unhandled response received: opcode=a0 initiator=1 destination=0 response=0
TRAFFIC: [           36589]     >> 01:9f
WARNING: [           36686]     unhandled response received: opcode=9e initiator=1 destination=0 response=0
TRAFFIC: [           37104]     >> 8f:87:00:0c:e7
DEBUG:   [           37105]     >> Playback 2 (8) -> Broadcast (F): device vendor id (87)
TRAFFIC: [           37504]     >> 8f:84:10:00:04
DEBUG:   [           37508]     >> Playback 2 (8) -> Broadcast (F): report physical address (84)
TRAFFIC: [           42978]     >> 01:8f
WARNING: [           43073]     unhandled response received: opcode=90 initiator=1 destination=0 response=0
TRAFFIC: [           43129]     >> 01:83
WARNING: [           43286]     unhandled response received: opcode=84 initiator=1 destination=f response=0
TRAFFIC: [           43495]     >> 0f:86:30:00
DEBUG:   [           43495]     >> TV (0) sets stream path to physical address 3000
DEBUG:   [           43499]     >> TV (0) -> Broadcast (F): set stream path (86)
WARNING: [           43629]     unhandled response received: opcode=82 initiator=1 destination=f response=0
WARNING: [           57884]     unhandled response received: opcode=36 initiator=1 destination=0 response=0
TRAFFIC: [           58036]     >> 0f:36
DEBUG:   [           58036]     TV (0): power status changed from 'on' to 'standby'
DEBUG:   [           58039]     >> TV (0) -> Broadcast (F): standby (36)
TRAFFIC: [           58105]     >> 0f:36

@trainman419
Copy link
Owner

trainman419 commented Jul 8, 2020

It's hard for me to tell if this is a bug in python-cec or in the libCEC library that we use.

The python script you posted should be the same as sending the following commands via cec-client (the cli for libCEC):

pow 0
on 0
pow 0
standby 0
pow 0

If you see similar behavior from running those commands in cec-client, that would indicate that the issue is in libCEC.

@Blackbox-git
Copy link
Author

I used your commands with the following python script. Its extremly slow to execute the commands, because it has to connect for every command with the cec-client.

I have to execute the 'on 0' twice because the tv is only start at the secound command.

But it works. Especially the status is now every time correct. Can you use this information to narrow down the error?

import time
import os

test = os.popen("echo 'pow 0' | cec-client -s -d 1").readlines()
print test[1].strip()
time.sleep(5)
test = os.popen("echo 'pow 0' | cec-client -s -d 1").readlines()
print test[1].strip()
time.sleep(5)
print "Powering TV on"
test = os.popen("echo 'on 0' | cec-client -s -d 1").readlines()
test = os.popen("echo 'on 0' | cec-client -s -d 1").readlines()
print "Sleeping to allow device to power on"
time.sleep(30)
test = os.popen("echo 'pow 0' | cec-client -s -d 1").readlines()
print test[1].strip()
print "Powering TV off"
test = os.popen("echo 'standby 0' | cec-client -s -d 1").readlines()
print "Sleeping to allow device to power off"
time.sleep(30)
test = os.popen("echo 'pow 0' | cec-client -s -d 1").readlines()
print test[1].strip()

power status: standby                         <-TV is in standby
power status: standby                         <-TV is in standby
Powering TV on                                   <-TV is starting with execute 'on 0' twice
Sleeping to allow device to power on
power status: on                                  <-TV is on
Powering TV off                                   <- TV goes to standby
Sleeping to allow device to power off
power status: standby                        <-TV is in standby
starting a monitor-only client. use 'mon 0' to switch to normal mode
No device type given. Using 'recording device'
CEC Parser created - libCEC version 4.0.4
no serial port given. trying autodetect:
 path:     Raspberry Pi
 com port: RPI

opening a connection to the CEC adapter...
DEBUG:   [            1536]     Broadcast (F): osd name set to 'Broadcast'
DEBUG:   [            1545]     logical address changed to Free use (e)
DEBUG:   [            1553]     Open - vc_cec initialised
NOTICE:  [            1559]     connection opened
waiting for input
DEBUG:   [            1562]     processor thread started
DEBUG:   [            6412]     logical address changed to Free use (e)
WARNING: [            6446]     unhandled response received: opcode=0 initiator=e destination=0 response=0
WARNING: [            6538]     unhandled response received: opcode=8c initiator=e destination=0 response=0
TRAFFIC: [            6648]     >> 0f:87:00:00:f0
DEBUG:   [            6648]     TV (0): vendor = Samsung (0000f0)
DEBUG:   [            6648]     device TV (0) status changed to present after command device vendor id
DEBUG:   [            6648]     replacing the command handler for device 'TV' (0)
DEBUG:   [            6649]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [            6657]     logical address changed to Broadcast (f)
DEBUG:   [            6897]     logical address changed to Free use (e)
DEBUG:   [            7047]     logical address changed to Broadcast (f)
DEBUG:   [            7318]     logical address changed to Free use (e)
DEBUG:   [            7409]     logical address changed to Recorder 1 (1)
WARNING: [            7565]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [            7868]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
WARNING: [            7930]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [            8011]     >> 01:90:01
DEBUG:   [            8011]     TV (0): power status changed from 'unknown' to 'standby'
DEBUG:   [            8421]     logical address changed to Broadcast (f)
DEBUG:   [           15641]     logical address changed to Free use (e)
WARNING: [           15705]     unhandled response received: opcode=0 initiator=e destination=0 response=0
WARNING: [           15767]     unhandled response received: opcode=8c initiator=e destination=0 response=0
TRAFFIC: [           15894]     >> 0f:87:00:00:f0
DEBUG:   [           15895]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [           15903]     logical address changed to Broadcast (f)
DEBUG:   [           16143]     logical address changed to Free use (e)
DEBUG:   [           16233]     logical address changed to Broadcast (f)
DEBUG:   [           16413]     logical address changed to Free use (e)
DEBUG:   [           16504]     logical address changed to Recorder 1 (1)
WARNING: [           16664]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [           16967]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
WARNING: [           17120]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
WARNING: [           18182]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [           18263]     >> 01:90:01
DEBUG:   [           18655]     logical address changed to Broadcast (f)
DEBUG:   [           24941]     logical address changed to Free use (e)
WARNING: [           25004]     unhandled response received: opcode=0 initiator=e destination=0 response=0
WARNING: [           25216]     unhandled response received: opcode=8c initiator=e destination=0 response=0
WARNING: [           26278]     unhandled response received: opcode=8c initiator=e destination=0 response=0
TRAFFIC: [           26406]     >> 0f:87:00:00:f0
DEBUG:   [           26409]     logical address changed to Broadcast (f)
DEBUG:   [           26413]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [           26649]     logical address changed to Free use (e)
DEBUG:   [           26740]     logical address changed to Broadcast (f)
DEBUG:   [           26920]     logical address changed to Free use (e)
DEBUG:   [           27013]     logical address changed to Recorder 1 (1)
WARNING: [           27171]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [           27475]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
WARNING: [           27660]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [           27662]     >> 0f:87:00:00:f0
DEBUG:   [           27668]     >> TV (0) -> Broadcast (F): device vendor id (87)
WARNING: [           27874]     unhandled response received: opcode=87 initiator=1 destination=f response=0
WARNING: [           28732]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [           29025]     >> 01:90:01
WARNING: [           29116]     unhandled response received: opcode=4 initiator=1 destination=0 response=0
DEBUG:   [           29948]     logical address changed to Broadcast (f)
DEBUG:   [           31187]     logical address changed to Free use (e)
WARNING: [           31250]     unhandled response received: opcode=0 initiator=e destination=0 response=0
WARNING: [           31312]     unhandled response received: opcode=8c initiator=e destination=0 response=0
TRAFFIC: [           32066]     >> 0f:87:00:00:f0
DEBUG:   [           32067]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [           32070]     logical address changed to Broadcast (f)
DEBUG:   [           32308]     logical address changed to Free use (e)
DEBUG:   [           32459]     logical address changed to Broadcast (f)
DEBUG:   [           32729]     logical address changed to Free use (e)
DEBUG:   [           32942]     logical address changed to Recorder 1 (1)
DEBUG:   [           32997]     GetPhysicalAddress - physical address = 3000
WARNING: [           33130]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [           33342]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [           33705]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
WARNING: [           33828]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [           33958]     >> 8f:84:10:00:04
DEBUG:   [           33959]     Playback 2 (8): physical address changed from ffff to 1000
DEBUG:   [           33959]     device Playback 2 (8) status changed to present after command report physical address
DEBUG:   [           33962]     >> Playback 2 (8) -> Broadcast (F): report physical address (84)
TRAFFIC: [           34048]     >> 01:90:00
DEBUG:   [           34048]     TV (0): power status changed from 'standby' to 'on'
WARNING: [           34112]     unhandled response received: opcode=4 initiator=1 destination=0 response=0
DEBUG:   [           34193]     logical address changed to Broadcast (f)
DEBUG:   [           65487]     logical address changed to Free use (e)
WARNING: [           65551]     unhandled response received: opcode=0 initiator=e destination=0 response=0
WARNING: [           65613]     unhandled response received: opcode=8c initiator=e destination=0 response=0
TRAFFIC: [           65741]     >> 0f:87:00:00:f0
DEBUG:   [           65741]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [           65743]     logical address changed to Broadcast (f)
DEBUG:   [           65923]     logical address changed to Free use (e)
DEBUG:   [           66014]     logical address changed to Broadcast (f)
DEBUG:   [           66194]     logical address changed to Free use (e)
DEBUG:   [           66287]     logical address changed to Recorder 1 (1)
WARNING: [           66442]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [           66746]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
WARNING: [           66870]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [           66872]     >> 01:8c
WARNING: [           67087]     unhandled response received: opcode=87 initiator=1 destination=f response=0
TRAFFIC: [           67088]     >> 01:90:00
TRAFFIC: [           67149]     >> 01:8f
TRAFFIC: [           67316]     >> 01:83
DEBUG:   [           67494]     logical address changed to Broadcast (f)
DEBUG:   [           68734]     logical address changed to Free use (e)
WARNING: [           68798]     unhandled response received: opcode=0 initiator=e destination=0 response=0
WARNING: [           68861]     unhandled response received: opcode=8c initiator=e destination=0 response=0
TRAFFIC: [           68988]     >> 0f:87:00:00:f0
DEBUG:   [           68988]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [           68991]     logical address changed to Broadcast (f)
DEBUG:   [           69171]     logical address changed to Free use (e)
DEBUG:   [           69261]     logical address changed to Broadcast (f)
DEBUG:   [           69441]     logical address changed to Free use (e)
DEBUG:   [           69533]     logical address changed to Recorder 1 (1)
WARNING: [           69687]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [           70110]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
TRAFFIC: [           70114]     >> 01:a0:00:00:f0:23
WARNING: [           70324]     unhandled response received: opcode=a0 initiator=1 destination=0 response=0
WARNING: [           70418]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [           70492]     >> 01:90:00
WARNING: [           70559]     unhandled response received: opcode=36 initiator=1 destination=0 response=0
TRAFFIC: [           70620]     >> 01:9f
DEBUG:   [           70742]     logical address changed to Broadcast (f)
DEBUG:   [           88902]     GetPhysicalAddress - physical address = 3000
DEBUG:   [          102006]     logical address changed to Free use (e)
WARNING: [          102068]     unhandled response received: opcode=0 initiator=e destination=0 response=0
WARNING: [          102131]     unhandled response received: opcode=8c initiator=e destination=0 response=0
TRAFFIC: [          102258]     >> 0f:87:00:00:f0
DEBUG:   [          102258]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [          102261]     logical address changed to Broadcast (f)
DEBUG:   [          102501]     logical address changed to Free use (e)
DEBUG:   [          102591]     logical address changed to Broadcast (f)
DEBUG:   [          102771]     logical address changed to Free use (e)
DEBUG:   [          102864]     logical address changed to Recorder 1 (1)
WARNING: [          103019]     unhandled response received: opcode=84 initiator=1 destination=f response=0
WARNING: [          103323]     unhandled response received: opcode=47 initiator=1 destination=0 response=0
WARNING: [          103476]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
WARNING: [          104539]     unhandled response received: opcode=8f initiator=1 destination=0 response=0
TRAFFIC: [          104621]     >> 01:90:01
DEBUG:   [          104621]     TV (0): power status changed from 'on' to 'standby'
DEBUG:   [          105012]     logical address changed to Broadcast (f)

@SchiSchi2
Copy link

The is_on() output on my side is also not reliable. cec-client says standby, is_on() says True.
I am using an Samsung TV and PulseEight adaptor for a Lenovo ThinkCentre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants