denonavr 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
denonavr/dirac.py ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ This module implements the Audyssey settings of Denon AVR receivers.
5
+
6
+ :copyright: (c) 2020 by Oliver Goetz.
7
+ :license: MIT, see LICENSE for more details.
8
+ """
9
+
10
+ import logging
11
+ from typing import Optional
12
+
13
+ import attr
14
+
15
+ from .const import (
16
+ DENON_ATTR_SETATTR,
17
+ DIRAC_FILTER_MAP,
18
+ DIRAC_FILTER_MAP_LABELS,
19
+ DiracFilters,
20
+ )
21
+ from .exceptions import AvrCommandError
22
+ from .foundation import DenonAVRFoundation
23
+
24
+ _LOGGER = logging.getLogger(__name__)
25
+
26
+
27
+ @attr.s(auto_attribs=True, on_setattr=DENON_ATTR_SETATTR)
28
+ class DenonAVRDirac(DenonAVRFoundation):
29
+ """Dirac Settings."""
30
+
31
+ _dirac_filter: Optional[str] = attr.ib(
32
+ converter=attr.converters.optional(str), default=None
33
+ )
34
+
35
+ def setup(self) -> None:
36
+ """Ensure that the instance is initialized."""
37
+ self._device.telnet_api.register_callback(
38
+ "PS", self._async_dirac_filter_callback
39
+ )
40
+ self._is_setup = True
41
+
42
+ async def _async_dirac_filter_callback(
43
+ self, zone: str, event: str, parameter: str
44
+ ) -> None:
45
+ """Handle Dirac filter change event."""
46
+ if event == "PS" and parameter[0:5] == "DIRAC":
47
+ self._dirac_filter = DIRAC_FILTER_MAP_LABELS[parameter[6:]]
48
+
49
+ ##############
50
+ # Properties #
51
+ ##############
52
+
53
+ @property
54
+ def dirac_filter(self) -> Optional[str]:
55
+ """
56
+ Returns the current Dirac filter.
57
+
58
+ Only available if using Telnet.
59
+
60
+ Possible values are: "Off", "Slot 1", "Slot 2", "Slot 3"
61
+ """
62
+ return self._dirac_filter
63
+
64
+ ##########
65
+ # Setter #
66
+ ##########
67
+ async def async_dirac_filter(self, dirac_filter: DiracFilters) -> None:
68
+ """Set Dirac filter."""
69
+ if dirac_filter not in DiracFilters:
70
+ raise AvrCommandError("Invalid Dirac filter")
71
+
72
+ mapped_filter = DIRAC_FILTER_MAP[dirac_filter]
73
+ if self._device.telnet_available:
74
+ await self._device.telnet_api.async_send_commands(
75
+ self._device.telnet_commands.command_dirac_filter.format(
76
+ filter=mapped_filter
77
+ )
78
+ )
79
+ return
80
+ await self._device.api.async_get_command(
81
+ self._device.urls.command_dirac_filter.format(filter=mapped_filter)
82
+ )
83
+
84
+
85
+ def dirac_factory(instance: DenonAVRFoundation) -> DenonAVRDirac:
86
+ """Create DenonAVRDirac at receiver instances."""
87
+ # pylint: disable=protected-access
88
+ new = DenonAVRDirac(device=instance._device)
89
+ return new