Skip to content

Commit

Permalink
yamahayxc: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Morg42 committed Oct 14, 2024
1 parent 6909b96 commit db181cf
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions yamahayxc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
# - parse zone().range_step -> read range/step for vol / eq


import logging
import requests
import socket
import json
Expand All @@ -53,20 +52,20 @@ class YamahaYXC(SmartPlugin):
"""
This is the main plugin class YamahaYXC to control YXC-compatible devices.
"""
PLUGIN_VERSION = "1.0.6"
PLUGIN_VERSION = "1.0.7"
ALLOW_MULTIINSTANCE = False

#
# public functions
#

def __init__(self, smarthome):
def __init__(self, **kwargs):
"""
Default init function
"""
self.logger = logging.getLogger(__name__)
super().__init__(**kwargs)

self.logger.info("Init YamahaYXC")
self._sh = smarthome

# valid commands for use in item configuration 'yamahayxc_cmd = ...'
self._yamaha_cmds = ['state', 'power', 'input', 'playback', 'preset',
Expand All @@ -79,7 +78,7 @@ def __init__(self, smarthome):
self._yamaha_ignore_cmds_upd = ['state', 'preset', 'alarm_on', 'alarm_time', 'alarm_beep']

# store items in 2D-array:
# _yamaha_dev [host] [cmd] = item
# _yamaha_dev [host] [cmd] = item
# also see parse_item()...
self._yamaha_dev = {}
# store host addresses of devices
Expand All @@ -106,13 +105,13 @@ def run(self):
data, addr = self.sock.recvfrom(self.srv_buffer)
try:
host, port = addr
except:
except Exception as e:
self.logger.warn(
"Error receiving data - host/port not readable")
f"Error receiving data - host/port not readable: {e}")
return
if host not in list(self._yamaha_dev.keys()):
self.logger.debug(
"Received notify from unknown host {}".format(host))
f"Received notify from unknown host {host}")
else:
# connected device sends updates every second for
# about 10 minutes without further interaction
Expand All @@ -128,11 +127,11 @@ def run(self):
data_flat = {}
try:
data_flat.update(data['main'])
except:
except Exception:
pass
try:
data_flat.update(data['netusb'])
except:
except Exception:
pass

# try all known command words...
Expand All @@ -145,7 +144,7 @@ def run(self):
notify_val = self._convert_value_yxc_to_plugin(data_flat[cmd], cmd, host)
item = self._yamaha_dev[host][cmd]
item(notify_val, "YamahaYXC")
except:
except Exception:
pass

# device told us new info is available?
Expand All @@ -171,7 +170,7 @@ def stop(self):
self.alive = False
try:
self.sock.shutdown(socket.SHUT_RDWR)
except:
except Exception:
pass

def parse_item(self, item):
Expand Down Expand Up @@ -352,7 +351,7 @@ def _update_alarm_state(self, yamaha_host, update_items=True):
alarm = state["alarm"]
except KeyError:
return

alarm_on = alarm["alarm_on"]
alarm_time = alarm["oneday"]["time"]
alarm_beep = alarm["oneday"]["beep"]
Expand Down

0 comments on commit db181cf

Please sign in to comment.