RogerSelwyn / Home_Assistant_SkyQ_MediaPlayer

Home Assistant SkyQ Media player component
MIT License
105 stars 16 forks source link

[BUG] Device is discoverers every day newly. #151

Closed DarthSonic closed 1 year ago

DarthSonic commented 1 year ago

Describe the bug
I put my Sky Q Receiver to deep standby every night. Every next start the device gets re-discovered by integration. When configuring it says device already configured and dismisses. Configured device is running without problems anyway.

To Reproduce
Steps to reproduce the behavior: I guess it is problem with deep standby.

Expected behavior
No re-duscover after configured device once.

Component versions

  1. What version of SkyQ component are you using?

Latest stable.

Your configuration
UI

Either - Your configuration from the options dialogue
Cannot open it on Android device.

RogerSelwyn commented 1 year ago
  1. What was the last version where the problem was not shown?
RogerSelwyn commented 1 year ago

Or if you go back to v2.10.x does it still happen.?

DarthSonic commented 1 year ago

I did not use any previous version.

RogerSelwyn commented 1 year ago

Should be fixed with this release - https://github.com/RogerSelwyn/Home_Assistant_SkyQ_MediaPlayer/releases/tag/v2.11.1

DarthSonic commented 1 year ago

Unfortunately still the same issue. Screenshot_20230625_152442_Home Assistant Screenshot_20230625_152549_Home Assistant

RogerSelwyn commented 1 year ago

Ok, I may have to give you a custom version with extra debugging. I’ll look at it in a while, maybe tomorrow.

RogerSelwyn commented 1 year ago

How come you have three rediscoveries in one night?

Can you provide the detailed log entries, rather than that summary.

RogerSelwyn commented 1 year ago

Normally deep sleep is from about 2am to 5am. This suggests it is doing it between 00:00 and 13:00. Does it keep discovering during the day?

DarthSonic commented 1 year ago

I put my device in deep standby everytime. I set to Eco Mode. I so not worry about that 3 minute start time each time I start the box.

RogerSelwyn commented 1 year ago

OK

DarthSonic commented 1 year ago

So my device was going to deep standby at night around 00:30 and around 13:00 today.

RogerSelwyn commented 1 year ago

Are you able to look in .storage/core.config_entries for the skyq entry. It should look like this:

      {
        "entry_id": "85e60b553c7e9acab917f6df8804aae0",
        "version": 2,
        "domain": "skyq",
        "title": "Sky Q",
        "data": {
          "host": "192.168.1.199",
          "name": "Sky Q"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "GBR06270869999",
        "disabled_by": null
      }

Can you post here.

RogerSelwyn commented 1 year ago

I think you may need to swap lines 108/109 in config_flow.py so they look like this:

        self._async_abort_entries_match({CONF_HOST: host})
        self._abort_if_unique_id_configured()
RogerSelwyn commented 1 year ago

I suspect it is a race condition where the box is announcing itself via SSDP before it is ready to be connected to. Ignore last post, change _async_setuniqueid to look like the below in config_flow.py.

    async def _async_setuniqueid(self, host):
        self._async_abort_entries_match({CONF_HOST: host})
        remote = await self.hass.async_add_executor_job(SkyQRemote, host)
        if not remote.device_setup:
            raise CannotConnect()

        if remote.device_type in UNSUPPORTED_DEVICES:
            _LOGGER.warning(
                "W0010 - Device type - %s - is not supported", remote.device_type
            )

        device_info = await self.hass.async_add_executor_job(
            remote.get_device_information
        )

        await self.async_set_unique_id(
            device_info.countryCode
            + "".join(e for e in device_info.serialNumber.casefold() if e.isalnum())
        )

        self._abort_if_unique_id_configured()
DarthSonic commented 1 year ago

Are you able to look in .storage/core.config_entries for the skyq entry. It should look like this:

      {
        "entry_id": "85e60b553c7e9acab917f6df8804aae0",
        "version": 2,
        "domain": "skyq",
        "title": "Sky Q",
        "data": {
          "host": "192.168.1.199",
          "name": "Sky Q"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "GBR06270869999",
        "disabled_by": null
      }

Can you post here.

Looks like this:

      {
        "entry_id": "9d4de0a76e5c6834825e5f43221bbd86",
        "version": 2,
        "domain": "skyq",
        "title": "Sky Q",
        "data": {
          "host": "192.168.178.24",
          "name": "Sky Q"
        },
        "options": {
          "output_programme_image": false,
          "live_tv": true,
          "get_live_record": false,
          "generate_switches_for_channels": true,
          "room": "Wohnzimmer",
          "advanced_options": true,
          "channel_sources": [
            "Das Erste HD",
            "ZDF HD",
            "RTL HD",
            "SAT.1 HD",
            "ProSieben HD",
            "VOX HD",
            "RTLZWEI HD",
            "kabel eins HD",
            "SIXX HD",
            "SAT.1 Gold HD",
            "Pro7 MAXX HD",
            "NITRO HD",
            "Sky Sport Bundesliga HD",
            "Sky Sport F1 HD",
            "SPORT1 HD",
            "Sky Cinema Premieren HD",
            "Sky Cinema Best Of HD",
            "Sky Cinema Thriller HD",
            "Sky Cinema Action HD",
            "Sky Cinema Family HD",
            "Sky Cinema Fun HD",
            "Sky Cinema Classics HD",
            "Sky Cinema Special HD",
            "Warner TV Film HD",
            "Deluxe Music HD",
            "Deluxe Dance by Kontor",
            "Deluxe Rock",
            "Deluxe Rap",
            "Deluxe Flashback"
          ],
          "tv_device_class": false,
          "country": "DEU",
          "epg_cache_len": 20
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "ssdp",
        "unique_id": "DEU21151027307076",
        "disabled_by": null
      }
DarthSonic commented 1 year ago
    async def _async_setuniqueid(self, host):
        self._async_abort_entries_match({CONF_HOST: host})
        remote = await self.hass.async_add_executor_job(SkyQRemote, host)
        if not remote.device_setup:
            raise CannotConnect()

        if remote.device_type in UNSUPPORTED_DEVICES:
            _LOGGER.warning(
                "W0010 - Device type - %s - is not supported", remote.device_type
            )

        device_info = await self.hass.async_add_executor_job(
            remote.get_device_information
        )

        await self.async_set_unique_id(
            device_info.countryCode
            + "".join(e for e in device_info.serialNumber.casefold() if e.isalnum())
        )

        self._abort_if_unique_id_configured()

Changed that. Will report tomorrow if issue still exists.

DarthSonic commented 1 year ago

It is working with the change to _async_setuniqueid

RogerSelwyn commented 1 year ago

Good. I had the same rediscovery last night, but I hadn’t spilled that change. I’ll do a new version tomorrow.

DarthSonic commented 1 year ago

And to be able to power on the Sky Q box still using media player card, I use this automation:

alias: Sky Q Power On
description: ""
trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: media_player
      service: turn_on
      service_data:
        device_id:
          - 48af9acf47ace8a3ba3c0cfe9dd0c5b0
    alias: When Sky Q is turned on
condition:
  - condition: or
    conditions:
      - condition: device
        device_id: 48af9acf47ace8a3ba3c0cfe9dd0c5b0
        domain: media_player
        entity_id: media_player.sky_q
        type: is_off
      - condition: state
        entity_id: media_player.sky_q
        state: unavailable
action:
  - service: script.skyq_toggle
    data: {}
mode: single

What you need is a script "script.skyq_toggle" that is doing the power toggle. For me it is a broadlink ir device.

Maybe some example for your documentation when others want to use deep standby / Eco Mode.

DarthSonic commented 1 year ago

P. S. would have loved to "buy you a beer" but it does not accept my credit card. 🙁

RogerSelwyn commented 1 year ago

😀 no worries

RogerSelwyn commented 1 year ago

Closed with v2.11.2