petro-kushchak / homebridge-homepod-radio

MIT License
39 stars 2 forks source link

Enhancement: specify HomePod by name in config #53

Open justjam2013 opened 2 months ago

justjam2013 commented 2 months ago

Installed version of homebridge-homepod-radio: v3.0.0 - latest

This is a suggested enhancement to specify the HomePod by name instead of by id in the plugin config. As a side effect, it will fiix the issue with the mac addresses changing in iOS 18.

In bin/stream.py replace:

    atvs = await pyatv.scan(self.loop, identifier=self.atv_identifier, timeout=5)

    if not atvs:
        self.logger.error("* No Device found")
        return False

    conf = atvs[0]

with a scan by protocol:

    from pyatv.const import Protocol

    ...
    atvs = await pyatv.scan(self.loop, protocol=Protocol.AirPlay, timeout=5)

    atvs[:] = [atv for atv in atvs if atv.name == self.homepod_name]
    if not atvs:
        self.logger.error("* No Device found")
        return False

    conf = atvs[0]
justjam2013 commented 2 months ago

Using the HomePod name instead of the id, would create volume buttons with human readable names instead of using the id string.

Screenshot 2024-09-30 at 1 40 44 AM
justjam2013 commented 1 month ago

Update: I think that the average end user would be more comfortable with a device name, rather than trying to find a MAC address. And to retrieve the device's MAC, they still have to know the device's name. So actually, the plugin could do the intermediate step for the user. Here's my thought. It is a little bit more work, but it is a one-time code change and it fixes the issue of MAC address or name changes.

  1. The user configures the plugin by entering the name of the device, for example "Living room Apple TV".
  2. When starting up, if the plugin does not find an identifier available, so it performs a scan by protocol and matches the device using "Living room Apple TV". This is what the user currently does by hand.
  3. The plugin then retrieves and stores the MAC address. From then on, it uses the MAC address to connect to the device.
  4. If at any point the plugin fails to connect to the device by MAC address, it falls back to step (2) and repeats the process. This obviously assumes that the device name hasn't changed, so ...
  5. Whenever the plugin runs, it retrieves the device name and updates the config (not sure if this is possible, but it would be nice), to keep the name up to date.

The chances that the device's name and MAC both change at the same time are extremely small. So in the event of one of the properties changing, the plugin quickly recovers and update its info. Not only does this make the plugin more resilient, but it also removes the additional step on setup or if/when MAC address changes occur.

petro-kushchak commented 1 month ago

Hi, @justjam2013 - agree, this would be also on my todo list along with multi file support feature

justjam2013 commented 1 month ago

FYI, I have created an enhancement ticket asking to include pyatv in the docker image for Homebridge here. Together with being able to specify the homepod name in the config, it will make installing this plugin straightforward, at least in a Docker container.