Skip to content

Commit

Permalink
Merge pull request #955 from onkelandy/lms
Browse files Browse the repository at this point in the history
Lms plugin: update to use new SDP version features
  • Loading branch information
onkelandy authored Aug 17, 2024
2 parents 513ef9d + 86841c4 commit 1f295c5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 29 deletions.
8 changes: 6 additions & 2 deletions lms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ class SmartPluginWebIf():
else:
builtins.SDP_standalone = False

from lib.model.sdp.globals import (CUSTOM_SEP, PLUGIN_ATTR_NET_HOST, PLUGIN_ATTR_RECURSIVE, PLUGIN_ATTR_CONN_TERMINATOR)
from lib.model.sdp.globals import (CUSTOM_SEP, PLUGIN_ATTR_NET_HOST, PLUGIN_ATTR_RECURSIVE, PLUGIN_ATTR_CMD_CLASS, PLUGIN_ATTR_CONNECTION, PLUGIN_ATTR_CONN_TERMINATOR)
from lib.model.smartdeviceplugin import SmartDevicePlugin, Standalone
from lib.model.sdp.command import SDPCommandParseStr

import urllib.parse


class lms(SmartDevicePlugin):
""" Device class for Logitech Mediaserver/Squeezebox function. """

PLUGIN_VERSION = '1.5.2'
PLUGIN_VERSION = '1.5.3'

def _set_device_defaults(self):
self.custom_commands = 1
Expand All @@ -58,6 +59,9 @@ def _set_device_defaults(self):
self._custom_patterns = {1: '(?:[0-9a-fA-F]{2}[-:]){5}[0-9a-fA-F]{2}', 2: '', 3: ''}
self._use_callbacks = True
self._parameters[PLUGIN_ATTR_RECURSIVE] = 1
self._parameters[PLUGIN_ATTR_CMD_CLASS] = SDPCommandParseStr
self._parameters[PLUGIN_ATTR_CONNECTION] = 'net_tcp_client'

self._parameters['web_port'] = self.get_parameter_value('web_port')
if self.get_parameter_value('web_host') == '':
host = self._parameters.get(PLUGIN_ATTR_NET_HOST)
Expand Down
8 changes: 4 additions & 4 deletions lms/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

commands = {
'server': {
'listenmode': {'read': True, 'write': True, 'write_cmd': 'listen {RAW_VALUE:01}', 'item_type': 'bool', 'dev_datatype': 'str', 'reply_pattern': r'listen (\d)', 'item_attrs': {'custom1': ''}},
'listenmode': {'read': True, 'write': True, 'write_cmd': 'listen {RAW_VALUE:01}', 'item_type': 'bool', 'dev_datatype': 'LMSonoff', 'reply_pattern': r'listen (\d)', 'item_attrs': {'custom1': ''}},
'playercount': {'read': True, 'write': False, 'read_cmd': 'player count ?', 'item_type': 'num', 'dev_datatype': 'str', 'reply_pattern': r'player count (\d+)', 'item_attrs': {'initial': True, 'custom1': ''}},
'favoritescount': {'read': True, 'write': False, 'read_cmd': 'favorites items', 'item_type': 'num', 'dev_datatype': 'str', 'reply_pattern': r'favorites items\s+ count:(\d+)', 'item_attrs': {'initial': True, 'custom1': ''}},
},
Expand All @@ -28,11 +28,11 @@
},
'player': {
'control': {
'power': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} power ?', 'item_type': 'bool', 'write_cmd': '{CUSTOM_ATTR1} power {RAW_VALUE:01}', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} (?:prefset server\s)?power (\d)', '{CUSTOM_PATTERN1} status(?:.*)power:([^\s]+)'], 'item_attrs': {'enforce': True}},
'power': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} power ?', 'item_type': 'bool', 'write_cmd': '{CUSTOM_ATTR1} power {RAW_VALUE:01}', 'dev_datatype': 'LMSonoff', 'reply_pattern': [r'{CUSTOM_PATTERN1} (?:prefset server\s)?power (\d)', '{CUSTOM_PATTERN1} status(?:.*)power:([^\s]+)'], 'item_attrs': {'enforce': True}},
'playmode': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} mode ?', 'item_type': 'str', 'write_cmd': '{CUSTOM_ATTR1} mode {VALUE}', 'dev_datatype': 'LMSPlayMode', 'cmd_settings': {'valid_list_ci': ['PLAY', 'PAUSE', 'STOP']}, 'reply_pattern': [r'{CUSTOM_PATTERN1} mode {VALID_LIST_CI}', r'{CUSTOM_PATTERN1} playlist (pause \d|stop)', '{CUSTOM_PATTERN1} status(?:.*)mode:([^\s]+)'], 'item_attrs': {'enforce': True}},
'playpause': {'read': True, 'write': True, 'item_type': 'bool', 'write_cmd': '{CUSTOM_ATTR1} {VALUE}', 'dev_datatype': 'LMSPlay', 'reply_pattern': [r'{CUSTOM_PATTERN1} (?:playlist\s)?(play|pause)(?:\s3)?$', '{CUSTOM_PATTERN1} pause (0|1)'], 'item_attrs': {'enforce': True}},
'stop': {'read': True, 'write': True, 'item_type': 'bool', 'write_cmd': '{CUSTOM_ATTR1} {VALUE}', 'dev_datatype': 'LMSStop', 'reply_pattern': r'{CUSTOM_PATTERN1} (?:playlist\s)?(stop)$', 'item_attrs': {'enforce': True}},
'mute': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} mixer muting ?', 'item_type': 'bool', 'write_cmd': '{CUSTOM_ATTR1} mixer muting {RAW_VALUE:01}', 'dev_datatype': 'str', 'reply_pattern': r'{CUSTOM_PATTERN1} (?:mixer muting|prefset server mute) (\d)', 'item_attrs': {'initial': True, 'enforce': True}},
'mute': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} mixer muting ?', 'item_type': 'bool', 'write_cmd': '{CUSTOM_ATTR1} mixer muting {RAW_VALUE:01}', 'dev_datatype': 'LMSonoff', 'reply_pattern': r'{CUSTOM_PATTERN1} (?:mixer muting|prefset server mute) (\d)', 'item_attrs': {'initial': True, 'enforce': True}},
'volume': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} mixer volume ?', 'item_type': 'num', 'write_cmd': '{CUSTOM_ATTR1} mixer volume {VALUE}', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} (?:mixer volume \-?|prefset server volume \-?)(\d{1,3})', '{CUSTOM_PATTERN1} status(?:.*)mixer volume:([^\s]+)']},
'volume_fading': {'read': False, 'write': True, 'item_type': 'num', 'write_cmd': '{CUSTOM_ATTR1} mixer volume {VALUE}', 'dev_datatype': 'str', 'item_attrs': {'item_template': 'volume_fading'}},
'volume_low': {'read': False, 'write': True, 'item_type': 'num', 'write_cmd': '{CUSTOM_ATTR1} mixer volume {VALUE}', 'dev_datatype': 'str', 'item_attrs': {'attributes': {'cache': True, 'enforce_updates': True, 'initial_value': 60}}},
Expand All @@ -42,7 +42,7 @@
'set_alarm': {'read': True, 'write': True, 'item_type': 'str', 'write_cmd': '{CUSTOM_ATTR1} alarm {VALUE}', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} alarm (.*)'},
'alarms': {'read': True, 'write': False, 'item_type': 'dict', 'read_cmd': '{CUSTOM_ATTR1} alarms 0 100 all', 'dev_datatype': 'LMSAlarms', 'reply_pattern': r'{CUSTOM_PATTERN1} alarms 0 100 all fade:\d+ count:\d+ (.*)', 'item_attrs': {'initial': True, 'read_groups': [{'name': 'player.control.alarms', 'trigger': 'query'}]}},
'sync': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} sync ?', 'write_cmd': '{CUSTOM_ATTR1} sync {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} sync (.*)', 'item_attrs': {'initial': True}},
'unsync': {'read': False, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} sync -', 'item_type': 'bool', 'dev_datatype': 'str', 'item_attrs': {'attributes': {'autotimer': '1s = 0'}}},
'unsync': {'read': False, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} sync -', 'item_type': 'bool', 'dev_datatype': 'LMSonoff', 'item_attrs': {'attributes': {'autotimer': '1s = 0'}}},
'display': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} display ? ?', 'item_type': 'str', 'write_cmd': '{CUSTOM_ATTR1} display {VALUE}', 'dev_datatype': 'str', 'reply_pattern': r'{CUSTOM_PATTERN1} display\s?(.*)', 'item_attrs': {'initial': True}},
'connect': {'read': True, 'write': True, 'item_type': 'str', 'write_cmd': '{CUSTOM_ATTR1} connect {VALUE}', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} connect (.*)', 'item_attrs': {'attributes': {'remark': 'ip|www.mysqueezebox.com|www.test.mysqueezebox.com'}}},
'disconnect': {'read': True, 'write': True, 'item_type': 'str', 'write_cmd': 'disconnect {CUSTOM_ATTR1} {VALUE}', 'dev_datatype': 'str', 'reply_pattern': 'disconnect {CUSTOM_PATTERN1} (.*)', 'item_attrs': {'attributes': {'remark': 'ip|www.mysqueezebox.com|www.test.mysqueezebox.com'}}},
Expand Down
4 changes: 4 additions & 0 deletions lms/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ def get_send_data(self, data, type=None, **kwargs):

def get_shng_data(self, data, type=None, **kwargs):
return True if data == "stop" else False

class DT_LMSonoff(DT.Datatype):
def get_shng_data(self, data, type=None, **kwargs):
return True if data == "1" else False
79 changes: 56 additions & 23 deletions lms/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ plugin:
tester: Morg
state: develop
keywords: iot device logitechmediaserver lms sdp av
version: 1.5.2
version: 1.5.3
sh_minversion: '1.9.5'
py_minversion: '3.7'
sdp_minversion: '1.0.3'
multi_instance: false
restartable: true
classname: lms
Expand Down Expand Up @@ -71,28 +72,6 @@ parameters:
de: Port für CLI Netzwerkverbindung
en: CLI network port

conn_type:
type: str
default: net_tcp_client
valid_list:
- ''
- net_tcp_client

description:
de: Verbindungstyp
en: connection type

command_class:
type: str
default: SDPCommandParseStr
valid_list:
- SDPCommand
- SDPCommandParseStr

description:
de: Klasse für Verarbeitung von Kommandos
en: class for command processing

autoreconnect:
type: bool
default: true
Expand Down Expand Up @@ -149,6 +128,60 @@ parameters:
de: Item-Pfad für das Standby-Item
en: item path for standby switch item

send_retries:
type: num
default: 0

description:
de: Anzahl Sendeversuche
en: number of sending retries
description_long:
de: 'Anzahl Sendeversuche\n
Kommt keine (passende) Antwort nach dem Senden
eines Commands zurück, wird das Kommando nochmals
gesendet, sofern der Wert über 0 liegt.
'
en: 'number of sending retries\n
If no (suiting) answer is received after sending
a command the command is resent as long as this
value is more than 0.
'

sendretry_cycle:
type: num
valid_min: 1
default: 1

description:
de: Pause zwischen Durchgängen von Sendeversuchen
en: wait time between sending retry rounds
description_long:
de: 'Pause zwischen Durchgängen von Sendeversuchen\n
Sind Send Retries aktiv, wird ein Scheduler erstellt,
der im angegebenen Sekundentakt Kommandos erneut sendet,
zu denen keine (passenden) Antworten erhalten wurden.
'
en: 'wait time between sending retry rounds\n
If send retries are active, a scheduler gets added
that resends commands in the given cycle value (in seconds)
where no (suiting) answer got received.
'

delay_initial_read:
type: num
default: 0

description:
de: Warte nach Verbindungsaufbau mit dem Abfragen von Werten
en: Wait after connection with querying values

resume_initial_read:
type: bool
defaul: false
description:
de: 'Bei resume vom Plugin erstmaliges Lesen erneut durchführen'
en: 'Repeat initial read on resume'

item_attributes:

sqb_command:
Expand Down

0 comments on commit 1f295c5

Please sign in to comment.