| 1 |
"""async_upnp_client profile for OpenHome Media players. |
| 2 |
|
| 3 |
This profile has many convenience methods for invoking an action from an OpenHome Media service |
| 4 |
Not all devices will offer all services and actions. If a service or action is not available |
| 5 |
then an error will be raised. |
| 6 |
""" |
| 7 |
|
| 8 |
# pylint: disable=too-many-public-methods,too-many-lines |
| 9 |
import base64 |
| 10 |
import binascii |
| 11 |
import logging |
| 12 |
import struct |
| 13 |
from enum import Enum # py310 replace str, Enum with StrEnum when Python 3.10 becomes end-of-life |
| 14 |
from typing import Any, Mapping, Sequence |
| 15 |
|
| 16 |
import defusedxml.ElementTree as DET |
| 17 |
|
| 18 |
from async_upnp_client.exceptions import UpnpError |
| 19 |
from async_upnp_client.profiles.profile import UpnpProfileDevice |
| 20 |
|
| 21 |
_LOGGER = logging.getLogger(__name__) |
| 22 |
|
| 23 |
|
| 24 |
# region Service and other enums |
| 25 |
class Service(str, Enum): |
| 26 |
"""Linn/OpenHome Network Service Identifiers. |
| 27 |
|
| 28 |
The Service Identifier from the ServiceId |
| 29 |
This assumes no collisions if domain namespace is ignored |
| 30 |
""" |
| 31 |
|
| 32 |
CREDENTIALS = "Credentials" |
| 33 |
INFO = "Info" |
| 34 |
PINS = "Pins" |
| 35 |
PLAYLIST = "Playlist" |
| 36 |
PRODUCT = "Product" |
| 37 |
RADIO = "Radio" |
| 38 |
RECEIVER = "Receiver" |
| 39 |
SENDER = "Sender" |
| 40 |
TIME = "Time" |
| 41 |
TRANSPORT = "Transport" |
| 42 |
UPDATE = "Update" |
| 43 |
VOLUME = "Volume" |
| 44 |
|
| 45 |
|
| 46 |
class ServiceId(str, Enum): |
| 47 |
"""Linn/OpenHome Network Service Ids. |
| 48 |
|
| 49 |
A service ID uniquely identifies a service instance within a device. |
| 50 |
It follows a URI format of urn:<domain-namespace>:serviceId:<ServiceIdentifier> |
| 51 |
""" |
| 52 |
|
| 53 |
# OPENHOME |
| 54 |
CREDENTIALS = "urn:av-openhome-org:serviceId:Credentials" |
| 55 |
INFO = "urn:av-openhome-org:serviceId:Info" |
| 56 |
PINS = "urn:av-openhome-org:serviceId:Pins" |
| 57 |
PLAYLIST = "urn:av-openhome-org:serviceId:Playlist" |
| 58 |
PLAYLISTMANAGER = "urn:av-openhome-org:serviceId:PlaylistManager" |
| 59 |
PRODUCT = "urn:av-openhome-org:serviceId:Product" |
| 60 |
RADIO = "urn:av-openhome-org:serviceId:Radio" |
| 61 |
RECEIVER = "urn:av-openhome-org:serviceId:Receiver" |
| 62 |
SENDER = "urn:av-openhome-org:serviceId:Sender" |
| 63 |
TIME = "urn:av-openhome-org:serviceId:Time" |
| 64 |
TRANSPORT = "urn:av-openhome-org:serviceId:Transport" |
| 65 |
VOLUME = "urn:av-openhome-org:serviceId:Volume" |
| 66 |
# LINN |
| 67 |
DIAGNOSTICS = "urn:linn-co-uk:serviceId:Diagnostics" |
| 68 |
PRIVACY = "urn:linn-co-uk:serviceId:Privacy" |
| 69 |
UPDATE = "urn:linn-co-uk:serviceId:Update" |
| 70 |
VOLKANO = "urn:linn-co-uk:serviceId:Volkano" |
| 71 |
|
| 72 |
|
| 73 |
class ProductSourceType(str, Enum): |
| 74 |
"""Supported values for Product Source Type.""" |
| 75 |
|
| 76 |
ANALOG = "Analog" # Specifies an analog external input |
| 77 |
DIGITAL = "Digital" # Specifies a digital external input |
| 78 |
HDMI = "Hdmi" # Specifies a HDMI external input |
| 79 |
NETAUX = "NetAux" # Specifies 3rd party, non OpenHome controllable, network protocols such as AirPlay |
| 80 |
PLAYLIST = "Playlist" # the av.openhome.org:Playlist:1 service must be available |
| 81 |
RADIO = "Radio" # the av.openhome.org:Radio:1 service must be available |
| 82 |
RECEIVER = "Receiver" # the av.openhome.org:Receiver:1 service must be available |
| 83 |
UPNPAV = "UpnpAv" # the upnp.org:MediaRenderer:1 device must be available |
| 84 |
|
| 85 |
|
| 86 |
# endregion |
| 87 |
|
| 88 |
|
| 89 |
# region Action Enums |
| 90 |
# These Enums are intended to cover the complete specification |
| 91 |
# Only a subset of actions which are deemed useful at present are implemented |
| 92 |
class Credentials(str, Enum): |
| 93 |
"""Actions for Credentials Service.""" |
| 94 |
|
| 95 |
SET = "Set" |
| 96 |
CLEAR = "Clear" |
| 97 |
SET_ENABLED = "SetEnabled" |
| 98 |
GET = "Get" |
| 99 |
LOGIN = "Login" |
| 100 |
RE_LOGIN = "ReLogin" |
| 101 |
GET_IDS = "GetIds" |
| 102 |
GET_PUBLIC_KEY = "GetPublicKey" |
| 103 |
GET_SEQUENCE_NUMBER = "GetSequenceNumber" |
| 104 |
|
| 105 |
|
| 106 |
class Info(str, Enum): |
| 107 |
"""Actions for Info Service.""" |
| 108 |
|
| 109 |
COUNTERS = "Counters" |
| 110 |
TRACK = "Track" |
| 111 |
DETAILS = "Details" |
| 112 |
METATEXT = "Metatext" |
| 113 |
|
| 114 |
|
| 115 |
class Pins(str, Enum): |
| 116 |
"""Actions for Pins Service.""" |
| 117 |
|
| 118 |
GET_DEVICE_MAX = "GetDeviceMax" |
| 119 |
GET_ACCOUNT_MAX = "GetAccountMax" |
| 120 |
GET_MODES = "GetModes" |
| 121 |
GET_ID_ARRAY = "GetIdArray" |
| 122 |
GET_CLOUD_CONNECTED = "GetCloudConnected" |
| 123 |
READ_LIST = "ReadList" |
| 124 |
INVOKE_ID = "InvokeId" |
| 125 |
INVOKE_INDEX = "InvokeIndex" |
| 126 |
INVOKE_URI = "InvokeUri" |
| 127 |
SET_DEVICE = "SetDevice" |
| 128 |
SET_ACCOUNT = "SetAccount" |
| 129 |
CLEAR = "Clear" |
| 130 |
SWAP = "Swap" |
| 131 |
|
| 132 |
|
| 133 |
class Playlist(str, Enum): |
| 134 |
"""Actions for Playlist Service.""" |
| 135 |
|
| 136 |
PLAY = "Play" |
| 137 |
PAUSE = "Pause" |
| 138 |
STOP = "Stop" |
| 139 |
NEXT = "Next" |
| 140 |
PREVIOUS = "Previous" |
| 141 |
SET_REPEAT = "SetRepeat" |
| 142 |
REPEAT = "Repeat" |
| 143 |
SET_SHUFFLE = "SetShuffle" |
| 144 |
SHUFFLE = "Shuffle" |
| 145 |
SEEK_SECOND_ABSOLUTE = "SeekSecondAbsolute" |
| 146 |
SEEK_SECOND_RELATIVE = "SeekSecondRelative" |
| 147 |
SEEK_ID = "SeekId" |
| 148 |
SEEK_INDEX = "SeekIndex" |
| 149 |
TRANSPORT_STATE = "TransportState" |
| 150 |
ID = "Id" |
| 151 |
READ = "Read" |
| 152 |
READ_LIST = "ReadList" |
| 153 |
INSERT = "Insert" |
| 154 |
DELETE_ID = "DeleteId" |
| 155 |
DELETE_ALL = "DeleteAll" |
| 156 |
TRACKS_MAX = "TracksMax" |
| 157 |
ID_ARRAY = "IdArray" |
| 158 |
ID_ARRAY_CHANGED = "IdArrayChanged" |
| 159 |
PROTOCOL_INFO = "ProtocolInfo" |
| 160 |
|
| 161 |
|
| 162 |
class Product(str, Enum): |
| 163 |
"""Actions for Product Service.""" |
| 164 |
|
| 165 |
MANUFACTURER = "Manufacturer" |
| 166 |
MODEL = "Model" |
| 167 |
PRODUCT = "Product" |
| 168 |
STANDBY = "Standby" |
| 169 |
STANDBY_TRANSITIONING = "StandbyTransitioning" |
| 170 |
SET_STANDBY = "SetStandby" |
| 171 |
SOURCE_COUNT = "SourceCount" |
| 172 |
SOURCE_XML = "SourceXml" |
| 173 |
SOURCE_INDEX = "SourceIndex" |
| 174 |
SET_SOURCE_INDEX = "SetSourceIndex" |
| 175 |
SET_SOURCE_BY_SYSTEM_NAME = "SetSourceBySystemName" |
| 176 |
SOURCE = "Source" |
| 177 |
ATTRIBUTES = "Attributes" |
| 178 |
SOURCE_XML_CHANGE_COUNT = "SourceXmlChangeCount" |
| 179 |
GET_IMAGE_URI = "GetImageUri" |
| 180 |
|
| 181 |
|
| 182 |
class Radio(str, Enum): |
| 183 |
"""Actions for Radio Service.""" |
| 184 |
|
| 185 |
REFRESH_PRESETS = "RefreshPresets" |
| 186 |
PLAY = "Play" |
| 187 |
PAUSE = "Pause" |
| 188 |
STOP = "Stop" |
| 189 |
SEEK_SECOND_ABSOLUTE = "SeekSecondAbsolute" |
| 190 |
SEEK_SECOND_RELATIVE = "SeekSecondRelative" |
| 191 |
CHANNEL = "Channel" |
| 192 |
SET_CHANNEL = "SetChannel" |
| 193 |
TRANSPORT_STATE = "TransportState" |
| 194 |
ID = "Id" |
| 195 |
SET_ID = "SetId" |
| 196 |
READ = "Read" |
| 197 |
READ_LIST = "ReadList" |
| 198 |
ID_ARRAY = "IdArray" |
| 199 |
ID_ARRAY_CHANGED = "IdArrayChanged" |
| 200 |
CHANNELS_MAX = "ChannelsMax" |
| 201 |
PROTOCOL_INFO = "ProtocolInfo" |
| 202 |
|
| 203 |
|
| 204 |
class Receiver(str, Enum): |
| 205 |
"""Actions for Receiver Service.""" |
| 206 |
|
| 207 |
PLAY = "Play" |
| 208 |
STOP = "Stop" |
| 209 |
SET_SENDER = "SetSender" |
| 210 |
SENDER = "Sender" |
| 211 |
PROTOCOL_INFO = "ProtocolInfo" |
| 212 |
TRANSPORT_STATE = "TransportState" |
| 213 |
|
| 214 |
|
| 215 |
class Sender(str, Enum): |
| 216 |
"""Actions for Sender Service.""" |
| 217 |
|
| 218 |
PRESENTATION_URL = "PresentationUrl" |
| 219 |
METADATA = "Metadata" |
| 220 |
AUDIO = "Audio" |
| 221 |
STATUS = "Status" |
| 222 |
STATUS2 = "Status2" |
| 223 |
ENABLED = "Enabled" |
| 224 |
ATTRIBUTES = "Attributes" |
| 225 |
|
| 226 |
|
| 227 |
class Time(str, Enum): |
| 228 |
"""Actions for Time Service.""" |
| 229 |
|
| 230 |
TIME = "Time" |
| 231 |
|
| 232 |
|
| 233 |
class Transport(str, Enum): |
| 234 |
"""Actions for Transport Service.""" |
| 235 |
|
| 236 |
PLAY_AS = "PlayAs" |
| 237 |
PLAY = "Play" |
| 238 |
PAUSE = "Pause" |
| 239 |
STOP = "Stop" |
| 240 |
SKIP_NEXT = "SkipNext" |
| 241 |
SKIP_PREVIOUS = "SkipPrevious" |
| 242 |
SET_REPEAT = "SetRepeat" |
| 243 |
SET_SHUFFLE = "SetShuffle" |
| 244 |
SEEK_SECOND_ABSOLUTE = "SeekSecondAbsolute" |
| 245 |
SEEK_SECOND_RELATIVE = "SeekSecondRelative" |
| 246 |
TRANSPORT_STATE = "TransportState" |
| 247 |
MODES = "Modes" |
| 248 |
MODE_INFO = "ModeInfo" |
| 249 |
STREAM_INFO = "StreamInfo" |
| 250 |
STREAM_ID = "StreamId" |
| 251 |
REPEAT = "Repeat" |
| 252 |
SHUFFLE = "Shuffle" |
| 253 |
|
| 254 |
|
| 255 |
class Update(str, Enum): |
| 256 |
"""Actions for Update Service.""" |
| 257 |
|
| 258 |
GET_SOFTWARE_STATUS = "GetSoftwareStatus" |
| 259 |
GET_EXECUTOR_STATUS = "GetExecutorStatus" |
| 260 |
GET_JOB_STATUS = "GetJobStatus" |
| 261 |
PUSH_MANIFEST = "PushManifest" |
| 262 |
PUSH_MANIFEST2 = "PushManifest2" |
| 263 |
APPLY = "Apply" |
| 264 |
APPLY2 = "Apply2" |
| 265 |
RECOVER = "Recover" |
| 266 |
RECOVER2 = "Recover2" |
| 267 |
RECOVER_KEEP_STORE = "RecoverKeepStore" |
| 268 |
RECOVER_KEEP_STORE2 = "RecoverKeepStore2" |
| 269 |
CHECK_NOW = "CheckNow" |
| 270 |
GET_RECOVER_SUPPORTED = "GetRecoverSupported" |
| 271 |
|
| 272 |
|
| 273 |
class Volume(str, Enum): |
| 274 |
"""Action names for Volume service.""" |
| 275 |
|
| 276 |
CHARACTERISTICS = "Characteristics" |
| 277 |
SET_VOLUME = "SetVolume" |
| 278 |
VOLUME_INC = "VolumeInc" |
| 279 |
VOLUME_DEC = "VolumeDec" |
| 280 |
SET_VOLUME_NO_UNMUTE = "SetVolumeNoUnmute" |
| 281 |
VOLUME_INC_NO_UNMUTE = "VolumeIncNoUnmute" |
| 282 |
VOLUME_DEC_NO_UNMUTE = "VolumeDecNoUnmute" |
| 283 |
VOLUME = "Volume" |
| 284 |
SET_BALANCE = "SetBalance" |
| 285 |
BALANCE_INC = "BalanceInc" |
| 286 |
BALANCE_DEC = "BalanceDec" |
| 287 |
BALANCE = "Balance" |
| 288 |
SET_FADE = "SetFade" |
| 289 |
FADE_INC = "FadeInc" |
| 290 |
FADE_DEC = "FadeDec" |
| 291 |
FADE = "Fade" |
| 292 |
SET_MUTE = "SetMute" |
| 293 |
MUTE = "Mute" |
| 294 |
VOLUME_LIMIT = "VolumeLimit" |
| 295 |
UNITY_GAIN = "UnityGain" |
| 296 |
VOLUME_OFFSET = "VolumeOffset" |
| 297 |
SET_VOLUME_OFFSET = "SetVolumeOffset" |
| 298 |
TRIM = "Trim" |
| 299 |
SET_TRIM = "SetTrim" |
| 300 |
|
| 301 |
|
| 302 |
# endregion |
| 303 |
|
| 304 |
|
| 305 |
# region State Variable Enums |
| 306 |
class CredentialsState(str, Enum): |
| 307 |
"""State variable names for Credentials service.""" |
| 308 |
|
| 309 |
IDS = "Ids" |
| 310 |
PUBLIC_KEY = "PublicKey" |
| 311 |
SEQUENCE_NUMBER = "SequenceNumber" |
| 312 |
|
| 313 |
|
| 314 |
class InfoState(str, Enum): |
| 315 |
"""State variable names for Info service.""" |
| 316 |
|
| 317 |
BIT_DEPTH = "BitDepth" |
| 318 |
BIT_RATE = "BitRate" |
| 319 |
CODEC_NAME = "CodecName" |
| 320 |
DETAILS_COUNT = "DetailsCount" |
| 321 |
DURATION = "Duration" |
| 322 |
LOSSLESS = "Lossless" |
| 323 |
METADATA = "Metadata" |
| 324 |
METATEXT = "Metatext" |
| 325 |
METATEXT_COUNT = "MetatextCount" |
| 326 |
SAMPLE_RATE = "SampleRate" |
| 327 |
TRACK_COUNT = "TrackCount" |
| 328 |
URI = "Uri" |
| 329 |
|
| 330 |
|
| 331 |
class PinsState(str, Enum): |
| 332 |
"""State variable names for Pins service.""" |
| 333 |
|
| 334 |
ACCOUNT_MAX = "AccountMax" |
| 335 |
CLOUD_CONNECTED = "CloudConnected" |
| 336 |
DEVICE_MAX = "DeviceMax" |
| 337 |
ID_ARRAY = "IdArray" |
| 338 |
MODES = "Modes" |
| 339 |
|
| 340 |
|
| 341 |
class PlaylistState(str, Enum): |
| 342 |
"""State variable names for Playlist service.""" |
| 343 |
|
| 344 |
ID = "Id" |
| 345 |
ID_ARRAY = "IdArray" |
| 346 |
PROTOCOL_INFO = "ProtocolInfo" |
| 347 |
REPEAT = "Repeat" |
| 348 |
SHUFFLE = "Shuffle" |
| 349 |
TRACKS_MAX = "TracksMax" |
| 350 |
TRANSPORT_STATE = "TransportState" |
| 351 |
|
| 352 |
|
| 353 |
class PlaylistStateAllowedValues(str, Enum): |
| 354 |
"""Allowed values for Playlist service.""" |
| 355 |
|
| 356 |
BUFFERING = "Buffering" |
| 357 |
PAUSED = "Paused" |
| 358 |
PLAYING = "Playing" |
| 359 |
STOPPED = "Stopped" |
| 360 |
|
| 361 |
|
| 362 |
class ProductState(str, Enum): |
| 363 |
"""State variable names for Product service.""" |
| 364 |
|
| 365 |
ATTRIBUTES = "Attributes" |
| 366 |
MANUFACTURER_IMAGE_URI = "ManufacturerImageUri" |
| 367 |
MANUFACTURER_INFO = "ManufacturerInfo" |
| 368 |
MANUFACTURER_NAME = "ManufacturerName" |
| 369 |
MANUFACTURER_URL = "ManufacturerUrl" |
| 370 |
MODEL_IMAGE_URI = "ModelImageUri" |
| 371 |
MODEL_INFO = "ModelInfo" |
| 372 |
MODEL_NAME = "ModelName" |
| 373 |
MODEL_URL = "ModelUrl" |
| 374 |
PRODUCT_IMAGE_HIRES_URI = "ProductImageHiresUri" |
| 375 |
PRODUCT_IMAGE_URI = "ProductImageUri" |
| 376 |
PRODUCT_INFO = "ProductInfo" |
| 377 |
PRODUCT_NAME = "ProductName" |
| 378 |
PRODUCT_ROOM = "ProductRoom" |
| 379 |
PRODUCT_URL = "ProductUrl" |
| 380 |
SOURCE_COUNT = "SourceCount" |
| 381 |
SOURCE_INDEX = "SourceIndex" |
| 382 |
SOURCE_NAME = "A_ARG_TYPE_Source_Name" |
| 383 |
SOURCE_SYSTEM_NAME = "A_ARG_TYPE_Source_SystemName" |
| 384 |
SOURCE_TYPE = "A_ARG_TYPE_Source_Type" |
| 385 |
SOURCE_VISIBLE = "A_ARG_TYPE_Source_Visible" |
| 386 |
SOURCE_XML = "SourceXml" |
| 387 |
SOURCE_XML_CHANGE_COUNT_VALUE = "A_ARG_TYPE_SourceXmlChangeCount_Value" |
| 388 |
STANDBY = "Standby" |
| 389 |
STANDBY_TRANSITIONING = "StandbyTransitioning" |
| 390 |
|
| 391 |
|
| 392 |
class RadioState(str, Enum): |
| 393 |
"""State variable names for Radio service.""" |
| 394 |
|
| 395 |
CHANNELS_MAX = "ChannelsMax" |
| 396 |
ID = "Id" |
| 397 |
ID_ARRAY = "IdArray" |
| 398 |
PROTOCOL_INFO = "ProtocolInfo" |
| 399 |
METADATA = "Metadata" |
| 400 |
URI = "Uri" |
| 401 |
TRANSPORT_STATE = "TransportState" |
| 402 |
|
| 403 |
|
| 404 |
class ReceiverState(str, Enum): |
| 405 |
"""State variable names for Receiver service.""" |
| 406 |
|
| 407 |
PROTOCOL_INFO = "ProtocolInfo" |
| 408 |
METADATA = "Receiver_Metadata" |
| 409 |
URI = "Receiver_Uri" |
| 410 |
TRANSPORT_STATE = "TransportState" |
| 411 |
|
| 412 |
|
| 413 |
class SenderState(str, Enum): |
| 414 |
"""State variable names for Sender service.""" |
| 415 |
|
| 416 |
ATTRIBUTES = "Attributes" |
| 417 |
AUDIO = "Audio" |
| 418 |
ENABLED = "Enabled" |
| 419 |
PRESENTATION_URL = "PresentationUrl" |
| 420 |
METADATA = "Metadata" |
| 421 |
STATUS = "Status" |
| 422 |
STATUS2 = "Status2" |
| 423 |
|
| 424 |
|
| 425 |
class TimeState(str, Enum): |
| 426 |
"""State variable names for Time service.""" |
| 427 |
|
| 428 |
DURATION = "Duration" |
| 429 |
SECONDS = "Seconds" |
| 430 |
TRACK_COUNT = "TrackCount" |
| 431 |
|
| 432 |
|
| 433 |
class TransportState(str, Enum): |
| 434 |
"""State variable names for Transport service.""" |
| 435 |
|
| 436 |
CAN_PAUSE = "CanPause" |
| 437 |
CAN_REPEAT = "CanRepeat" |
| 438 |
CAN_SEEK = "CanSeek" |
| 439 |
CAN_SHUFFLE = "CanShuffle" |
| 440 |
CAN_SKIP_NEXT = "CanSkipNext" |
| 441 |
CAN_SKIP_PREVIOUS = "CanSkipPrevious" |
| 442 |
MODES = "Modes" |
| 443 |
REPEAT = "Repeat" |
| 444 |
SHUFFLE = "Shuffle" |
| 445 |
STREAM_ID = "StreamId" |
| 446 |
TRANSPORT_STATE = "TransportState" |
| 447 |
|
| 448 |
|
| 449 |
class TransportStateAllowedValues(str, Enum): |
| 450 |
"""Allowed values for Transport service.""" |
| 451 |
|
| 452 |
BUFFERING = "Buffering" |
| 453 |
PAUSED = "Paused" |
| 454 |
PLAYING = "Playing" |
| 455 |
STOPPED = "Stopped" |
| 456 |
WAITING = "Waiting" |
| 457 |
|
| 458 |
|
| 459 |
class UpdateState(str, Enum): |
| 460 |
"""State variable names for Update service.""" |
| 461 |
|
| 462 |
EXECUTOR_STATUS = "ExecutorStatus" |
| 463 |
JOB_STATUS = "JobStatus" |
| 464 |
RECOVER_SUPPORTED = "RecoverSupported" |
| 465 |
SOFTWARE_STATUS = "SoftwareStatus" |
| 466 |
|
| 467 |
|
| 468 |
class VolumeState(str, Enum): |
| 469 |
"""State variable names for Volume service.""" |
| 470 |
|
| 471 |
BALANCE = "Balance" |
| 472 |
BALANCE_MAX = "BalanceMax" |
| 473 |
FADE = "Fade" |
| 474 |
FADE_MAX = "FadeMax" |
| 475 |
MUTE = "Mute" |
| 476 |
TRIM = "A_ARG_TYPE_Trim_TrimBinaryMilliDb" |
| 477 |
UNITY_GAIN = "UnityGain" |
| 478 |
VOLUME = "Volume" |
| 479 |
VOLUME_LIMIT = "VolumeLimit" |
| 480 |
VOLUME_MAX = "VolumeMax" |
| 481 |
VOLUME_MILLI_DB_PER_STEP = "VolumeMilliDbPerStep" |
| 482 |
VOLUME_OFFSET = "A_ARG_TYPE_VolumeOffset_VolumeOffsetBinaryMilliDb" |
| 483 |
VOLUME_STEPS = "VolumeSteps" |
| 484 |
VOLUME_UNITY = "VolumeUnity" |
| 485 |
|
| 486 |
|
| 487 |
# endregion |
| 488 |
|
| 489 |
|
| 490 |
class OhmDevice(UpnpProfileDevice): |
| 491 |
"""Representation of an OpenHome Media (ohMedia) device.""" |
| 492 |
|
| 493 |
# region enums and constants |
| 494 |
DEVICE_TYPES = [ |
| 495 |
"urn:av-openhome-org:device:Source:1", |
| 496 |
"urn:linn-co-uk:device:Source:1", |
| 497 |
] |
| 498 |
|
| 499 |
# Product is the only service which must be available to be OpenHome Media compliant |
| 500 |
SERVICE_IDS = frozenset(("urn:av-openhome-org:serviceId:Product",)) |
| 501 |
|
| 502 |
_SERVICE_TYPES = { |
| 503 |
"Credentials": {"urn:av-openhome-org:service:Credentials:1"}, |
| 504 |
"Info": {"urn:av-openhome-org:service:Info:1"}, |
| 505 |
"Pins": {"urn:av-openhome-org:service:Pins:1"}, |
| 506 |
"Playlist": {"urn:av-openhome-org:service:Playlist:1"}, |
| 507 |
"Product": { |
| 508 |
"urn:av-openhome-org:service:Product:4", |
| 509 |
"urn:av-openhome-org:service:Product:3", |
| 510 |
"urn:av-openhome-org:service:Product:2", |
| 511 |
"urn:av-openhome-org:service:Product:1", |
| 512 |
}, |
| 513 |
"Radio": { |
| 514 |
"urn:av-openhome-org:service:Radio:2", |
| 515 |
"urn:av-openhome-org:service:Radio:1", |
| 516 |
}, |
| 517 |
"Receiver": {"urn:av-openhome-org:service:Receiver:1"}, |
| 518 |
"Sender": { |
| 519 |
"urn:av-openhome-org:service:Sender:2", |
| 520 |
"urn:av-openhome-org:service:Sender:1", |
| 521 |
}, |
| 522 |
"Time": {"urn:av-openhome-org:service:Time:1"}, |
| 523 |
"Transport": {"urn:av-openhome-org:service:Transport:1"}, |
| 524 |
"Volume": { |
| 525 |
"urn:av-openhome-org:service:Volume:4", |
| 526 |
"urn:av-openhome-org:service:Volume:3", |
| 527 |
"urn:av-openhome-org:service:Volume:2", |
| 528 |
"urn:av-openhome-org:service:Volume:1", |
| 529 |
}, |
| 530 |
"Update": { |
| 531 |
"urn:linn-co-uk:service:Update:4", |
| 532 |
}, |
| 533 |
} |
| 534 |
# endregion |
| 535 |
|
| 536 |
# region Credentials Service actions |
| 537 |
async def async_credentials_set(self, ident: str, username: str, password: str) -> None: |
| 538 |
"""Set the username and password for a given service. |
| 539 |
|
| 540 |
:param ident: the identifier for the service |
| 541 |
:param username: username for the service |
| 542 |
:param password: must be encrypted using the RSA public key in the PublicKey state variable |
| 543 |
""" |
| 544 |
await self._async_call_action( |
| 545 |
Service.CREDENTIALS, |
| 546 |
Credentials.SET, |
| 547 |
Id=ident, |
| 548 |
UserName=username, |
| 549 |
Password=password, |
| 550 |
) |
| 551 |
|
| 552 |
async def async_credentials_clear(self, ident: str) -> None: |
| 553 |
"""Remove both username and password for a given service. |
| 554 |
|
| 555 |
:param ident: the identifier for the service |
| 556 |
""" |
| 557 |
await self._async_call_action(Service.CREDENTIALS, Credentials.CLEAR, Id=ident) |
| 558 |
|
| 559 |
async def async_credentials_set_enabled(self, ident: str, enabled: bool) -> None: |
| 560 |
"""Set or clear the enabled state of a service. |
| 561 |
|
| 562 |
:param ident: the identifier of the credentials |
| 563 |
:param enabled: whether enabled or not |
| 564 |
""" |
| 565 |
await self._async_call_action(Service.CREDENTIALS, Credentials.SET_ENABLED, Id=ident, Enabled=enabled) |
| 566 |
|
| 567 |
async def async_credentials_get(self, ident: str) -> Mapping[str, str | bool]: |
| 568 |
"""Retrieve username, password, status and enabled state for a service. |
| 569 |
|
| 570 |
:param ident: the identifier for the service |
| 571 |
""" |
| 572 |
return await self._async_call_action(Service.CREDENTIALS, Credentials.GET, Id=ident) |
| 573 |
|
| 574 |
async def async_credentials_login(self, ident: str) -> Mapping[str, Any]: |
| 575 |
"""Read a token indicating that a registered user has logged in to a remote service. |
| 576 |
|
| 577 |
:param ident: the identifier for the service |
| 578 |
""" |
| 579 |
return await self._async_call_action(Service.CREDENTIALS, Credentials.LOGIN, Id=ident) |
| 580 |
|
| 581 |
async def async_credentials_re_login(self, ident: str, currenttoken: str) -> Mapping[str, Any]: |
| 582 |
"""Refresh an existing token returned from Login(). |
| 583 |
|
| 584 |
:param ident: the identifier for the service |
| 585 |
:param currenttoken: the current token for the service |
| 586 |
""" |
| 587 |
return await self._async_call_action( |
| 588 |
Service.CREDENTIALS, |
| 589 |
Credentials.RE_LOGIN, |
| 590 |
Id=ident, |
| 591 |
CurrentToken=currenttoken, |
| 592 |
) |
| 593 |
|
| 594 |
async def async_credentials_get_ids(self) -> Mapping[str, str]: |
| 595 |
"""Return list of identifiers for services whose credentials can be set.""" |
| 596 |
return await self._async_call_action(Service.CREDENTIALS, Credentials.GET_IDS) |
| 597 |
|
| 598 |
async def async_credentials_get_public_key(self) -> Mapping[str, str]: |
| 599 |
"""Return RSA public key that must be used to encrypt any/all passwords.""" |
| 600 |
return await self._async_call_action(Service.CREDENTIALS, Credentials.GET_PUBLIC_KEY) |
| 601 |
|
| 602 |
async def async_credentials_get_sequence_number(self) -> Mapping[str, int]: |
| 603 |
"""Return Sequence Number.""" |
| 604 |
return await self._async_call_action(Service.CREDENTIALS, Credentials.GET_SEQUENCE_NUMBER) |
| 605 |
|
| 606 |
# endregion |
| 607 |
# region Info Service actions |
| 608 |
async def async_info_counters(self) -> Mapping[str, int]: |
| 609 |
"""Return the counters used to version Track, Details, and Metatext information.""" |
| 610 |
return await self._async_call_action(Service.INFO, Info.COUNTERS) |
| 611 |
|
| 612 |
async def async_info_track(self) -> Mapping[str, str]: |
| 613 |
"""Return current track information concerning the current media.""" |
| 614 |
return await self._async_call_action(Service.INFO, Info.TRACK) |
| 615 |
|
| 616 |
async def async_info_details(self) -> Mapping[str, int | bool | str]: |
| 617 |
"""Return details concerning the current media.""" |
| 618 |
return await self._async_call_action(Service.INFO, Info.DETAILS) |
| 619 |
|
| 620 |
async def async_info_metatext(self) -> Mapping[str, str]: |
| 621 |
"""Return dynamic textual information concerning the current media.""" |
| 622 |
return await self._async_call_action(Service.INFO, Info.METATEXT) |
| 623 |
|
| 624 |
# endregion |
| 625 |
# region Pins Service actions |
| 626 |
async def async_pins_get_device_max(self) -> Mapping[str, int]: |
| 627 |
"""Return the value of the DeviceMax state variable. |
| 628 |
|
| 629 |
:return: DeviceMax |
| 630 |
DeviceMax is the maximum number of device-specific pins supported |
| 631 |
""" |
| 632 |
return await self._async_call_action(Service.PINS, Pins.GET_DEVICE_MAX) |
| 633 |
|
| 634 |
async def async_pins_get_account_max(self) -> Mapping[str, int]: |
| 635 |
"""Return the value of the AccountMax state variable. |
| 636 |
|
| 637 |
:return: AccountMax |
| 638 |
AccountMax is the maximum number of account-wide pins supported |
| 639 |
""" |
| 640 |
return await self._async_call_action(Service.PINS, Pins.GET_ACCOUNT_MAX) |
| 641 |
|
| 642 |
async def async_pins_get_modes(self) -> Mapping[str, str]: |
| 643 |
"""Return the value of the Modes state variable. |
| 644 |
|
| 645 |
:return: Modes |
| 646 |
Modes is a JSON array of strings identifying the different styles of pins supported |
| 647 |
""" |
| 648 |
return await self._async_call_action(Service.PINS, Pins.GET_MODES) |
| 649 |
|
| 650 |
async def async_pins_get_id_array(self) -> Mapping[str, str]: |
| 651 |
"""Get pins id array. |
| 652 |
|
| 653 |
:return: IdArray |
| 654 |
""" |
| 655 |
return await self._async_call_action(Service.PINS, Pins.GET_ID_ARRAY) |
| 656 |
|
| 657 |
async def async_pins_read_list(self, ids: str) -> Mapping[str, str]: |
| 658 |
"""Get pins metadata. |
| 659 |
|
| 660 |
:param ids: string representation of integer array of ids of pins |
| 661 |
|
| 662 |
:return: List |
| 663 |
""" |
| 664 |
return await self._async_call_action(Service.PINS, Pins.READ_LIST, Ids=ids) |
| 665 |
|
| 666 |
async def async_pins_invoke_uri(self, mode: str, pin_type: str, uri: str, shuffle: bool) -> None: |
| 667 |
"""Invoke a pin using data (mode, type, uri, shuffle) from a control point. |
| 668 |
|
| 669 |
:param mode: one of the modes available from GetModes |
| 670 |
:param type: the type of the uri |
| 671 |
:param uri: the uri of the stream/track |
| 672 |
:param shuffle: whether to shuffle or not |
| 673 |
|
| 674 |
""" |
| 675 |
await self._async_call_action( |
| 676 |
Service.PINS, |
| 677 |
Pins.INVOKE_URI, |
| 678 |
Mode=mode, |
| 679 |
Type=pin_type, |
| 680 |
Uri=uri, |
| 681 |
Shuffle=shuffle, |
| 682 |
) |
| 683 |
|
| 684 |
async def async_pins_invoke_id(self, ident: int) -> None: |
| 685 |
"""Invoke the pin with identifier ident. |
| 686 |
|
| 687 |
:param ident: the identifier of the pin in the IdArray |
| 688 |
""" |
| 689 |
await self._async_call_action(Service.PINS, Pins.INVOKE_ID, Id=ident) |
| 690 |
|
| 691 |
async def async_pins_invoke_index(self, index: int) -> None: |
| 692 |
"""Invoke the pin at the specified index in IdArray. |
| 693 |
|
| 694 |
:param index: the index of the pin to invoke |
| 695 |
|
| 696 |
Note that index expected here corresponds to the 1-based index as presented by the Linn app |
| 697 |
This normally ranges from 1 to DeviceMax corresponding to a Python 0-based array index from 0 to DeviceMax-1 |
| 698 |
""" |
| 699 |
await self._async_call_action(Service.PINS, Pins.INVOKE_INDEX, Index=index - 1) |
| 700 |
|
| 701 |
# pylint: disable=too-many-arguments,too-many-positional-arguments |
| 702 |
async def async_pins_set_device( |
| 703 |
self, |
| 704 |
index: int, |
| 705 |
mode: str, |
| 706 |
pin_type: str, |
| 707 |
uri: str, |
| 708 |
title: str, |
| 709 |
description: str, |
| 710 |
artworkuri: str, |
| 711 |
shuffle: bool, |
| 712 |
) -> None: |
| 713 |
"""Set a device pin, specifying the parameters of the device pin.""" |
| 714 |
await self._async_call_action( |
| 715 |
Service.PINS, |
| 716 |
Pins.SET_DEVICE, |
| 717 |
Index=index, |
| 718 |
Mode=mode, |
| 719 |
Type=pin_type, |
| 720 |
Uri=uri, |
| 721 |
Title=title, |
| 722 |
Description=description, |
| 723 |
ArtworkUri=artworkuri, |
| 724 |
Shuffle=shuffle, |
| 725 |
) |
| 726 |
|
| 727 |
async def async_pins_set_account( |
| 728 |
self, |
| 729 |
index: int, |
| 730 |
mode: str, |
| 731 |
pin_type: str, |
| 732 |
uri: str, |
| 733 |
title: str, |
| 734 |
description: str, |
| 735 |
artworkuri: str, |
| 736 |
shuffle: bool, |
| 737 |
) -> None: |
| 738 |
"""Set an account pin, specifying the parameters of the account pin.""" |
| 739 |
await self._async_call_action( |
| 740 |
Service.PINS, |
| 741 |
Pins.SET_ACCOUNT, |
| 742 |
Index=index, |
| 743 |
Mode=mode, |
| 744 |
Type=pin_type, |
| 745 |
Uri=uri, |
| 746 |
Title=title, |
| 747 |
Description=description, |
| 748 |
ArtworkUri=artworkuri, |
| 749 |
Shuffle=shuffle, |
| 750 |
) |
| 751 |
|
| 752 |
async def async_pins_clear(self, ident: int) -> None: |
| 753 |
"""Clear any content in the pin with the specified identifier. |
| 754 |
|
| 755 |
:param ident: the identifier of the pin to clear |
| 756 |
""" |
| 757 |
await self._async_call_action(Service.PINS, Pins.CLEAR, Id=ident) |
| 758 |
|
| 759 |
async def async_pins_swap(self, index1: int, index2: int) -> None: |
| 760 |
"""Swap contents of the 2 pins at the specified indices. |
| 761 |
|
| 762 |
:param index1: the index to swap |
| 763 |
:param index2: the index to swap |
| 764 |
""" |
| 765 |
await self._async_call_action(Service.PINS, Pins.SWAP, Index1=index1, Index2=index2) |
| 766 |
|
| 767 |
# endregion |
| 768 |
# region Playlist Service actions |
| 769 |
async def async_playlist_stop(self) -> None: |
| 770 |
"""Stop the current track.""" |
| 771 |
await self._async_call_action(Service.PLAYLIST, Playlist.STOP) |
| 772 |
|
| 773 |
async def async_playlist_pause(self) -> None: |
| 774 |
"""Pause the current track.""" |
| 775 |
await self._async_call_action(Service.PLAYLIST, Playlist.PAUSE) |
| 776 |
|
| 777 |
async def async_playlist_play(self) -> None: |
| 778 |
"""Start playing the track indicated by the Id state variable.""" |
| 779 |
await self._async_call_action(Service.PLAYLIST, Playlist.PLAY) |
| 780 |
|
| 781 |
async def async_playlist_next(self) -> None: |
| 782 |
"""Start playing the next track in the playlist.""" |
| 783 |
await self._async_call_action(Service.PLAYLIST, Playlist.NEXT) |
| 784 |
|
| 785 |
async def async_playlist_previous(self) -> None: |
| 786 |
"""Start playing the previous track in the playlist.""" |
| 787 |
await self._async_call_action(Service.PLAYLIST, Playlist.PREVIOUS) |
| 788 |
|
| 789 |
async def async_playlist_set_repeat(self, value: bool) -> None: |
| 790 |
"""Enable or disable repeat mode. |
| 791 |
|
| 792 |
:param value: repeat mode |
| 793 |
""" |
| 794 |
await self._async_call_action(Service.PLAYLIST, Playlist.SET_REPEAT, Value=value) |
| 795 |
|
| 796 |
async def async_playlist_repeat(self) -> Mapping[str, bool]: |
| 797 |
"""Return the value of the Repeat state variable.""" |
| 798 |
return await self._async_call_action(Service.PLAYLIST, Playlist.REPEAT) |
| 799 |
|
| 800 |
async def async_playlist_set_shuffle(self, value: bool) -> None: |
| 801 |
"""Enable or disable shuffle mode. |
| 802 |
|
| 803 |
:param value: shuffle on or off |
| 804 |
""" |
| 805 |
await self._async_call_action(Service.PLAYLIST, Playlist.SET_SHUFFLE, Value=value) |
| 806 |
|
| 807 |
async def async_playlist_shuffle(self) -> Mapping[str, bool] | None: |
| 808 |
"""Return the value of the Shuffle state variable.""" |
| 809 |
return await self._async_call_action(Service.PLAYLIST, Playlist.SHUFFLE) |
| 810 |
|
| 811 |
async def async_playlist_seek_second_absolute(self, value: int) -> None: |
| 812 |
"""Seek to an absolute second within the current track. |
| 813 |
|
| 814 |
:param value: number of seconds to seek to |
| 815 |
""" |
| 816 |
await self._async_call_action(Service.PLAYLIST, Playlist.SEEK_SECOND_ABSOLUTE, Value=value) |
| 817 |
|
| 818 |
async def async_playlist_seek_second_relative(self, value: int) -> None: |
| 819 |
"""Seek to a relative second within the current track. |
| 820 |
|
| 821 |
:param value: number of seconds to seek to |
| 822 |
""" |
| 823 |
await self._async_call_action(Service.PLAYLIST, Playlist.SEEK_SECOND_RELATIVE, Value=value) |
| 824 |
|
| 825 |
async def async_playlist_seek_id(self, value: int) -> None: |
| 826 |
"""Switch to the track with the specified id. |
| 827 |
|
| 828 |
:param value: id |
| 829 |
""" |
| 830 |
await self._async_call_action(Service.PLAYLIST, Playlist.SEEK_ID, Value=value) |
| 831 |
|
| 832 |
async def async_playlist_seek_index(self, value: int) -> None: |
| 833 |
"""Switch to the track with the specified index. |
| 834 |
|
| 835 |
:param value: index |
| 836 |
""" |
| 837 |
await self._async_call_action(Service.PLAYLIST, Playlist.SEEK_INDEX, Value=value) |
| 838 |
|
| 839 |
async def async_playlist_transport_state(self) -> Mapping[str, str]: |
| 840 |
"""Return the value of the TransportState state variable.""" |
| 841 |
return await self._async_call_action(Service.PLAYLIST, Playlist.TRANSPORT_STATE) |
| 842 |
|
| 843 |
async def async_playlist_id(self) -> Mapping[str, int]: |
| 844 |
"""Return the value of the Id state variable.""" |
| 845 |
return await self._async_call_action(Service.PLAYLIST, Playlist.ID) |
| 846 |
|
| 847 |
async def async_playlist_read(self, ident: int) -> Mapping[str, str]: |
| 848 |
"""Return the uri and metadata for a given track id. |
| 849 |
|
| 850 |
:param ident: track identifier |
| 851 |
""" |
| 852 |
return await self._async_call_action(Service.PLAYLIST, Playlist.READ, Id=ident) |
| 853 |
|
| 854 |
async def async_playlist_read_list(self, idlist: str) -> Mapping[str, str]: |
| 855 |
"""Return associated uri and metadata for a list of track ids. |
| 856 |
|
| 857 |
:param idlist: space separated list of track Ids |
| 858 |
""" |
| 859 |
return await self._async_call_action(Service.PLAYLIST, Playlist.READ_LIST, IdList=idlist) |
| 860 |
|
| 861 |
async def async_playlist_insert(self, afterid: int, uri: str, metadata: str) -> Mapping[str, int]: |
| 862 |
"""Add the given uri and metadata as a new track to the playlist. |
| 863 |
|
| 864 |
:param afterid: insert track after this identifier; set to 0 to insert at start |
| 865 |
:param uri: uri of the track |
| 866 |
:param metadata: metadata of the track |
| 867 |
""" |
| 868 |
return await self._async_call_action( |
| 869 |
Service.PLAYLIST, |
| 870 |
Playlist.INSERT, |
| 871 |
AfterId=afterid, |
| 872 |
Uri=uri, |
| 873 |
Metadata=metadata, |
| 874 |
) |
| 875 |
|
| 876 |
async def async_playlist_delete_id(self, value: int) -> None: |
| 877 |
"""Perform the action DeleteId. |
| 878 |
|
| 879 |
:param value: the track id to delete from the playlist |
| 880 |
""" |
| 881 |
await self._async_call_action(Service.PLAYLIST, Playlist.DELETE_ID, Value=value) |
| 882 |
|
| 883 |
async def async_playlist_delete_all(self) -> None: |
| 884 |
"""Delete all tracks from the playlist.""" |
| 885 |
await self._async_call_action(Service.PLAYLIST, Playlist.DELETE_ALL) |
| 886 |
|
| 887 |
async def async_playlist_tracks_max(self) -> Mapping[str, int]: |
| 888 |
"""Return the value of the TracksMax state variable.""" |
| 889 |
return await self._async_call_action(Service.PLAYLIST, Playlist.TRACKS_MAX) |
| 890 |
|
| 891 |
async def async_playlist_id_array(self) -> Mapping[str, str]: |
| 892 |
"""Return the value of the IdArray and Token state variables.""" |
| 893 |
return await self._async_call_action(Service.PLAYLIST, Playlist.ID_ARRAY) |
| 894 |
|
| 895 |
async def async_playlist_id_array_changed(self, token: int) -> Mapping[str, bool]: |
| 896 |
"""Check if the token has changed. |
| 897 |
|
| 898 |
:param token: value of token |
| 899 |
""" |
| 900 |
return await self._async_call_action(Service.PLAYLIST, Playlist.ID_ARRAY_CHANGED, Token=token) |
| 901 |
|
| 902 |
async def async_playlist_protocol_info(self) -> Mapping[str, str]: |
| 903 |
"""Return the value of the ProtocolInfo state variable.""" |
| 904 |
return await self._async_call_action(Service.PLAYLIST, Playlist.PROTOCOL_INFO) |
| 905 |
|
| 906 |
# endregion |
| 907 |
# region Product Service actions |
| 908 |
|
| 909 |
async def async_product_attributes(self) -> Mapping[str, str]: |
| 910 |
"""Return the value of the Attributes state variable.""" |
| 911 |
return await self._async_call_action(Service.PRODUCT, Product.ATTRIBUTES) |
| 912 |
|
| 913 |
async def async_product(self) -> Mapping[str, str]: |
| 914 |
"""Return the values of the Product state variables. |
| 915 |
|
| 916 |
:return: ProductRoom, ProductName, ProductInfo, ProductUrl, ProductImageUri |
| 917 |
""" |
| 918 |
return await self._async_call_action(Service.PRODUCT, Product.PRODUCT) |
| 919 |
|
| 920 |
async def async_product_manufacturer(self) -> Mapping[str, str]: |
| 921 |
"""Return the values of the Manufacturer state variables. |
| 922 |
|
| 923 |
:return: ManufacturerName, ManufacturerInfo, ManufacturerUrl, ManufacturerImageUri |
| 924 |
""" |
| 925 |
return await self._async_call_action(Service.PRODUCT, Product.MANUFACTURER) |
| 926 |
|
| 927 |
async def async_product_model(self) -> Mapping[str, str]: |
| 928 |
"""Return the values of the Model state variables. |
| 929 |
|
| 930 |
:return: ModelName, ModelInfo, ModelUrl, ModelImageUri |
| 931 |
""" |
| 932 |
return await self._async_call_action(Service.PRODUCT, Product.MODEL) |
| 933 |
|
| 934 |
async def async_product_set_source_index(self, index: int) -> None: |
| 935 |
"""Set the currently active source.""" |
| 936 |
await self._async_call_action(Service.PRODUCT, Product.SET_SOURCE_INDEX, Value=index) |
| 937 |
|
| 938 |
async def async_product_set_standby(self, standby: bool) -> None: |
| 939 |
"""Set the product to standby.""" |
| 940 |
await self._async_call_action(Service.PRODUCT, Product.SET_STANDBY, Value=standby) |
| 941 |
|
| 942 |
async def async_product_source_count(self) -> Mapping[str, int]: |
| 943 |
"""Return the SourceCount state variable.""" |
| 944 |
return await self._async_call_action(Service.PRODUCT, Product.SOURCE_COUNT) |
| 945 |
|
| 946 |
async def async_product_source(self, index: int) -> Mapping[str, str | bool]: |
| 947 |
"""Get the details of the source at index. |
| 948 |
|
| 949 |
:param index: the source index |
| 950 |
|
| 951 |
:return: SystemName, Type, Name, Visible |
| 952 |
""" |
| 953 |
return await self._async_call_action(Service.PRODUCT, Product.SOURCE, Index=index) |
| 954 |
|
| 955 |
async def async_product_source_index(self) -> Mapping[str, int]: |
| 956 |
"""Get the current source index.""" |
| 957 |
return await self._async_call_action(Service.PRODUCT, Product.SOURCE_INDEX) |
| 958 |
|
| 959 |
async def async_product_source_xml(self) -> Mapping[str, str]: |
| 960 |
"""Get the product source xml.""" |
| 961 |
return await self._async_call_action(Service.PRODUCT, Product.SOURCE_XML) |
| 962 |
|
| 963 |
async def async_product_source_xml_change_count(self) -> Mapping[str, int]: |
| 964 |
"""Get the product source xml change count.""" |
| 965 |
return await self._async_call_action(Service.PRODUCT, Product.SOURCE_XML_CHANGE_COUNT) |
| 966 |
|
| 967 |
async def async_product_standby(self) -> Mapping[str, bool]: |
| 968 |
"""Get the product standby status.""" |
| 969 |
return await self._async_call_action(Service.PRODUCT, Product.STANDBY) |
| 970 |
|
| 971 |
# endregion |
| 972 |
# region Radio Service actions |
| 973 |
async def async_radio_channel(self) -> Mapping[str, str]: |
| 974 |
"""Return the values of the Uri and Metadata state variables for the Radio source.""" |
| 975 |
return await self._async_call_action(Service.RADIO, Radio.CHANNEL) |
| 976 |
|
| 977 |
async def async_radio_pause(self) -> None: |
| 978 |
"""Pause any currently playing radio stream.""" |
| 979 |
await self._async_call_action(Service.RADIO, Radio.PAUSE) |
| 980 |
|
| 981 |
async def async_radio_play(self) -> None: |
| 982 |
"""Play the previously selected stream (set via either SetChannel or SetId).""" |
| 983 |
await self._async_call_action(Service.RADIO, Radio.PLAY) |
| 984 |
|
| 985 |
async def async_radio_set_channel(self, uri: str, metadata: str) -> None: |
| 986 |
"""Set the uri and metadata for a new stream. |
| 987 |
|
| 988 |
uri: uri for channel |
| 989 |
metadata: metadata for radio channel |
| 990 |
must be valid metadata |
| 991 |
""" |
| 992 |
await self._async_call_action(Service.RADIO, Radio.SET_CHANNEL, Uri=uri, Metadata=metadata) |
| 993 |
|
| 994 |
async def async_radio_stop(self) -> None: |
| 995 |
"""Stop any currently playing radio stream.""" |
| 996 |
await self._async_call_action(Service.RADIO, Radio.STOP) |
| 997 |
|
| 998 |
async def async_radio_transport_state(self) -> Mapping[str, str]: |
| 999 |
"""Return the value of the TransportState state variable.""" |
| 1000 |
return await self._async_call_action(Service.RADIO, Radio.TRANSPORT_STATE) |
| 1001 |
|
| 1002 |
async def async_radio_id(self) -> Mapping[str, int]: |
| 1003 |
"""Return the value of the Id state variable.""" |
| 1004 |
return await self._async_call_action(Service.RADIO, Radio.ID) |
| 1005 |
|
| 1006 |
async def async_radio_set_id(self, value: int, uri: str) -> None: |
| 1007 |
"""Set the preset Id and uri for a new stream. |
| 1008 |
|
| 1009 |
:param value: the preset identifier |
| 1010 |
:param uri: the uri of the stream |
| 1011 |
""" |
| 1012 |
await self._async_call_action(Service.RADIO, Radio.SET_ID, Value=value, Uri=uri) |
| 1013 |
|
| 1014 |
async def async_radio_read(self, ident: int) -> Mapping[str, str]: |
| 1015 |
"""Given a channel preset Id, return its associated metadata. |
| 1016 |
|
| 1017 |
:param ident: the preset identifier |
| 1018 |
""" |
| 1019 |
return await self._async_call_action(Service.RADIO, Radio.READ, Id=ident) |
| 1020 |
|
| 1021 |
async def async_radio_read_list(self, idlist: str) -> Mapping[str, str]: |
| 1022 |
"""Return associated metadata for a list of Ids. |
| 1023 |
|
| 1024 |
:param idlist: space separated list of Ids |
| 1025 |
""" |
| 1026 |
return await self._async_call_action(Service.RADIO, Radio.READ_LIST, IdList=idlist) |
| 1027 |
|
| 1028 |
async def async_radio_id_array(self) -> Mapping[str, int | str]: |
| 1029 |
"""Return the value of the IdArray and Token state variables.""" |
| 1030 |
return await self._async_call_action(Service.RADIO, Radio.ID_ARRAY) |
| 1031 |
|
| 1032 |
async def async_radio_id_array_changed(self, token: int) -> Mapping[str, bool]: |
| 1033 |
"""Get the state variables for IdArrayChanged. |
| 1034 |
|
| 1035 |
:param token: value of token |
| 1036 |
""" |
| 1037 |
return await self._async_call_action(Service.RADIO, Radio.ID_ARRAY_CHANGED, Token=token) |
| 1038 |
|
| 1039 |
async def async_radio_channels_max(self) -> Mapping[str, int]: |
| 1040 |
"""Return the value of the ChannelsMax state variable.""" |
| 1041 |
return await self._async_call_action(Service.RADIO, Radio.CHANNELS_MAX) |
| 1042 |
|
| 1043 |
async def async_radio_protocol_info(self) -> Mapping[str, str]: |
| 1044 |
"""Return the value of the ProtocolInfo state variable.""" |
| 1045 |
return await self._async_call_action(Service.RADIO, Radio.PROTOCOL_INFO) |
| 1046 |
|
| 1047 |
async def async_radio_refresh_presets(self) -> None: |
| 1048 |
"""Perform the action RefreshPresets.""" |
| 1049 |
await self._async_call_action(Service.RADIO, Radio.REFRESH_PRESETS) |
| 1050 |
|
| 1051 |
async def async_radio_seek_second_absolute(self, value: int) -> None: |
| 1052 |
"""Seek to an absolute second within the current stream, if permitted. |
| 1053 |
|
| 1054 |
:param value: second to seek |
| 1055 |
""" |
| 1056 |
await self._async_call_action(Service.RADIO, Radio.SEEK_SECOND_ABSOLUTE, Value=value) |
| 1057 |
|
| 1058 |
async def async_radio_seek_second_relative(self, value: int) -> None: |
| 1059 |
"""Seek to a relative second within the current stream, if permitted. |
| 1060 |
|
| 1061 |
:param value: second to seek |
| 1062 |
""" |
| 1063 |
await self._async_call_action(Service.RADIO, Radio.SEEK_SECOND_RELATIVE, Value=value) |
| 1064 |
|
| 1065 |
# endregion |
| 1066 |
# region Receiver Service actions |
| 1067 |
async def async_receiver_play(self) -> None: |
| 1068 |
"""Perform the action Play.""" |
| 1069 |
await self._async_call_action(Service.RECEIVER, Receiver.PLAY) |
| 1070 |
|
| 1071 |
async def async_receiver_stop(self) -> None: |
| 1072 |
"""Perform the action Stop.""" |
| 1073 |
await self._async_call_action(Service.RECEIVER, Receiver.STOP) |
| 1074 |
|
| 1075 |
async def async_receiver_set_sender(self, uri: str, metadata: str) -> None: |
| 1076 |
"""Set the uri and metadata of the sender to listen to. |
| 1077 |
|
| 1078 |
:param uri: uri of the sender |
| 1079 |
:param metadata: metadata of the sender |
| 1080 |
""" |
| 1081 |
await self._async_call_action(Service.RECEIVER, Receiver.SET_SENDER, Uri=uri, Metadata=metadata) |
| 1082 |
|
| 1083 |
async def async_receiver_sender(self) -> Mapping[str, str]: |
| 1084 |
"""Get the state variables for Sender.""" |
| 1085 |
return await self._async_call_action(Service.RECEIVER, Receiver.SENDER) |
| 1086 |
|
| 1087 |
async def async_receiver_protocol_info(self) -> Mapping[str, str]: |
| 1088 |
"""Get the state variables for ProtocolInfo.""" |
| 1089 |
return await self._async_call_action(Service.RECEIVER, Receiver.PROTOCOL_INFO) |
| 1090 |
|
| 1091 |
async def async_receiver_transport_state(self) -> Mapping[str, str]: |
| 1092 |
"""Get the state variables for TransportState.""" |
| 1093 |
return await self._async_call_action(Service.RECEIVER, Receiver.TRANSPORT_STATE) |
| 1094 |
|
| 1095 |
# endregion |
| 1096 |
# region Sender Service actions |
| 1097 |
async def async_sender_presentation_url(self) -> Mapping[str, str]: |
| 1098 |
"""Return the value of the PresentationUrl state variable.""" |
| 1099 |
return await self._async_call_action(Service.SENDER, Sender.PRESENTATION_URL) |
| 1100 |
|
| 1101 |
async def async_sender_metadata(self) -> Mapping[str, str]: |
| 1102 |
"""Return the value of the Metadata state variable.""" |
| 1103 |
return await self._async_call_action(Service.SENDER, Sender.METADATA) |
| 1104 |
|
| 1105 |
async def async_sender_audio(self) -> Mapping[str, bool]: |
| 1106 |
"""Return the value of the Audio state variable.""" |
| 1107 |
return await self._async_call_action(Service.SENDER, Sender.AUDIO) |
| 1108 |
|
| 1109 |
async def async_sender_status(self) -> Mapping[str, str]: |
| 1110 |
"""Return the value of the Status state variable.""" |
| 1111 |
return await self._async_call_action(Service.SENDER, Sender.STATUS) |
| 1112 |
|
| 1113 |
async def async_sender_status2(self) -> Mapping[str, str]: |
| 1114 |
"""Return the value of the Status state variable.""" |
| 1115 |
return await self._async_call_action(Service.SENDER, Sender.STATUS2) |
| 1116 |
|
| 1117 |
async def async_sender_enabled(self) -> Mapping[str, bool]: |
| 1118 |
"""Is the device capable of acting as a Songcast sender.""" |
| 1119 |
return await self._async_call_action(Service.SENDER, Sender.ENABLED) |
| 1120 |
|
| 1121 |
async def async_sender_attributes(self) -> Mapping[str, str]: |
| 1122 |
"""Return the value of the Attributes state variable.""" |
| 1123 |
return await self._async_call_action(Service.SENDER, Sender.ATTRIBUTES) |
| 1124 |
|
| 1125 |
# endregion |
| 1126 |
# region Time Service actions |
| 1127 |
async def async_time(self) -> Mapping[str, int]: |
| 1128 |
"""Report time information about progress through a track. |
| 1129 |
|
| 1130 |
:return: TrackCount, Duration, Seconds |
| 1131 |
""" |
| 1132 |
return await self._async_call_action(Service.TIME, Time.TIME) |
| 1133 |
|
| 1134 |
# endregion |
| 1135 |
# region Transport Service actions |
| 1136 |
async def async_transport_pause(self) -> None: |
| 1137 |
"""Pause the current track or stream.""" |
| 1138 |
await self._async_call_action(Service.TRANSPORT, Transport.PAUSE) |
| 1139 |
|
| 1140 |
async def async_transport_play(self) -> None: |
| 1141 |
"""Play the current track or stream.""" |
| 1142 |
await self._async_call_action(Service.TRANSPORT, Transport.PLAY) |
| 1143 |
|
| 1144 |
async def async_transport_skip_next(self) -> None: |
| 1145 |
"""Move to the next track or stream.""" |
| 1146 |
await self._async_call_action(Service.TRANSPORT, Transport.SKIP_NEXT) |
| 1147 |
|
| 1148 |
async def async_transport_skip_previous(self) -> None: |
| 1149 |
"""Move to the previous track or stream.""" |
| 1150 |
await self._async_call_action(Service.TRANSPORT, Transport.SKIP_PREVIOUS) |
| 1151 |
|
| 1152 |
async def async_transport_state(self) -> Mapping[str, str]: |
| 1153 |
"""Return the current value of the TransportState state variable.""" |
| 1154 |
return await self._async_call_action(Service.TRANSPORT, Transport.TRANSPORT_STATE) |
| 1155 |
|
| 1156 |
async def async_transport_stop(self) -> None: |
| 1157 |
"""Stop the current track or stream.""" |
| 1158 |
await self._async_call_action(Service.TRANSPORT, Transport.STOP) |
| 1159 |
|
| 1160 |
async def async_transport_set_repeat(self, repeat: bool) -> None: |
| 1161 |
"""Set the Repeat state of the device. |
| 1162 |
|
| 1163 |
:param repeat: repeat the current playlist |
| 1164 |
""" |
| 1165 |
await self._async_call_action(Service.TRANSPORT, Transport.SET_REPEAT, Repeat=repeat) |
| 1166 |
|
| 1167 |
async def async_transport_set_shuffle(self, shuffle: bool) -> None: |
| 1168 |
"""Set the Shuffle state of the device. |
| 1169 |
|
| 1170 |
:param shuffle: shuffle the current playlist |
| 1171 |
""" |
| 1172 |
await self._async_call_action(Service.TRANSPORT, Transport.SET_SHUFFLE, Shuffle=shuffle) |
| 1173 |
|
| 1174 |
async def async_transport_seek_second_absolute(self, streamid: int, secondabsolute: int) -> None: |
| 1175 |
"""Seek to an absolute second within the current track or stream, if permitted.""" |
| 1176 |
await self._async_call_action( |
| 1177 |
Service.TRANSPORT, |
| 1178 |
Transport.SEEK_SECOND_ABSOLUTE, |
| 1179 |
StreamId=streamid, |
| 1180 |
SecondAbsolute=secondabsolute, |
| 1181 |
) |
| 1182 |
|
| 1183 |
async def async_transport_seek_second_relative(self, streamid: int, secondrelative: int) -> None: |
| 1184 |
"""Seek to a second relative to the current track or stream position, if permitted.""" |
| 1185 |
await self._async_call_action( |
| 1186 |
Service.TRANSPORT, |
| 1187 |
Transport.SEEK_SECOND_RELATIVE, |
| 1188 |
StreamId=streamid, |
| 1189 |
SecondRelative=secondrelative, |
| 1190 |
) |
| 1191 |
|
| 1192 |
async def async_transport_modes(self) -> Mapping[str, str]: |
| 1193 |
"""Return the value of the Modes state variable.""" |
| 1194 |
return await self._async_call_action(Service.TRANSPORT, Transport.MODES) |
| 1195 |
|
| 1196 |
async def async_transport_mode_info(self) -> Mapping[str, bool]: |
| 1197 |
"""Return the values of the ModeInfo state variables. |
| 1198 |
|
| 1199 |
:return: Mode, CanSkipNext, CanSkipPrev, CanRepeat, CanShuffle |
| 1200 |
""" |
| 1201 |
return await self._async_call_action(Service.TRANSPORT, Transport.MODE_INFO) |
| 1202 |
|
| 1203 |
async def async_transport_stream_info(self) -> Mapping[str, int | bool]: |
| 1204 |
"""Return the values of the StreamInfo state variables. |
| 1205 |
|
| 1206 |
:return: StreamId, Seekable, Pausable |
| 1207 |
""" |
| 1208 |
return await self._async_call_action(Service.TRANSPORT, Transport.STREAM_INFO) |
| 1209 |
|
| 1210 |
async def async_transport_stream_id(self) -> Mapping[str, int]: |
| 1211 |
"""Return the current value of the StreamId state variable. |
| 1212 |
|
| 1213 |
:return: StreamId |
| 1214 |
""" |
| 1215 |
return await self._async_call_action(Service.TRANSPORT, Transport.STREAM_ID) |
| 1216 |
|
| 1217 |
async def async_transport_repeat(self) -> Mapping[str, bool]: |
| 1218 |
"""Return the current value of the Repeat state variable.""" |
| 1219 |
return await self._async_call_action(Service.TRANSPORT, Transport.REPEAT) |
| 1220 |
|
| 1221 |
async def async_transport_shuffle(self) -> Mapping[str, bool]: |
| 1222 |
"""Return the current value of the Shuffle state variable.""" |
| 1223 |
return await self._async_call_action(Service.TRANSPORT, Transport.SHUFFLE) |
| 1224 |
|
| 1225 |
async def async_transport_play_as(self, mode: str, command: str) -> None: |
| 1226 |
"""Start a new stream playing given a mode and command. |
| 1227 |
|
| 1228 |
:param mode: source or group of related sources |
| 1229 |
:param command: mode specific command |
| 1230 |
""" |
| 1231 |
await self._async_call_action(Service.TRANSPORT, Transport.PLAY_AS, Mode=mode, Command=command) |
| 1232 |
|
| 1233 |
# endregion |
| 1234 |
# region Update Service actions |
| 1235 |
async def async_update_apply(self) -> None: |
| 1236 |
"""Apply a software update.""" |
| 1237 |
await self._async_call_action(Service.UPDATE, Update.APPLY) |
| 1238 |
|
| 1239 |
async def async_update_apply2(self) -> None: |
| 1240 |
"""Apply a software update.""" |
| 1241 |
await self._async_call_action(Service.UPDATE, Update.APPLY2) |
| 1242 |
|
| 1243 |
async def async_update_check_now(self) -> Mapping[str, Any]: |
| 1244 |
"""Check the current status of the software.""" |
| 1245 |
return await self._async_call_action(Service.UPDATE, Update.CHECK_NOW) |
| 1246 |
|
| 1247 |
async def async_update_get_software_status(self) -> Mapping[str, str]: |
| 1248 |
"""Return the current status of the software.""" |
| 1249 |
return await self._async_call_action(Service.UPDATE, Update.GET_SOFTWARE_STATUS) |
| 1250 |
|
| 1251 |
# endregion |
| 1252 |
# region Volume Service actions |
| 1253 |
async def async_volume_set(self, volume_level: int) -> None: |
| 1254 |
"""Set the volume level. |
| 1255 |
|
| 1256 |
:param volume_level: the absolute value of the volume |
| 1257 |
""" |
| 1258 |
await self._async_call_action(Service.VOLUME, Volume.SET_VOLUME, Value=volume_level) |
| 1259 |
|
| 1260 |
async def async_volume_set_mute(self, mute: bool) -> None: |
| 1261 |
"""Set the volume mute state. |
| 1262 |
|
| 1263 |
:param mute: the mute status of the volume to set |
| 1264 |
""" |
| 1265 |
# if mute is False then the Volume will be unmuted |
| 1266 |
# unmute only if explicitly boolean False |
| 1267 |
if isinstance(mute, bool): |
| 1268 |
await self._async_call_action(Service.VOLUME, Volume.SET_MUTE, Value=mute) |
| 1269 |
else: |
| 1270 |
raise TypeError("mute must be bool") |
| 1271 |
|
| 1272 |
async def async_volume_inc(self) -> None: |
| 1273 |
"""Increase the volume level by one.""" |
| 1274 |
await self._async_call_action(Service.VOLUME, Volume.VOLUME_INC) |
| 1275 |
|
| 1276 |
async def async_volume_dec(self) -> None: |
| 1277 |
"""Decrease the volume level by one.""" |
| 1278 |
await self._async_call_action(Service.VOLUME, Volume.VOLUME_DEC) |
| 1279 |
|
| 1280 |
# these actions return the values of state variables having been polled |
| 1281 |
async def async_volume(self) -> Mapping[str, int]: |
| 1282 |
"""Return the value of the current volume level.""" |
| 1283 |
return await self._async_call_action(Service.VOLUME, Volume.VOLUME) |
| 1284 |
|
| 1285 |
async def async_volume_mute(self) -> Mapping[str, bool]: |
| 1286 |
"""Return the value of the current volume mute state.""" |
| 1287 |
return await self._async_call_action(Service.VOLUME, Volume.MUTE) |
| 1288 |
|
| 1289 |
async def async_volume_characteristics(self) -> Mapping[str, int]: |
| 1290 |
"""Return the value of the Characteristics state variables. |
| 1291 |
|
| 1292 |
:return: VolumeMax, VolumeUnity, VolumeSteps, VolumeMilliDbPerStep, BalanceMax, FadeMax |
| 1293 |
""" |
| 1294 |
return await self._async_call_action(Service.VOLUME, Volume.CHARACTERISTICS) |
| 1295 |
|
| 1296 |
async def async_volume_set_no_unmute(self, value: int) -> None: |
| 1297 |
"""Set the absolute volume level without un-muting. |
| 1298 |
|
| 1299 |
:param value: the absolute volume level to set |
| 1300 |
""" |
| 1301 |
await self._async_call_action(Service.VOLUME, Volume.SET_VOLUME_NO_UNMUTE, Value=value) |
| 1302 |
|
| 1303 |
async def async_volume_inc_no_unmute(self) -> None: |
| 1304 |
"""Increase the volume level by one without un-muting.""" |
| 1305 |
await self._async_call_action(Service.VOLUME, Volume.VOLUME_INC_NO_UNMUTE) |
| 1306 |
|
| 1307 |
async def async_volume_dec_no_unmute(self) -> None: |
| 1308 |
"""Decrease the volume level by one without un-muting.""" |
| 1309 |
await self._async_call_action(Service.VOLUME, Volume.VOLUME_DEC_NO_UNMUTE) |
| 1310 |
|
| 1311 |
async def async_volume_set_balance(self, value: int) -> None: |
| 1312 |
"""Set the volume left-right balance. |
| 1313 |
|
| 1314 |
:param value: the balance level to set |
| 1315 |
""" |
| 1316 |
await self._async_call_action(Service.VOLUME, Volume.SET_BALANCE, Value=value) |
| 1317 |
|
| 1318 |
async def async_volume_balance_inc(self) -> None: |
| 1319 |
"""Increase the balance level by one.""" |
| 1320 |
await self._async_call_action(Service.VOLUME, Volume.BALANCE_INC) |
| 1321 |
|
| 1322 |
async def async_volume_balance_dec(self) -> None: |
| 1323 |
"""Decrease the balance level by one.""" |
| 1324 |
await self._async_call_action(Service.VOLUME, Volume.BALANCE_DEC) |
| 1325 |
|
| 1326 |
async def async_volume_balance(self) -> Mapping[str, int]: |
| 1327 |
"""Return the value of the Balance state variable.""" |
| 1328 |
return await self._async_call_action(Service.VOLUME, Volume.BALANCE) |
| 1329 |
|
| 1330 |
async def async_volume_set_fade(self, value: int) -> None: |
| 1331 |
"""Set the value of Fade (front-rear) balance. |
| 1332 |
|
| 1333 |
:param value: the Fade value to set |
| 1334 |
""" |
| 1335 |
await self._async_call_action(Service.VOLUME, Volume.SET_FADE, Value=value) |
| 1336 |
|
| 1337 |
async def async_volume_fade_inc(self) -> None: |
| 1338 |
"""Increase the value of Fade (front-rear) balance by one.""" |
| 1339 |
await self._async_call_action(Service.VOLUME, Volume.FADE_INC) |
| 1340 |
|
| 1341 |
async def async_volume_fade_dec(self) -> None: |
| 1342 |
"""Decrease the value of Fade (front-rear) balance by one.""" |
| 1343 |
await self._async_call_action(Service.VOLUME, Volume.FADE_DEC) |
| 1344 |
|
| 1345 |
async def async_volume_fade(self) -> Mapping[str, int]: |
| 1346 |
"""Return the value of the Fade state variable.""" |
| 1347 |
return await self._async_call_action(Service.VOLUME, Volume.FADE) |
| 1348 |
|
| 1349 |
async def async_volume_limit(self) -> Mapping[str, int]: |
| 1350 |
"""Return value of the VolumeLimit state variable.""" |
| 1351 |
return await self._async_call_action(Service.VOLUME, Volume.VOLUME_LIMIT) |
| 1352 |
|
| 1353 |
async def async_volume_unity_gain(self) -> Mapping[str, bool]: |
| 1354 |
"""Return value of the UnityGain state variable.""" |
| 1355 |
return await self._async_call_action(Service.VOLUME, Volume.UNITY_GAIN) |
| 1356 |
|
| 1357 |
async def async_volume_offset(self, channel: str) -> Mapping[str, int]: |
| 1358 |
"""Return value of the VolumeOffset state variable. |
| 1359 |
|
| 1360 |
:param channel: the channel for which to return the volume offset |
| 1361 |
|
| 1362 |
:return: VolumeOffsetBinaryMilliDb |
| 1363 |
""" |
| 1364 |
return await self._async_call_action(Service.VOLUME, Volume.VOLUME_OFFSET, Channel=channel) |
| 1365 |
|
| 1366 |
async def async_volume_set_offset(self, channel: str, volumeoffsetbinarymillidb: int) -> None: |
| 1367 |
"""Set the value of the VolumeOffset state variable. |
| 1368 |
|
| 1369 |
:param channel: the channel for which to set the volume offset |
| 1370 |
:param volumeoffsetbinarymillidb: the volume offset in binary milli decibels (mibi dB) |
| 1371 |
""" |
| 1372 |
await self._async_call_action( |
| 1373 |
Service.VOLUME, |
| 1374 |
Volume.SET_VOLUME_OFFSET, |
| 1375 |
Channel=channel, |
| 1376 |
VolumeOffsetBinaryMilliDb=volumeoffsetbinarymillidb, |
| 1377 |
) |
| 1378 |
|
| 1379 |
async def async_volume_trim(self, channel: str) -> Mapping[str, int]: |
| 1380 |
"""Get the state variables for Trim. |
| 1381 |
|
| 1382 |
:param channel: the device channel to report on |
| 1383 |
""" |
| 1384 |
return await self._async_call_action(Service.VOLUME, Volume.TRIM, Channel=channel) |
| 1385 |
|
| 1386 |
async def async_volume_set_trim(self, channel: str, trimbinarymillidb: int) -> None: |
| 1387 |
"""Trim the Volume of the channel. |
| 1388 |
|
| 1389 |
:param channel: the device channel |
| 1390 |
:param trimbinarymillidb: the trim value in binary milli decibels (MiBi dB) |
| 1391 |
""" |
| 1392 |
await self._async_call_action( |
| 1393 |
Service.VOLUME, |
| 1394 |
Volume.SET_TRIM, |
| 1395 |
Channel=channel, |
| 1396 |
TrimBinaryMilliDb=trimbinarymillidb, |
| 1397 |
) |
| 1398 |
|
| 1399 |
# endregion |
| 1400 |
|
| 1401 |
# region Credentials Service State Variables |
| 1402 |
@property |
| 1403 |
def credentials_ids(self) -> str | None: |
| 1404 |
"""Space separated list of identifiers for services whose credentials can be set.""" |
| 1405 |
return self.get_state_variable_value(Service.CREDENTIALS, CredentialsState.IDS) |
| 1406 |
|
| 1407 |
@property |
| 1408 |
def public_key(self) -> str | None: |
| 1409 |
"""RSA public key. |
| 1410 |
|
| 1411 |
Must be used to encrypt any/all passwords. |
| 1412 |
""" |
| 1413 |
return self.get_state_variable_value(Service.CREDENTIALS, CredentialsState.PUBLIC_KEY) |
| 1414 |
|
| 1415 |
@property |
| 1416 |
def sequence_number(self) -> int | None: |
| 1417 |
"""Sequence number. |
| 1418 |
|
| 1419 |
Increases whenever any aspect of state for any user of credentials listed in Ids changes. |
| 1420 |
""" |
| 1421 |
return self.get_state_variable_value(Service.CREDENTIALS, CredentialsState.SEQUENCE_NUMBER) |
| 1422 |
|
| 1423 |
# endregion |
| 1424 |
# region Info Service State Variables |
| 1425 |
@property |
| 1426 |
def info_track_count(self) -> int | None: |
| 1427 |
"""Return the value of the TrackCount state variable.""" |
| 1428 |
return self.get_state_variable_value(Service.INFO, InfoState.TRACK_COUNT) |
| 1429 |
|
| 1430 |
@property |
| 1431 |
def info_details_count(self) -> int | None: |
| 1432 |
"""Return the value of the DetailsCount state variable.""" |
| 1433 |
return self.get_state_variable_value(Service.INFO, InfoState.DETAILS_COUNT) |
| 1434 |
|
| 1435 |
@property |
| 1436 |
def info_metatext_count(self) -> int | None: |
| 1437 |
"""Return the value of the MetatextCount state variable.""" |
| 1438 |
return self.get_state_variable_value(Service.INFO, InfoState.METATEXT_COUNT) |
| 1439 |
|
| 1440 |
@property |
| 1441 |
def info_uri(self) -> str | None: |
| 1442 |
"""Return the value of the Uri state variable.""" |
| 1443 |
return self.get_state_variable_value(Service.INFO, InfoState.URI) |
| 1444 |
|
| 1445 |
@property |
| 1446 |
def info_metadata(self) -> str | None: |
| 1447 |
"""Return the value of the Metadata state variable.""" |
| 1448 |
return self.get_state_variable_value(Service.INFO, InfoState.METADATA) |
| 1449 |
|
| 1450 |
@property |
| 1451 |
def info_duration(self) -> int | None: |
| 1452 |
"""Return the value of the Duration state variable.""" |
| 1453 |
return self.get_state_variable_value(Service.INFO, InfoState.DURATION) |
| 1454 |
|
| 1455 |
@property |
| 1456 |
def info_bit_rate(self) -> int | None: |
| 1457 |
"""Return the value of the BitRate state variable.""" |
| 1458 |
return self.get_state_variable_value(Service.INFO, InfoState.BIT_RATE) |
| 1459 |
|
| 1460 |
@property |
| 1461 |
def info_bit_depth(self) -> int | None: |
| 1462 |
"""Return the value of the BitDepth state variable.""" |
| 1463 |
return self.get_state_variable_value(Service.INFO, InfoState.BIT_DEPTH) |
| 1464 |
|
| 1465 |
@property |
| 1466 |
def info_sample_rate(self) -> int | None: |
| 1467 |
"""Return the value of the SampleRate state variable.""" |
| 1468 |
return self.get_state_variable_value(Service.INFO, InfoState.SAMPLE_RATE) |
| 1469 |
|
| 1470 |
@property |
| 1471 |
def info_lossless(self) -> bool | None: |
| 1472 |
"""Return the value of the Lossless state variable.""" |
| 1473 |
return self.get_state_variable_value(Service.INFO, InfoState.LOSSLESS) |
| 1474 |
|
| 1475 |
@property |
| 1476 |
def info_codec_name(self) -> str | None: |
| 1477 |
"""Return the value of the CodecName state variable.""" |
| 1478 |
return self.get_state_variable_value(Service.INFO, InfoState.CODEC_NAME) |
| 1479 |
|
| 1480 |
@property |
| 1481 |
def info_metatext(self) -> str | None: |
| 1482 |
"""Return the value of the Metatext state variable.""" |
| 1483 |
return self.get_state_variable_value(Service.INFO, InfoState.METATEXT) |
| 1484 |
|
| 1485 |
# endregion |
| 1486 |
# region Pins Service State Variables |
| 1487 |
@property |
| 1488 |
def pins_device_max(self) -> int | None: |
| 1489 |
"""Return the value of the DeviceMax state variable.""" |
| 1490 |
return self.get_state_variable_value(Service.PINS, PinsState.DEVICE_MAX) |
| 1491 |
|
| 1492 |
@property |
| 1493 |
def pins_account_max(self) -> int | None: |
| 1494 |
"""Return the value of the AccountMax state variable.""" |
| 1495 |
return self.get_state_variable_value(Service.PINS, PinsState.ACCOUNT_MAX) |
| 1496 |
|
| 1497 |
@property |
| 1498 |
def pins_modes(self) -> str | None: |
| 1499 |
"""Return the value of the Modes state variable.""" |
| 1500 |
return self.get_state_variable_value(Service.PINS, PinsState.MODES) |
| 1501 |
|
| 1502 |
@property |
| 1503 |
def pins_id_array(self) -> str | None: |
| 1504 |
"""Return the value of the IdArray state variable.""" |
| 1505 |
return self.get_state_variable_value(Service.PINS, PinsState.ID_ARRAY) |
| 1506 |
|
| 1507 |
@property |
| 1508 |
def pins_cloud_connected(self) -> bool | None: |
| 1509 |
"""Return the value of the CloudConnected state variable.""" |
| 1510 |
return self.get_state_variable_value(Service.PINS, PinsState.CLOUD_CONNECTED) |
| 1511 |
|
| 1512 |
# endregion |
| 1513 |
# region Playlist Service State Variables |
| 1514 |
@property |
| 1515 |
def playlist_transport_state(self) -> str | None: |
| 1516 |
"""Get playlist transport state.""" |
| 1517 |
return self.get_state_variable_value(Service.PLAYLIST, PlaylistState.TRANSPORT_STATE) |
| 1518 |
|
| 1519 |
@property |
| 1520 |
def shuffle(self) -> bool | None: |
| 1521 |
"""Get playlist shuffle state.""" |
| 1522 |
return self.get_state_variable_value(Service.PLAYLIST, PlaylistState.SHUFFLE) |
| 1523 |
|
| 1524 |
@property |
| 1525 |
def repeat(self) -> str | None: |
| 1526 |
"""Get playlist repeat state.""" |
| 1527 |
return self.get_state_variable_value(Service.PLAYLIST, PlaylistState.REPEAT) |
| 1528 |
|
| 1529 |
# endregion |
| 1530 |
# region Product Service State Variables |
| 1531 |
@property |
| 1532 |
def product_room(self) -> str | None: |
| 1533 |
"""Return the room where product is located.""" |
| 1534 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.PRODUCT_ROOM) |
| 1535 |
|
| 1536 |
@property |
| 1537 |
def product_name(self) -> str | None: |
| 1538 |
"""Return the name of the product.""" |
| 1539 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.PRODUCT_NAME) |
| 1540 |
|
| 1541 |
@property |
| 1542 |
def product_manufacturer_name(self) -> str | None: |
| 1543 |
"""Return the value of the ManufacturerName state variable.""" |
| 1544 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.MANUFACTURER_NAME) |
| 1545 |
|
| 1546 |
@property |
| 1547 |
def product_manufacturer_info(self) -> str | None: |
| 1548 |
"""Return the value of the ManufacturerInfo state variable.""" |
| 1549 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.MANUFACTURER_INFO) |
| 1550 |
|
| 1551 |
@property |
| 1552 |
def product_manufacturer_url(self) -> str | None: |
| 1553 |
"""Return the value of the ManufacturerUrl state variable.""" |
| 1554 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.MANUFACTURER_URL) |
| 1555 |
|
| 1556 |
@property |
| 1557 |
def product_manufacturer_image_uri(self) -> str | None: |
| 1558 |
"""Return the value of the ManufacturerImageUri state variable.""" |
| 1559 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.MANUFACTURER_IMAGE_URI) |
| 1560 |
|
| 1561 |
@property |
| 1562 |
def product_model_name(self) -> str | None: |
| 1563 |
"""Return the value of the ModelName state variable.""" |
| 1564 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.MODEL_NAME) |
| 1565 |
|
| 1566 |
@property |
| 1567 |
def product_model_info(self) -> str | None: |
| 1568 |
"""Return the value of the ModelInfo state variable.""" |
| 1569 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.MODEL_INFO) |
| 1570 |
|
| 1571 |
@property |
| 1572 |
def product_model_url(self) -> str | None: |
| 1573 |
"""Return the value of the ModelUrl state variable.""" |
| 1574 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.MODEL_URL) |
| 1575 |
|
| 1576 |
@property |
| 1577 |
def product_model_image_uri(self) -> str | None: |
| 1578 |
"""Return the value of the ModelImageUri state variable.""" |
| 1579 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.MODEL_IMAGE_URI) |
| 1580 |
|
| 1581 |
@property |
| 1582 |
def product_info(self) -> str | None: |
| 1583 |
"""Return the value of the ProductInfo state variable.""" |
| 1584 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.PRODUCT_INFO) |
| 1585 |
|
| 1586 |
@property |
| 1587 |
def product_url(self) -> str | None: |
| 1588 |
"""Return the value of the ProductUrl state variable.""" |
| 1589 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.PRODUCT_URL) |
| 1590 |
|
| 1591 |
@property |
| 1592 |
def product_image_uri(self) -> str | None: |
| 1593 |
"""Return the value of the ProductImageUri state variable.""" |
| 1594 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.PRODUCT_IMAGE_URI) |
| 1595 |
|
| 1596 |
@property |
| 1597 |
def product_image_hires_uri(self) -> str | None: |
| 1598 |
"""Return the value of the ProductImageHiresUri state variable.""" |
| 1599 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.PRODUCT_IMAGE_HIRES_URI) |
| 1600 |
|
| 1601 |
@property |
| 1602 |
def product_standby(self) -> bool | None: |
| 1603 |
"""Return the value of the Standby state variable.""" |
| 1604 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.STANDBY) |
| 1605 |
|
| 1606 |
@property |
| 1607 |
def product_standby_transitioning(self) -> bool | None: |
| 1608 |
"""Return the value of the StandbyTransitioning state variable.""" |
| 1609 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.STANDBY_TRANSITIONING) |
| 1610 |
|
| 1611 |
@property |
| 1612 |
def product_source_index(self) -> int | None: |
| 1613 |
"""Return the value of the SourceIndex state variable.""" |
| 1614 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.SOURCE_INDEX) |
| 1615 |
|
| 1616 |
@property |
| 1617 |
def product_source_count(self) -> int | None: |
| 1618 |
"""Return the value of the SourceCount state variable.""" |
| 1619 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.SOURCE_COUNT) |
| 1620 |
|
| 1621 |
@property |
| 1622 |
def product_source_xml(self) -> str | None: |
| 1623 |
"""Return the value of the SourceXml state variable.""" |
| 1624 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.SOURCE_XML) |
| 1625 |
|
| 1626 |
@property |
| 1627 |
def product_attributes(self) -> str | None: |
| 1628 |
"""Return the value of the Attributes state variable.""" |
| 1629 |
return self.get_state_variable_value(Service.PRODUCT, ProductState.ATTRIBUTES) |
| 1630 |
|
| 1631 |
# endregion |
| 1632 |
# region Radio Service State Variables |
| 1633 |
@property |
| 1634 |
def radio_uri(self) -> str | None: |
| 1635 |
"""Return the value of the Uri state variable.""" |
| 1636 |
return self.get_state_variable_value(Service.RADIO, RadioState.URI) |
| 1637 |
|
| 1638 |
@property |
| 1639 |
def radio_metadata(self) -> str | None: |
| 1640 |
"""Return the value of the Metadata state variable.""" |
| 1641 |
return self.get_state_variable_value(Service.RADIO, RadioState.METADATA) |
| 1642 |
|
| 1643 |
@property |
| 1644 |
def radio_transport_state(self) -> str | None: |
| 1645 |
"""Return the value of the TransportState state variable.""" |
| 1646 |
return self.get_state_variable_value(Service.RADIO, RadioState.TRANSPORT_STATE) |
| 1647 |
|
| 1648 |
@property |
| 1649 |
def radio_id(self) -> int | None: |
| 1650 |
"""Return the value of the Id state variable.""" |
| 1651 |
return self.get_state_variable_value(Service.RADIO, RadioState.ID) |
| 1652 |
|
| 1653 |
@property |
| 1654 |
def radio_id_array(self) -> str | None: |
| 1655 |
"""Return the value of the IdArray state variable.""" |
| 1656 |
return self.get_state_variable_value(Service.RADIO, RadioState.ID_ARRAY) |
| 1657 |
|
| 1658 |
@property |
| 1659 |
def radio_channels_max(self) -> int | None: |
| 1660 |
"""Return the value of the ChannelsMax state variable.""" |
| 1661 |
return self.get_state_variable_value(Service.RADIO, RadioState.CHANNELS_MAX) |
| 1662 |
|
| 1663 |
@property |
| 1664 |
def radio_protocol_info(self) -> str | None: |
| 1665 |
"""Return the value of the ProtocolInfo state variable.""" |
| 1666 |
return self.get_state_variable_value(Service.RADIO, RadioState.PROTOCOL_INFO) |
| 1667 |
|
| 1668 |
# endregion |
| 1669 |
# region Receiver Service State Variables |
| 1670 |
@property |
| 1671 |
def receiver_metadata(self) -> str | None: |
| 1672 |
"""The metadata of the sender to listen to.""" |
| 1673 |
return self.get_state_variable_value(Service.RECEIVER, ReceiverState.METADATA) |
| 1674 |
|
| 1675 |
@property |
| 1676 |
def receiver_uri(self) -> str | None: |
| 1677 |
"""The URI of the sender to listen to.""" |
| 1678 |
return self.get_state_variable_value(Service.RECEIVER, ReceiverState.URI) |
| 1679 |
|
| 1680 |
@property |
| 1681 |
def receiver_protocol_info(self) -> str | None: |
| 1682 |
"""Reports the protocols supported.""" |
| 1683 |
return self.get_state_variable_value(Service.RECEIVER, ReceiverState.PROTOCOL_INFO) |
| 1684 |
|
| 1685 |
@property |
| 1686 |
def receiver_transport_state(self) -> str | None: |
| 1687 |
"""Reports the receiver transport state.""" |
| 1688 |
return self.get_state_variable_value(Service.RECEIVER, ReceiverState.TRANSPORT_STATE) |
| 1689 |
|
| 1690 |
# endregion |
| 1691 |
# region Sender Service State Variables |
| 1692 |
@property |
| 1693 |
def sender_audio(self) -> bool | None: |
| 1694 |
"""Is audio currently available from this Sender.""" |
| 1695 |
return self.get_state_variable_value(Service.SENDER, SenderState.AUDIO) |
| 1696 |
|
| 1697 |
@property |
| 1698 |
def sender_metadata(self) -> str | None: |
| 1699 |
"""Provides basic information about the sender in DIDL-Lite format.""" |
| 1700 |
return self.get_state_variable_value(Service.SENDER, SenderState.METADATA) |
| 1701 |
|
| 1702 |
@property |
| 1703 |
def sender_presentation_url(self) -> str | None: |
| 1704 |
"""Reports the url of a presentation page.""" |
| 1705 |
return self.get_state_variable_value(Service.SENDER, SenderState.PRESENTATION_URL) |
| 1706 |
|
| 1707 |
@property |
| 1708 |
def sender_status2(self) -> str | None: |
| 1709 |
"""Reports the status of the sender.""" |
| 1710 |
return self.get_state_variable_value(Service.SENDER, SenderState.STATUS2) |
| 1711 |
|
| 1712 |
@property |
| 1713 |
def sender_enabled(self) -> bool | None: |
| 1714 |
"""Reports if Songcast sending is enabled.""" |
| 1715 |
return self.get_state_variable_value(Service.SENDER, SenderState.ENABLED) |
| 1716 |
|
| 1717 |
# endregion |
| 1718 |
# region Time Service State Variables |
| 1719 |
@property |
| 1720 |
def track_count(self) -> int | None: |
| 1721 |
"""The number of tracks that have been played.""" |
| 1722 |
return self.get_state_variable_value(Service.TIME, TimeState.TRACK_COUNT) |
| 1723 |
|
| 1724 |
@property |
| 1725 |
def time_duration(self) -> int | None: |
| 1726 |
"""The total length of the current track in seconds.""" |
| 1727 |
return self.get_state_variable_value(Service.TIME, TimeState.DURATION) |
| 1728 |
|
| 1729 |
@property |
| 1730 |
def seconds(self) -> int | None: |
| 1731 |
"""The total length of time in seconds for which the current track has been playing.""" |
| 1732 |
return self.get_state_variable_value(Service.TIME, TimeState.SECONDS) |
| 1733 |
|
| 1734 |
# endregion |
| 1735 |
# region Transport Service State Variables |
| 1736 |
@property |
| 1737 |
def transport_modes(self) -> str | None: |
| 1738 |
"""Return the value of the Modes state variable.""" |
| 1739 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.MODES) |
| 1740 |
|
| 1741 |
@property |
| 1742 |
def transport_can_skip_next(self) -> bool | None: |
| 1743 |
"""Return the value of the CanSkipNext state variable.""" |
| 1744 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.CAN_SKIP_NEXT) |
| 1745 |
|
| 1746 |
@property |
| 1747 |
def transport_can_skip_previous(self) -> bool | None: |
| 1748 |
"""Return the value of the CanSkipPrevious state variable.""" |
| 1749 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.CAN_SKIP_PREVIOUS) |
| 1750 |
|
| 1751 |
@property |
| 1752 |
def transport_can_repeat(self) -> bool | None: |
| 1753 |
"""Return the value of the CanRepeat state variable.""" |
| 1754 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.CAN_REPEAT) |
| 1755 |
|
| 1756 |
@property |
| 1757 |
def transport_can_shuffle(self) -> bool | None: |
| 1758 |
"""Return the value of the CanShuffle state variable.""" |
| 1759 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.CAN_SHUFFLE) |
| 1760 |
|
| 1761 |
@property |
| 1762 |
def transport_stream_id(self) -> int | None: |
| 1763 |
"""Return the value of the StreamId state variable.""" |
| 1764 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.STREAM_ID) |
| 1765 |
|
| 1766 |
@property |
| 1767 |
def transport_can_seek(self) -> bool | None: |
| 1768 |
"""Return the value of the CanSeek state variable.""" |
| 1769 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.CAN_SEEK) |
| 1770 |
|
| 1771 |
@property |
| 1772 |
def transport_can_pause(self) -> bool | None: |
| 1773 |
"""Return the value of the CanPause state variable.""" |
| 1774 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.CAN_PAUSE) |
| 1775 |
|
| 1776 |
@property |
| 1777 |
def transport_state(self) -> str | None: |
| 1778 |
"""Return the value of the TransportState state variable for the active source. |
| 1779 |
|
| 1780 |
Return None if value cannot be determined |
| 1781 |
""" |
| 1782 |
if self.has_transport_state: |
| 1783 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.TRANSPORT_STATE) |
| 1784 |
# transport service transport_state is not available |
| 1785 |
active_source_type = None |
| 1786 |
if self.product_source_xml is not None: |
| 1787 |
try: |
| 1788 |
source_xml = DET.fromstring(self.product_source_xml) |
| 1789 |
active_index = self.product_source_index |
| 1790 |
if active_index is not None: |
| 1791 |
active_source_type = source_xml[active_index].find("Type") |
| 1792 |
if active_source_type is not None: |
| 1793 |
active_source_type = active_source_type.text |
| 1794 |
except DET.ParseError as error: |
| 1795 |
_LOGGER.error("Value is not valid XML - %s", error.msg) |
| 1796 |
|
| 1797 |
match active_source_type: |
| 1798 |
case ProductSourceType.PLAYLIST: |
| 1799 |
return self.playlist_transport_state |
| 1800 |
case ProductSourceType.RADIO: |
| 1801 |
return self.radio_transport_state |
| 1802 |
case ProductSourceType.RECEIVER: |
| 1803 |
return self.receiver_transport_state |
| 1804 |
case _: |
| 1805 |
_LOGGER.warning("Unhandled source type: %s", active_source_type) |
| 1806 |
return None |
| 1807 |
|
| 1808 |
@property |
| 1809 |
def transport_repeat(self) -> bool | None: |
| 1810 |
"""Return the value of the Repeat state variable.""" |
| 1811 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.REPEAT) |
| 1812 |
|
| 1813 |
@property |
| 1814 |
def transport_shuffle(self) -> bool | None: |
| 1815 |
"""Return the value of the Shuffle state variable.""" |
| 1816 |
return self.get_state_variable_value(Service.TRANSPORT, TransportState.SHUFFLE) |
| 1817 |
|
| 1818 |
# endregion |
| 1819 |
# region Update Service State Variables |
| 1820 |
@property |
| 1821 |
def update_software_status(self) -> str | None: |
| 1822 |
"""Return the value of the SoftwareStatus state variable.""" |
| 1823 |
return self.get_state_variable_value(Service.UPDATE, UpdateState.SOFTWARE_STATUS) |
| 1824 |
|
| 1825 |
@property |
| 1826 |
def update_executor_status(self) -> str | None: |
| 1827 |
"""Return the value of the ExecutorStatus state variable.""" |
| 1828 |
return self.get_state_variable_value(Service.UPDATE, UpdateState.EXECUTOR_STATUS) |
| 1829 |
|
| 1830 |
@property |
| 1831 |
def update_job_status(self) -> str | None: |
| 1832 |
"""Return the value of the JobStatus state variable.""" |
| 1833 |
return self.get_state_variable_value(Service.UPDATE, UpdateState.JOB_STATUS) |
| 1834 |
|
| 1835 |
@property |
| 1836 |
def update_recover_supported(self) -> bool | None: |
| 1837 |
"""Return the value of the RecoverSupported state variable.""" |
| 1838 |
return self.get_state_variable_value(Service.UPDATE, UpdateState.RECOVER_SUPPORTED) |
| 1839 |
|
| 1840 |
# endregion |
| 1841 |
# region Volume Service State Variables |
| 1842 |
@property |
| 1843 |
def volume(self) -> int | None: |
| 1844 |
"""Return the Volume level.""" |
| 1845 |
volume_level = self.get_state_variable_value(Service.VOLUME, VolumeState.VOLUME) |
| 1846 |
if not isinstance(volume_level, int): |
| 1847 |
volume_level = None |
| 1848 |
return volume_level |
| 1849 |
|
| 1850 |
@property |
| 1851 |
def is_muted(self) -> bool | None: |
| 1852 |
"""Get mute status.""" |
| 1853 |
return self.get_state_variable_value(Service.VOLUME, VolumeState.MUTE) |
| 1854 |
|
| 1855 |
# endregion |
| 1856 |
|
| 1857 |
# region some has_* functions purely for convenience |
| 1858 |
# use "self._action(<service>, <action>) is not None" for other combinations |
| 1859 |
# alternatively check service and action independently |
| 1860 |
# using <device>.has_service() and <service>.has_action() |
| 1861 |
@property |
| 1862 |
def has_product_set_source_index(self) -> bool: |
| 1863 |
"""Service Product has action SetSourceIndex.""" |
| 1864 |
return self._action(Service.PRODUCT, Product.SET_SOURCE_INDEX) is not None |
| 1865 |
|
| 1866 |
@property |
| 1867 |
def has_product_set_standby(self) -> bool: |
| 1868 |
"""Service Product has action SetStandby.""" |
| 1869 |
return self._action(Service.PRODUCT, Product.SET_STANDBY) is not None |
| 1870 |
|
| 1871 |
@property |
| 1872 |
def has_product_standby(self) -> bool: |
| 1873 |
"""Service Product has action Standby.""" |
| 1874 |
return self._action(Service.PRODUCT, Product.STANDBY) is not None |
| 1875 |
|
| 1876 |
@property |
| 1877 |
def has_transport_play(self) -> bool: |
| 1878 |
"""Service Transport has action Play.""" |
| 1879 |
return self._action(Service.TRANSPORT, Transport.PLAY) is not None |
| 1880 |
|
| 1881 |
@property |
| 1882 |
def has_transport_pause(self) -> bool: |
| 1883 |
"""Service Transport has action Pause.""" |
| 1884 |
return self._action(Service.TRANSPORT, Transport.PAUSE) is not None |
| 1885 |
|
| 1886 |
@property |
| 1887 |
def has_transport_state(self) -> bool: |
| 1888 |
"""Service Transport has action TransportState.""" |
| 1889 |
return self._action(Service.TRANSPORT, Transport.TRANSPORT_STATE) is not None |
| 1890 |
|
| 1891 |
@property |
| 1892 |
def has_transport_stop(self) -> bool: |
| 1893 |
"""Service Transport has action Stop.""" |
| 1894 |
return self._action(Service.TRANSPORT, Transport.STOP) is not None |
| 1895 |
|
| 1896 |
@property |
| 1897 |
def has_transport_skip_next(self) -> bool: |
| 1898 |
"""Service Transport has action SkipNext.""" |
| 1899 |
return self._action(Service.TRANSPORT, Transport.SKIP_NEXT) is not None |
| 1900 |
|
| 1901 |
@property |
| 1902 |
def has_transport_skip_previous(self) -> bool: |
| 1903 |
"""Service Transport has action SkipPrevious.""" |
| 1904 |
return self._action(Service.TRANSPORT, Transport.SKIP_PREVIOUS) is not None |
| 1905 |
|
| 1906 |
@property |
| 1907 |
def has_transport_set_repeat(self) -> bool: |
| 1908 |
"""Service Transport has action SetRepeat.""" |
| 1909 |
return self._action(Service.TRANSPORT, Transport.SET_REPEAT) is not None |
| 1910 |
|
| 1911 |
@property |
| 1912 |
def has_transport_set_shuffle(self) -> bool: |
| 1913 |
"""Service Transport has action SetShuffle.""" |
| 1914 |
return self._action(Service.TRANSPORT, Transport.SET_SHUFFLE) is not None |
| 1915 |
|
| 1916 |
@property |
| 1917 |
def has_transport_seek_second_absolute(self) -> bool: |
| 1918 |
"""Service Transport has action SeekSecondAbsolute.""" |
| 1919 |
return self._action(Service.TRANSPORT, Transport.SEEK_SECOND_ABSOLUTE) is not None |
| 1920 |
|
| 1921 |
@property |
| 1922 |
def has_transport_seek_second_relative(self) -> bool: |
| 1923 |
"""Service Transport has action SeekSecondRelative.""" |
| 1924 |
return self._action(Service.TRANSPORT, Transport.SEEK_SECOND_RELATIVE) is not None |
| 1925 |
|
| 1926 |
@property |
| 1927 |
def has_volume(self) -> bool: |
| 1928 |
"""Service Volume has action Volume.""" |
| 1929 |
return self._action(Service.VOLUME, Volume.VOLUME) is not None |
| 1930 |
|
| 1931 |
@property |
| 1932 |
def has_volume_set(self) -> bool: |
| 1933 |
"""Service Volume has action SetVolume.""" |
| 1934 |
return self._action(Service.VOLUME, Volume.SET_VOLUME) is not None |
| 1935 |
|
| 1936 |
@property |
| 1937 |
def has_volume_set_mute(self) -> bool: |
| 1938 |
"""Service Volume has action SetMute.""" |
| 1939 |
return self._action(Service.VOLUME, Volume.SET_MUTE) is not None |
| 1940 |
|
| 1941 |
@property |
| 1942 |
def has_volume_mute(self) -> bool: |
| 1943 |
"""Service Volume has action Mute.""" |
| 1944 |
return self._action(Service.VOLUME, Volume.MUTE) is not None |
| 1945 |
|
| 1946 |
# endregion |
| 1947 |
|
| 1948 |
# region syntactic helpers |
| 1949 |
async def async_active_source_index(self) -> int | None: |
| 1950 |
"""Get the active source index.""" |
| 1951 |
index = await self.async_product_source_index() |
| 1952 |
if index is not None: |
| 1953 |
return int(index["Value"]) |
| 1954 |
return None |
| 1955 |
|
| 1956 |
async def async_active_source(self) -> Mapping[str, str | bool] | None: |
| 1957 |
"""Get all details of the active source.""" |
| 1958 |
|
| 1959 |
index = await self.async_active_source_index() |
| 1960 |
if index is not None: |
| 1961 |
source = await self.async_product_source(index) |
| 1962 |
else: |
| 1963 |
source = None |
| 1964 |
return source |
| 1965 |
|
| 1966 |
async def async_active_source_name(self) -> str | None: |
| 1967 |
"""Get the name of the active source.""" |
| 1968 |
|
| 1969 |
source_name = None |
| 1970 |
active_source = await self.async_active_source() |
| 1971 |
if active_source is not None: |
| 1972 |
source_name = str(active_source.get("Name")) |
| 1973 |
return source_name |
| 1974 |
|
| 1975 |
async def async_active_source_type(self) -> str | None: |
| 1976 |
"""Get the type of the active source.""" |
| 1977 |
|
| 1978 |
source_type = None |
| 1979 |
active_source = await self.async_active_source() |
| 1980 |
if active_source is not None: |
| 1981 |
source_type = str(active_source.get("Type")) |
| 1982 |
return source_type |
| 1983 |
|
| 1984 |
async def async_visible_sources(self) -> list[dict[str, str | int | None]]: |
| 1985 |
"""Get list of visible sources.""" |
| 1986 |
|
| 1987 |
sources = [] |
| 1988 |
xml = await self.async_product_source_xml() |
| 1989 |
if xml is not None: |
| 1990 |
try: |
| 1991 |
sources_list_xml = DET.fromstring(xml["Value"]) |
| 1992 |
|
| 1993 |
for index, source_xml in enumerate(sources_list_xml): |
| 1994 |
visible = source_xml.findtext("Visible") |
| 1995 |
if visible in ("true", "1"): |
| 1996 |
sources.append( |
| 1997 |
{ |
| 1998 |
"Index": index, |
| 1999 |
"Name": source_xml.findtext("Name"), |
| 2000 |
"Type": source_xml.findtext("Type"), |
| 2001 |
"SystemName": source_xml.findtext("SystemName"), |
| 2002 |
} |
| 2003 |
) |
| 2004 |
except DET.ParseError as error: |
| 2005 |
_LOGGER.error("Value is not valid XML - %s", error.msg) |
| 2006 |
|
| 2007 |
return sources |
| 2008 |
|
| 2009 |
async def async_play(self) -> None: |
| 2010 |
"""Play.""" |
| 2011 |
|
| 2012 |
if self.has_transport_play: |
| 2013 |
await self.async_transport_play() |
| 2014 |
else: |
| 2015 |
active_source_type = await self.async_active_source_type() |
| 2016 |
match active_source_type: |
| 2017 |
case ProductSourceType.RADIO: |
| 2018 |
await self.async_radio_play() |
| 2019 |
case ProductSourceType.PLAYLIST: |
| 2020 |
await self.async_playlist_play() |
| 2021 |
case ProductSourceType.RECEIVER: |
| 2022 |
await self.async_receiver_play() |
| 2023 |
case _: |
| 2024 |
_LOGGER.warning("Unhandled source type: %s", active_source_type) |
| 2025 |
|
| 2026 |
async def async_stop(self) -> None: |
| 2027 |
"""Issue a Stop command. |
| 2028 |
|
| 2029 |
Stop using Transport service if available, otherwise Stop using active source. |
| 2030 |
However, if transport state is currently stopped then do nothing. |
| 2031 |
This is to avoid upnp error: 701 (Transition not available) from some devices e.g. BubbleUpnpServer |
| 2032 |
""" |
| 2033 |
|
| 2034 |
if self.has_transport_stop: |
| 2035 |
# guard against raising error if transition would raise error |
| 2036 |
if self.transport_state != TransportStateAllowedValues.STOPPED: |
| 2037 |
await self.async_transport_stop() |
| 2038 |
else: |
| 2039 |
active_source_type = await self.async_active_source_type() |
| 2040 |
match active_source_type: |
| 2041 |
case ProductSourceType.RADIO: |
| 2042 |
await self.async_radio_stop() |
| 2043 |
case ProductSourceType.PLAYLIST: |
| 2044 |
await self.async_playlist_stop() |
| 2045 |
case ProductSourceType.RECEIVER: |
| 2046 |
await self.async_receiver_stop() |
| 2047 |
case _: |
| 2048 |
_LOGGER.warning("Unhandled source type: %s", active_source_type) |
| 2049 |
|
| 2050 |
async def async_pause(self) -> None: |
| 2051 |
"""Pause.""" |
| 2052 |
|
| 2053 |
if self.has_transport_pause: |
| 2054 |
# guard against raising error if transition would raise error |
| 2055 |
if self.transport_state not in (TransportStateAllowedValues.STOPPED, TransportStateAllowedValues.PAUSED): |
| 2056 |
await self.async_transport_pause() |
| 2057 |
else: |
| 2058 |
active_source_type = await self.async_active_source_type() |
| 2059 |
match active_source_type: |
| 2060 |
case ProductSourceType.RADIO: |
| 2061 |
await self.async_radio_pause() |
| 2062 |
case ProductSourceType.PLAYLIST: |
| 2063 |
await self.async_playlist_pause() |
| 2064 |
case ProductSourceType.RECEIVER: |
| 2065 |
await self.async_receiver_stop() # Receiver does not support pause so just stop |
| 2066 |
case _: |
| 2067 |
_LOGGER.warning("Unhandled source type: %s", active_source_type) |
| 2068 |
|
| 2069 |
def has_source_type(self, product_source_type: ProductSourceType) -> bool | None: |
| 2070 |
"""Return True if profile has source type. |
| 2071 |
|
| 2072 |
None indicates not yet possible to determine source types |
| 2073 |
Test for None before using boolean return value |
| 2074 |
:param product_source_type: the product source type |
| 2075 |
""" |
| 2076 |
if self.product_source_xml is not None: |
| 2077 |
source_type: str = product_source_type.value # py310 |
| 2078 |
try: |
| 2079 |
parsed_xml = DET.fromstring(str(self.product_source_xml)) |
| 2080 |
return len(parsed_xml.findall(f'.//Source[Type="{source_type}"]')) > 0 |
| 2081 |
except DET.ParseError as error: |
| 2082 |
_LOGGER.error("source_xml is not valid XML - %s", error.msg) |
| 2083 |
else: |
| 2084 |
_LOGGER.warning("source_xml is not populated") |
| 2085 |
|
| 2086 |
return None |
| 2087 |
|
| 2088 |
# endregion |
| 2089 |
|
| 2090 |
# region core methods |
| 2091 |
async def _async_call_action(self, service_name: str, action_name: str, **kwargs: Any) -> Mapping[str, Any]: |
| 2092 |
"""Call service action by name with arguments. |
| 2093 |
|
| 2094 |
:param service_name: name of the service |
| 2095 |
:param action_name: name of action to call |
| 2096 |
|
| 2097 |
raise error if service, action or combination is bad |
| 2098 |
""" |
| 2099 |
|
| 2100 |
action = self._action(service_name, action_name) |
| 2101 |
if not action: # isolate cause of failure and raise appropriate error |
| 2102 |
service = self._service(service_name) |
| 2103 |
if service is None: |
| 2104 |
raise UpnpError(f"Bad service {service_name}") |
| 2105 |
raise UpnpError(f"Bad action {action_name} for service {service_name}") |
| 2106 |
|
| 2107 |
result = await action.async_call(**kwargs) |
| 2108 |
return result |
| 2109 |
|
| 2110 |
def get_state_variable_value(self, service_name: str, state_variable_name: str) -> Any | None: |
| 2111 |
"""Return value of state variable. |
| 2112 |
|
| 2113 |
:param service_name: name of the service |
| 2114 |
:param state_variable_name: name of state variable |
| 2115 |
|
| 2116 |
:return: value of state variable or None if either service or state variable not found |
| 2117 |
|
| 2118 |
Note that the corresponding service-action should be polled first, or service subscribed, |
| 2119 |
to assign a value to the variable |
| 2120 |
""" |
| 2121 |
service = self._service(service_name) |
| 2122 |
|
| 2123 |
if service is None: |
| 2124 |
_LOGGER.debug("Missing Service %s", service_name) |
| 2125 |
else: |
| 2126 |
state_var = self._state_variable(service_name, state_variable_name) |
| 2127 |
if state_var is not None: |
| 2128 |
return state_var.value |
| 2129 |
_LOGGER.debug("Missing State Variable %s:%s", service_name, state_variable_name) |
| 2130 |
return None |
| 2131 |
|
| 2132 |
async def async_update_state_variables(self, do_ping: bool = True) -> None: |
| 2133 |
"""Retrieve the latest values for all state variables of interesting services. |
| 2134 |
|
| 2135 |
:param do_ping: Poll device first to check if it is available (online). |
| 2136 |
""" |
| 2137 |
if do_ping: |
| 2138 |
await self.profile_device.async_ping() |
| 2139 |
|
| 2140 |
for service in self.device.all_services: |
| 2141 |
if self._interesting_service(service): |
| 2142 |
svc_identifier = service.service_id.split(":")[-1] |
| 2143 |
actions_with_rsv = self.get_actions_with_state_variables(svc_identifier) |
| 2144 |
await self._async_poll_state_variables(svc_identifier, actions_with_rsv) |
| 2145 |
|
| 2146 |
def get_actions_with_state_variables(self, service_name: str) -> Sequence[str]: |
| 2147 |
"""Create list of actions which have associated related state variables. |
| 2148 |
|
| 2149 |
:param service_name: the name of the service to process |
| 2150 |
|
| 2151 |
:return: list, possibly empty, of actions which have related state variables |
| 2152 |
""" |
| 2153 |
actions = set() |
| 2154 |
service = self._service(service_name) |
| 2155 |
if not service: |
| 2156 |
_LOGGER.debug("Can't find service %s", service_name) |
| 2157 |
else: |
| 2158 |
for action_name in service.actions: |
| 2159 |
action = service.action(action_name) |
| 2160 |
for arg in action.arguments: |
| 2161 |
if arg.direction == "out" and arg.related_state_variable.send_events: |
| 2162 |
actions.add(action_name) |
| 2163 |
# actions that need input parameters will have to be managed by hand |
| 2164 |
for arg in action.arguments: |
| 2165 |
if arg.direction == "in": |
| 2166 |
actions.discard(action_name) |
| 2167 |
return list(actions) |
| 2168 |
|
| 2169 |
# endregion |
| 2170 |
|
| 2171 |
# region miscellaneous functions |
| 2172 |
async def async_playlist_last_id(self) -> int: |
| 2173 |
"""Return the last id of the playlist.""" |
| 2174 |
|
| 2175 |
decoded = [] |
| 2176 |
last_id: int = 0 |
| 2177 |
id_array = await self.async_playlist_id_array() |
| 2178 |
if id_array is not None: |
| 2179 |
id_array_value = id_array.get("Array") |
| 2180 |
if id_array_value is not None: |
| 2181 |
decoded = _decode_id_array(id_array_value) |
| 2182 |
if len(decoded) > 0: |
| 2183 |
last_id = decoded[-1] |
| 2184 |
return last_id |
| 2185 |
|
| 2186 |
async def async_pins_set_device_metadata(self, pin_metadata: dict) -> None: |
| 2187 |
"""Set Pins service device using single metadata dictionary. |
| 2188 |
|
| 2189 |
:param pin_metadata: dictionary containing necessary metadata |
| 2190 |
""" |
| 2191 |
keys = ( |
| 2192 |
"id", |
| 2193 |
"mode", |
| 2194 |
"type", |
| 2195 |
"uri", |
| 2196 |
"title", |
| 2197 |
"description", |
| 2198 |
"artworkUri", |
| 2199 |
"shuffle", |
| 2200 |
) |
| 2201 |
if all(key in pin_metadata for key in keys): |
| 2202 |
await self._async_call_action( |
| 2203 |
Service.PINS, |
| 2204 |
Pins.SET_DEVICE, |
| 2205 |
Index=(pin_metadata["id"]), |
| 2206 |
Mode=pin_metadata["mode"], |
| 2207 |
Type=pin_metadata["type"], |
| 2208 |
Uri=pin_metadata["uri"], |
| 2209 |
Title=pin_metadata["title"], |
| 2210 |
Description=pin_metadata["description"], |
| 2211 |
ArtworkUri=pin_metadata["artworkUri"], |
| 2212 |
Shuffle=pin_metadata["shuffle"], |
| 2213 |
) |
| 2214 |
else: |
| 2215 |
_LOGGER.warning("pin_metadata has invalid key(s): %s", pin_metadata) |
| 2216 |
|
| 2217 |
# endregion |
| 2218 |
|
| 2219 |
|
| 2220 |
# region functions independent of class |
| 2221 |
def id_list_to_string(list_int: list) -> str: |
| 2222 |
"""Convert ID list to space separated string. |
| 2223 |
|
| 2224 |
Invalid IDs (those that are 0 or negative) are discarded. |
| 2225 |
""" |
| 2226 |
return " ".join(map(str, filter(lambda x: x > 0, list_int))) |
| 2227 |
|
| 2228 |
|
| 2229 |
def _decode_id_array(b64_id_array: str) -> list: |
| 2230 |
"""Convert base64 encoded list to list of integers.""" |
| 2231 |
|
| 2232 |
array_int = [] |
| 2233 |
encoded_as_bytes = b64_id_array.encode("utf-8") |
| 2234 |
try: |
| 2235 |
decoded = base64.b64decode(encoded_as_bytes, validate=True) |
| 2236 |
except binascii.Error as exception: |
| 2237 |
raise ValueError("Invalid base64 encoding.") from exception |
| 2238 |
|
| 2239 |
if len(decoded) % 4 == 0: # must be interpretable as 4 byte integers |
| 2240 |
array_int = list(struct.unpack(">" + "I" * (len(decoded) // 4), decoded)) |
| 2241 |
else: |
| 2242 |
_LOGGER.warning("Id array not parsable as 4-byte integers: %s", b64_id_array) |
| 2243 |
|
| 2244 |
return array_int |
| 2245 |
|
| 2246 |
|
| 2247 |
# endregion |