Skip to content

Commit

Permalink
services:
Browse files Browse the repository at this point in the history
power_on
standby
active_source
  • Loading branch information
konikvranik committed Dec 20, 2016
1 parent 33b540d commit 8f45282
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pycec/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
CMD_TUNER_STATUS = (0x07, 0x08)
CMD_MENU_STATUS = (0x8d, 0x8e)

CMD_ACTIVE_SOURCE=0x82
CMD_STREAM_PATH=0x86
CMD_KEY_PRESS = 0x44
CMD_KEY_RELEASE = 0x45

Expand Down
46 changes: 43 additions & 3 deletions pycec/network.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import asyncio
from concurrent.futures.thread import ThreadPoolExecutor
from multiprocessing import Queue

from functools import reduce
from multiprocessing import Queue

from pycec import _LOGGER, CecConfig
from pycec.commands import CecCommand
from pycec.const import CMD_OSD_NAME, VENDORS, DEVICE_TYPE_NAMES
from pycec.const import CMD_OSD_NAME, VENDORS, DEVICE_TYPE_NAMES, \
CMD_ACTIVE_SOURCE, CMD_STREAM_PATH, ADDR_BROADCAST
from pycec.const import CMD_PHYSICAL_ADDRESS, CMD_POWER_STATUS, CMD_VENDOR
from pycec.datastruct import PhysicalAddress

Expand Down Expand Up @@ -153,6 +153,10 @@ def async_send_command(self, command):
_LOGGER.debug("Device sending command %s", command)
yield from self._network.async_send_command(command)

def active_source(self):
self._loop.create_task(
self._network.async_active_source(self.physical_address))

@property
def is_updated(self, cmd):
return self._updates[cmd]
Expand Down Expand Up @@ -289,6 +293,42 @@ def io_send_command(self, command: CecCommand):
self._io_executor, self._adapter.Transmit,
self._adapter.CommandFromString(command.raw))

def standby(self):
self._loop.create_task(self.async_standby())

@asyncio.coroutine
def async_standby(self):
_LOGGER.debug("Queuing system standby")
self._loop.call_soon_threadsafe(self.io_standby)

def io_standby(self):
_LOGGER.debug("System standby")
self._loop.run_in_executor(self._io_executor,
self._adapter.StandbyDevices)

def power_on(self):
self._loop.create_task(self.async_power_on())

@asyncio.coroutine
def async_power_on(self):
_LOGGER.debug("Queuing power on")
self._loop.call_soon_threadsafe(self.io_power_on)

def io_power_on(self):
_LOGGER.debug("power on")
self._loop.run_in_executor(self._io_executor,
self._adapter.PowerOnDevices)

def active_source(self, source: PhysicalAddress):
self._loop.create_task(self.async_active_source(source))

@asyncio.coroutine
def async_active_source(self, addr: PhysicalAddress):
yield from self.async_send_command(
CecCommand(CMD_ACTIVE_SOURCE, ADDR_BROADCAST, att=addr.aslist))
yield from self.async_send_command(
CecCommand(CMD_STREAM_PATH, ADDR_BROADCAST, att=addr.aslist))

@property
def devices(self) -> tuple:
return tuple(self._devices.values())
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def read(fname):

setup(
name="pyCEC",
version="0.2.2",
version="0.3.0",
author="Petr Vraník",
author_email="hpa@suteren.net",
description=(
Expand Down

0 comments on commit 8f45282

Please sign in to comment.