Skip to content

Commit

Permalink
add is_on property and fix power off for older webos versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bendavid committed Jan 24, 2020
1 parent e0bae83 commit 55b689c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions aiopylgtv/webos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ async def connect_handler(self, res):
task.result()
except PyLGTVCmdException:
pass
# set placeholder power state if not available
if not self._power_state:
self._power_state = {"state": "Unknown"}
self.doStateUpdate = True
if self.state_update_callbacks:
await self.do_state_update_callbacks()
Expand Down Expand Up @@ -421,6 +424,20 @@ def software_info(self):
def sound_output(self):
return self._sound_output

@property
def is_on(self):
state = self._power_state.get("state")
if state == "Unknown":
# fallback to current app id for some older webos versions which don't support explicit power state
if self._current_appId in [None, ""]:
return False
else:
return True
elif state in [None, "Power Off", "Suspend", "Active Standby"]:
return False
else:
return True

def calibration_support_info(self):
info = {
"lut1d": False,
Expand Down Expand Up @@ -763,12 +780,7 @@ async def power_off(self):
"""Power off TV."""

# protect against turning tv back on if it is off
if self._power_state.get("state") in [
None,
"Power Off",
"Suspend",
"Active Standby",
]:
if not self.is_on:
return

# if tv is shutting down and standby+ option is not enabled,
Expand Down

0 comments on commit 55b689c

Please sign in to comment.