Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Commit

Permalink
cleanup, add event, raw command
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzorben committed Feb 27, 2017
1 parent de8e42f commit 6ebf7e8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions onkyo_serial/onkyo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import threading
import re
import time
from .log import logging
from .event import Event
from . log import logging
from . event import Event
from serial import Serial
from yaml import load, dump

Expand Down Expand Up @@ -121,13 +121,19 @@ def run(self):
break

if zone and prop:
val = self.process(prop, val)
logger.debug('zone: %s, property: %s, value: %s', zone, prop, val)
self.state_changed(zone, prop, val)
if prop in self.messages:
val = self.process(prop, val)
logger.debug('zone: %s, property: %s, value: %s', zone, prop, val)
self.state_changed(zone, prop, val)
else:
logger.debug('Received unknown response: %s', match.group())
else:
logger.debug('Received unknown response: %s', out)

class OnkyoSerial():
_serial = None
_worker_thread = None
on_state_change = Event()

@property
def _port(self):
Expand Down Expand Up @@ -178,8 +184,9 @@ def update(self):
def state_change(self, zone, prop, value):
"""Handle a state change from the worker thread."""
if zone == self._zone:
logger.info("state change [{z}] {k}={v}".format(z=zone, k=prop, v=value))
logger.debug("state change [{z}] {k}={v}".format(z=zone, k=prop, v=value))
self.__dict__['_' + prop] = value
self.on_state_change(prop, value)

def power_on(self):
"""Send power on command."""
Expand All @@ -206,6 +213,9 @@ def volume(self, level):
if 'volume' in self._commands:
self.command(self._commands['volume'] + format(level, '02X'))

def raw(self, command):
self.command(command)

def source(self, input):
"""Send set input source command."""
if 'source' in self._commands:
Expand Down

0 comments on commit 6ebf7e8

Please sign in to comment.