Beispiel #1
0
class HassPlayer(Player):
    """Generic/base Mapping from Home Assistant Mediaplayer to Music Assistant Player."""

    use_mute_as_power: bool = False

    def __init__(self, hass: HomeAssistant, entity_id: str) -> None:
        """Initialize player."""
        self.hass = hass
        self.logger = LOGGER.getChild(entity_id)
        # use the (source) entity_id as player_id for now, to be improved later with unique_id ?
        self.player_id = entity_id
        self.entity_id = entity_id

        # grab a reference to the underlying entity
        # we perform all logic directly on the entity instance and bypass the state machine
        entity_comp = hass.data.get(DATA_INSTANCES, {}).get(MP_DOMAIN)
        self.entity: MediaPlayerEntity = entity_comp.get_entity(entity_id)

        manufacturer = "Home Assistant"
        model = entity_id
        if reg_entry := self.entity.registry_entry:
            # grab device entry
            if reg_entry.device_id:
                dev_reg = dr.async_get(hass)
                device = dev_reg.async_get(reg_entry.device_id)
                manufacturer = device.manufacturer
                model = device.model
        self._attr_device_info = DeviceInfo(manufacturer=manufacturer,
                                            model=model)
        self._attr_powered = False
        self._attr_current_url = ""
        self._attr_elapsed_time = 0
        self.update_attributes()
Beispiel #2
0
 def device_info(self) -> DeviceInfo:
     """Return deviceinfo."""
     return DeviceInfo(
         model=self._cast_info.model_name,
         address=f"{self._cast_info.host}:{self._cast_info.port}",
         manufacturer=self._cast_info.manufacturer,
     )
Beispiel #3
0
    def __device_discovered(self, soco_device: soco.SoCo):
        """Handle discovered Sonos player."""
        speaker_info = soco_device.get_speaker_info(True)
        player = Player(
            player_id=soco_device.uid,
            provider_id=PROV_ID,
            name=soco_device.player_name,
            features=PLAYER_FEATURES,
            config_entries=PLAYER_CONFIG_ENTRIES,
            device_info=DeviceInfo(
                model=speaker_info["model_name"],
                address=speaker_info["mac_address"],
                manufacturer=PROV_NAME,
            ),
        )
        # store soco object on player
        player.soco = soco_device
        player.media_position_updated_at = 0
        # handle subscriptions to events
        player.subscriptions = []

        def subscribe(service, _callback):
            queue = ProcessSonosEventQueue(soco_device.uid, _callback)
            sub = service.subscribe(auto_renew=True, event_queue=queue)
            player.subscriptions.append(sub)

        subscribe(soco_device.avTransport, self.__player_event)
        subscribe(soco_device.renderingControl, self.__player_event)
        subscribe(soco_device.zoneGroupTopology, self.__topology_changed)
        self.mass.run_task(self.mass.players.add_player(player))
        return player
Beispiel #4
0
 def __init__(self, mass: MusicAssistant, player_id: str, player_name: str):
     """Initialize the wsplayer."""
     self._player_id = player_id
     self._player_name = player_name
     self._powered = True
     self._elapsed_time = 0
     self._state = PlaybackState.Stopped
     self._current_uri = ""
     self._volume_level = 100
     self._muted = False
     self._device_info = DeviceInfo()
     self.last_message = time.time()
Beispiel #5
0
 def __init__(self, *args, **kwargs) -> None:
     """Initialize player."""
     self._attr_device_info = DeviceInfo(manufacturer="Home Assistant",
                                         model="Media Player Group")
     super().__init__(*args, **kwargs)
Beispiel #6
0
 def device_info(self) -> DeviceInfo:
     """Return deviceinfo."""
     return DeviceInfo(
         model="Group Player",
         manufacturer=PROV_ID,
     )
Beispiel #7
0
 def device_info(self) -> DeviceInfo:
     """Return the device info for this player."""
     return DeviceInfo(
         model=self.socket_client.device_type,
         address=self.socket_client.device_address,
     )