1 """Support for Anthem Network Receivers and Processors."""
3 from __future__
import annotations
7 from anthemav.protocol
import AVR
10 MediaPlayerDeviceClass,
12 MediaPlayerEntityFeature,
21 from .
import AnthemavConfigEntry
22 from .const
import ANTHEMAV_UPDATE_SIGNAL, DOMAIN, MANUFACTURER
24 _LOGGER = logging.getLogger(__name__)
29 config_entry: AnthemavConfigEntry,
30 async_add_entities: AddEntitiesCallback,
33 name = config_entry.title
34 mac_address = config_entry.data[CONF_MAC]
35 model = config_entry.data[CONF_MODEL]
37 avr = config_entry.runtime_data
39 _LOGGER.debug(
"Connection data dump: %s", avr.dump_conndata)
43 avr.protocol, name, mac_address, model, zone_number, config_entry.entry_id
45 for zone_number
in avr.protocol.zones
50 """Entity reading values from Anthem AVR protocol."""
52 _attr_has_entity_name =
True
54 _attr_should_poll =
False
55 _attr_device_class = MediaPlayerDeviceClass.RECEIVER
56 _attr_supported_features = (
57 MediaPlayerEntityFeature.VOLUME_SET
58 | MediaPlayerEntityFeature.VOLUME_MUTE
59 | MediaPlayerEntityFeature.TURN_ON
60 | MediaPlayerEntityFeature.TURN_OFF
61 | MediaPlayerEntityFeature.SELECT_SOURCE
73 """Initialize entity with transport."""
78 self.
_zone_zone = avr.zones[zone_number]
80 unique_id = f
"{mac_address}_{zone_number}"
83 identifiers={(DOMAIN, unique_id)},
84 name=f
"Zone {zone_number}",
85 manufacturer=MANUFACTURER,
87 via_device=(DOMAIN, mac_address),
92 identifiers={(DOMAIN, mac_address)},
94 manufacturer=MANUFACTURER,
100 """When entity is added to hass."""
104 f
"{ANTHEMAV_UPDATE_SIGNAL}_{self._entry_id}",
111 """Update states for the current zone."""
116 """Set all the states from the device to the entity."""
118 MediaPlayerState.ON
if self.
_zone_zone.power
else MediaPlayerState.OFF
128 """Change AVR to the designated source (by name)."""
129 self.
_zone_zone.input_name = source
132 """Turn AVR power off."""
133 self.
_zone_zone.power =
False
136 """Turn AVR power on."""
137 self.
_zone_zone.power =
True
140 """Set AVR volume (0 to 1)."""
141 self.
_zone_zone.volume_as_percentage = volume
144 """Engage AVR mute."""
145 self.
_zone_zone.mute = mute
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)