Skip to content

Commit

Permalink
Sonos Plugin:
Browse files Browse the repository at this point in the history
- make plugin restartable
  • Loading branch information
sisamiwe committed Nov 25, 2024
1 parent 797cf66 commit d15e758
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions sonos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3014,7 +3014,7 @@ def __init__(self, sh):
speaker_ips = self.get_parameter_value("speaker_ips")
self._pause_item_path = self.get_parameter_value('pause_item')
except KeyError as e:
self.logger.critical(f"Plugin '{self.get_shortname()}': Inconsistent plugin (invalid metadata definition: {e} not defined)")
self.logger.critical(f"Plugin '{self.get_fullname()}': Inconsistent plugin (invalid metadata definition: {e} not defined)")
self._init_complete = False
return

Expand Down Expand Up @@ -3113,7 +3113,7 @@ def parse_item(self, item: Items) -> object:

if self.has_iattr(item.conf, 'sonos_recv'):
# create Speaker instance if not exists
_initialize_speaker(uid, self.logger, self.get_shortname())
_initialize_speaker(uid, self.logger, self.get_fullname())

# to make code smaller, map sonos_cmd value to the Speaker property by name
item_attribute = self.get_iattr_value(item.conf, 'sonos_recv')
Expand Down Expand Up @@ -3241,15 +3241,15 @@ def play_alert_all_speakers(self, alert_uri, speaker_list=[], alert_volume=20, a
def _handle_dpt3(self, item, caller=None, source=None, dest=None):
"""Handle relative volumen change via a received relative dim command (dpt3) by making use of internal fadeing"""

if caller != self.get_shortname():
if caller != self.get_fullname():
item_config = self.get_item_config(item)
volume_item = item_config['volume_item']
volume_helper_item = item_config['helper']
vol_step = item_config['dpt3_step']
vol_time = item_config['dpt3_time']
vol_max = max(0, self._resolve_max_volume_command(item)) or 100
_current_volume = max(0, min(100, int(volume_item())))
volume_helper_item(_current_volume, self.get_shortname())
volume_helper_item(_current_volume, self.get_fullname())

if item()[1] == 1:
self.logger.debug(f"Starte relative Lautstärkeänderung.")
Expand All @@ -3263,7 +3263,7 @@ def _handle_dpt3(self, item, caller=None, source=None, dest=None):
volume_helper_item.fade(0 - vol_step, vol_step, vol_time)
else:
self.logger.debug(f"Stoppe relative Lautstärkeänderung.")
volume_helper_item(int(volume_helper_item()), self.get_shortname())
volume_helper_item(int(volume_helper_item()), self.get_fullname())

def _check_webservice_ip(self, webservice_ip: str) -> bool:
if not webservice_ip == '' and not webservice_ip == '0.0.0.0':
Expand Down Expand Up @@ -3291,7 +3291,7 @@ def _check_webservice_port(self, webservice_port: int) -> bool:
else:
self.logger.error(f"Your webservice_port parameter is invalid. '{webservice_port}' is not within port range 1024-65535. TTS disabled!")
return False

return True

def _check_local_webservice_path(self, local_webservice_path: str) -> bool:
Expand Down Expand Up @@ -3467,7 +3467,7 @@ def update_item(self, item: Items, caller: object, source: object, dest: object)
"""

# check for pause item
if item is self._pause_item and caller != self.get_shortname():
if item is self._pause_item and caller != self.get_fullname():
self.logger.debug(f'pause item changed to {item()}')
if item() and self.alive:
self.stop()
Expand Down Expand Up @@ -3797,7 +3797,7 @@ def _discover(self, force: bool = False) -> None:
# sonos_speaker[uid].check_subscriptions()
else:
self.logger.warning(f"Initializing new speaker with uid={uid} and ip={zone.ip_address}")
_initialize_speaker(uid, self.logger, self.get_shortname())
_initialize_speaker(uid, self.logger, self.get_fullname())
sonos_speaker[uid].soco = zone

sonos_speaker[uid].is_initialized = True
Expand Down
6 changes: 3 additions & 3 deletions sonos/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ plugin:
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/25151-sonos-anbindung

version: 1.8.9 # Plugin version
sh_minversion: '1.5.1' # minimum shNG version to use this plugin
py_minversion: '3.8' # minimum Python version to use for this plugin
sh_minversion: '1.10.3' # minimum shNG version to use this plugin
py_minversion: '3.9' # minimum Python version to use for this plugin
multi_instance: False # plugin supports multi instance
restartable: yes
classname: Sonos # class containing the plugin
Expand Down Expand Up @@ -61,7 +61,7 @@ parameters:
If "tts" is enabled and this option is not set, the value "local_webservice_path" is used for the audio snippet path.'

webservice_ip:
type: ip
type: ipv4
description:
de: '(optional) Für TTS und die Audio-Snippet-Funktionalität wird ein simpler Webservice gestartet. \n
Die IP-Adresse wird per default automatisch ermittelt, kann hier aber manuell gesetzt werden.'
Expand Down

0 comments on commit d15e758

Please sign in to comment.