home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.91k stars 30.13k forks source link

Pi-Hole switches bounce back to enabled after disabling #117052

Open halfordfan opened 4 months ago

halfordfan commented 4 months ago

The problem

I have two Pi-Hole servers integrated with Home Assistant. When I click to disable ad blocking, the switch will turn off but the icon remains lit. The switch will turn itself back on while Pi-Hole is allowing ads. A second click will turn the icon off and the switch will remain off. Pi-Hole is still allowing ads. When I click the switch to enable, the icon will light up and the switch will briefly move to on, then back to off. Pi-Hole has already changed modes to block ads. After a second click, the switch will remain on and the ad blocking is unchanged.

Basically, I have to click the switch twice to get it to reflect proper ad-blocking state, though a single click actually changes the state of ad-blocking on the Pi-Hole.

What version of Home Assistant Core has the issue?

core-2024.4.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Pi-Hole

Link to integration documentation on our website

https://www.home-assistant.io/integrations/pi_hole/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-05-07 20:43:53.552 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:43:53.552 DEBUG (MainThread) [hole] {'status': 'disabled'}
2024-05-07 20:43:53.557 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:43:53.557 DEBUG (MainThread) [hole] {'domains_being_blocked': 549084, 'dns_queries_today': 75405, 'ads_blocked_today': 50434, 'ads_percentage_today': 66.884155, 'unique_domains': 16386, 'queries_forwarded': 19400, 'queries_cached': 2826, 'clients_ever_seen': 2, 'unique_clients': 2, 'dns_queries_all_types': 75405, 'reply_UNKNOWN': 2747, 'reply_NODATA': 11321, 'reply_NXDOMAIN': 1360, 'reply_CNAME': 9509, 'reply_IP': 49649, 'reply_DOMAIN': 0, 'reply_RRNAME': 0, 'reply_SERVFAIL': 599, 'reply_REFUSED': 0, 'reply_NOTIMP': 0, 'reply_OTHER': 0, 'reply_DNSSEC': 5, 'reply_NONE': 0, 'reply_BLOB': 215, 'dns_queries_all_replies': 75405, 'privacy_level': 0, 'status': 'enabled', 'gravity_last_updated': {'file_exists': True, 'absolute': 1714896063, 'relative': {'days': 2, 'hours': 15, 'minutes': 42}}}
2024-05-07 20:43:53.559 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:43:53.559 DEBUG (MainThread) [hole] {'core_update': False, 'web_update': False, 'FTL_update': False, 'core_current': 'v5.18.2', 'web_current': 'v5.21', 'FTL_current': 'v5.25.1', 'core_latest': 'v5.18.2', 'web_latest': 'v5.21', 'FTL_latest': 'v5.25.1', 'core_branch': 'master', 'web_branch': 'master', 'FTL_branch': 'master'}
2024-05-07 20:43:53.559 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole1 data in 0.006 seconds (success: True)
2024-05-07 20:44:58.162 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:44:58.162 DEBUG (MainThread) [hole] {'status': 'disabled'}
2024-05-07 20:44:58.166 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:44:58.166 DEBUG (MainThread) [hole] {'domains_being_blocked': 549084, 'dns_queries_today': 75442, 'ads_blocked_today': 50435, 'ads_percentage_today': 66.852684, 'unique_domains': 16387, 'queries_forwarded': 19433, 'queries_cached': 2828, 'clients_ever_seen': 2, 'unique_clients': 2, 'dns_queries_all_types': 75442, 'reply_UNKNOWN': 2748, 'reply_NODATA': 11326, 'reply_NXDOMAIN': 1360, 'reply_CNAME': 9527, 'reply_IP': 49662, 'reply_DOMAIN': 0, 'reply_RRNAME': 0, 'reply_SERVFAIL': 599, 'reply_REFUSED': 0, 'reply_NOTIMP': 0, 'reply_OTHER': 0, 'reply_DNSSEC': 5, 'reply_NONE': 0, 'reply_BLOB': 215, 'dns_queries_all_replies': 75442, 'privacy_level': 0, 'status': 'disabled', 'gravity_last_updated': {'file_exists': True, 'absolute': 1714896063, 'relative': {'days': 2, 'hours': 15, 'minutes': 43}}}
2024-05-07 20:44:58.168 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:44:58.168 DEBUG (MainThread) [hole] {'core_update': False, 'web_update': False, 'FTL_update': False, 'core_current': 'v5.18.2', 'web_current': 'v5.21', 'FTL_current': 'v5.25.1', 'core_latest': 'v5.18.2', 'web_latest': 'v5.21', 'FTL_latest': 'v5.25.1', 'core_branch': 'master', 'web_branch': 'master', 'FTL_branch': 'master'}
2024-05-07 20:44:58.168 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole1 data in 0.005 seconds (success: True)
2024-05-07 20:46:23.173 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:46:23.174 DEBUG (MainThread) [hole] {'domains_being_blocked': 549084, 'dns_queries_today': 75533, 'ads_blocked_today': 50527, 'ads_percentage_today': 66.893944, 'unique_domains': 16436, 'queries_forwarded': 19476, 'queries_cached': 2829, 'clients_ever_seen': 2, 'unique_clients': 2, 'dns_queries_all_types': 75533, 'reply_UNKNOWN': 2701, 'reply_NODATA': 11449, 'reply_NXDOMAIN': 1339, 'reply_CNAME': 9637, 'reply_IP': 49609, 'reply_DOMAIN': 0, 'reply_RRNAME': 0, 'reply_SERVFAIL': 599, 'reply_REFUSED': 0, 'reply_NOTIMP': 0, 'reply_OTHER': 0, 'reply_DNSSEC': 5, 'reply_NONE': 0, 'reply_BLOB': 194, 'dns_queries_all_replies': 75533, 'privacy_level': 0, 'status': 'enabled', 'gravity_last_updated': {'file_exists': True, 'absolute': 1714892884, 'relative': {'days': 2, 'hours': 16, 'minutes': 38}}}
2024-05-07 20:46:23.176 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:46:23.176 DEBUG (MainThread) [hole] {'core_update': False, 'web_update': False, 'FTL_update': False, 'core_current': 'v5.18.2', 'web_current': 'v5.21', 'FTL_current': 'v5.25.1', 'core_latest': 'v5.18.2', 'web_latest': 'v5.21', 'FTL_latest': 'v5.25.1', 'core_branch': 'master', 'web_branch': 'master', 'FTL_branch': 'master'}
2024-05-07 20:46:23.176 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole2 data in 0.009 seconds (success: True)
2024-05-07 20:47:03.006 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:03.006 DEBUG (MainThread) [hole] {'status': 'enabled'}
2024-05-07 20:47:03.009 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:03.009 DEBUG (MainThread) [hole] {'domains_being_blocked': 549084, 'dns_queries_today': 75560, 'ads_blocked_today': 50465, 'ads_percentage_today': 66.787987, 'unique_domains': 16387, 'queries_forwarded': 19512, 'queries_cached': 2832, 'clients_ever_seen': 2, 'unique_clients': 2, 'dns_queries_all_types': 75560, 'reply_UNKNOWN': 2753, 'reply_NODATA': 11373, 'reply_NXDOMAIN': 1360, 'reply_CNAME': 9566, 'reply_IP': 49686, 'reply_DOMAIN': 0, 'reply_RRNAME': 0, 'reply_SERVFAIL': 599, 'reply_REFUSED': 0, 'reply_NOTIMP': 0, 'reply_OTHER': 0, 'reply_DNSSEC': 5, 'reply_NONE': 0, 'reply_BLOB': 218, 'dns_queries_all_replies': 75560, 'privacy_level': 0, 'status': 'disabled', 'gravity_last_updated': {'file_exists': True, 'absolute': 1714896063, 'relative': {'days': 2, 'hours': 15, 'minutes': 46}}}
2024-05-07 20:47:03.011 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:03.011 DEBUG (MainThread) [hole] {'core_update': False, 'web_update': False, 'FTL_update': False, 'core_current': 'v5.18.2', 'web_current': 'v5.21', 'FTL_current': 'v5.25.1', 'core_latest': 'v5.18.2', 'web_latest': 'v5.21', 'FTL_latest': 'v5.25.1', 'core_branch': 'master', 'web_branch': 'master', 'FTL_branch': 'master'}
2024-05-07 20:47:03.011 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole1 data in 0.005 seconds (success: True)
2024-05-07 20:47:13.883 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:13.883 DEBUG (MainThread) [hole] {'status': 'enabled'}
2024-05-07 20:47:13.887 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:13.887 DEBUG (MainThread) [hole] {'domains_being_blocked': 549084, 'dns_queries_today': 75562, 'ads_blocked_today': 50465, 'ads_percentage_today': 66.786217, 'unique_domains': 16387, 'queries_forwarded': 19513, 'queries_cached': 2832, 'clients_ever_seen': 2, 'unique_clients': 2, 'dns_queries_all_types': 75562, 'reply_UNKNOWN': 2754, 'reply_NODATA': 11374, 'reply_NXDOMAIN': 1360, 'reply_CNAME': 9566, 'reply_IP': 49686, 'reply_DOMAIN': 0, 'reply_RRNAME': 0, 'reply_SERVFAIL': 599, 'reply_REFUSED': 0, 'reply_NOTIMP': 0, 'reply_OTHER': 0, 'reply_DNSSEC': 5, 'reply_NONE': 0, 'reply_BLOB': 218, 'dns_queries_all_replies': 75562, 'privacy_level': 0, 'status': 'enabled', 'gravity_last_updated': {'file_exists': True, 'absolute': 1714896063, 'relative': {'days': 2, 'hours': 15, 'minutes': 46}}}
2024-05-07 20:47:13.889 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:13.889 DEBUG (MainThread) [hole] {'core_update': False, 'web_update': False, 'FTL_update': False, 'core_current': 'v5.18.2', 'web_current': 'v5.21', 'FTL_current': 'v5.25.1', 'core_latest': 'v5.18.2', 'web_latest': 'v5.21', 'FTL_latest': 'v5.25.1', 'core_branch': 'master', 'web_branch': 'master', 'FTL_branch': 'master'}
2024-05-07 20:47:13.889 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole1 data in 0.006 seconds (success: True)
2024-05-07 20:47:22.997 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:22.997 DEBUG (MainThread) [hole] {'status': 'disabled'}
2024-05-07 20:47:23.898 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:23.898 DEBUG (MainThread) [hole] {'domains_being_blocked': 549084, 'dns_queries_today': 75564, 'ads_blocked_today': 50465, 'ads_percentage_today': 66.784447, 'unique_domains': 16387, 'queries_forwarded': 19513, 'queries_cached': 2834, 'clients_ever_seen': 2, 'unique_clients': 2, 'dns_queries_all_types': 75564, 'reply_UNKNOWN': 2754, 'reply_NODATA': 11374, 'reply_NXDOMAIN': 1360, 'reply_CNAME': 9566, 'reply_IP': 49688, 'reply_DOMAIN': 0, 'reply_RRNAME': 0, 'reply_SERVFAIL': 599, 'reply_REFUSED': 0, 'reply_NOTIMP': 0, 'reply_OTHER': 0, 'reply_DNSSEC': 5, 'reply_NONE': 0, 'reply_BLOB': 218, 'dns_queries_all_replies': 75564, 'privacy_level': 0, 'status': 'disabled', 'gravity_last_updated': {'file_exists': True, 'absolute': 1714896063, 'relative': {'days': 2, 'hours': 15, 'minutes': 46}}}
2024-05-07 20:47:23.900 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:23.900 DEBUG (MainThread) [hole] {'core_update': False, 'web_update': False, 'FTL_update': False, 'core_current': 'v5.18.2', 'web_current': 'v5.21', 'FTL_current': 'v5.25.1', 'core_latest': 'v5.18.2', 'web_latest': 'v5.21', 'FTL_latest': 'v5.25.1', 'core_branch': 'master', 'web_branch': 'master', 'FTL_branch': 'master'}
2024-05-07 20:47:23.900 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole1 data in 0.005 seconds (success: True)
2024-05-07 20:47:34.144 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:34.144 DEBUG (MainThread) [hole] {'status': 'enabled'}
2024-05-07 20:47:34.147 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:34.147 DEBUG (MainThread) [hole] {'domains_being_blocked': 549084, 'dns_queries_today': 75564, 'ads_blocked_today': 50465, 'ads_percentage_today': 66.784447, 'unique_domains': 16387, 'queries_forwarded': 19513, 'queries_cached': 2834, 'clients_ever_seen': 2, 'unique_clients': 2, 'dns_queries_all_types': 75564, 'reply_UNKNOWN': 2754, 'reply_NODATA': 11374, 'reply_NXDOMAIN': 1360, 'reply_CNAME': 9566, 'reply_IP': 49688, 'reply_DOMAIN': 0, 'reply_RRNAME': 0, 'reply_SERVFAIL': 599, 'reply_REFUSED': 0, 'reply_NOTIMP': 0, 'reply_OTHER': 0, 'reply_DNSSEC': 5, 'reply_NONE': 0, 'reply_BLOB': 218, 'dns_queries_all_replies': 75564, 'privacy_level': 0, 'status': 'disabled', 'gravity_last_updated': {'file_exists': True, 'absolute': 1714896063, 'relative': {'days': 2, 'hours': 15, 'minutes': 46}}}
2024-05-07 20:47:34.148 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:34.149 DEBUG (MainThread) [hole] {'core_update': False, 'web_update': False, 'FTL_update': False, 'core_current': 'v5.18.2', 'web_current': 'v5.21', 'FTL_current': 'v5.25.1', 'core_latest': 'v5.18.2', 'web_latest': 'v5.21', 'FTL_latest': 'v5.25.1', 'core_branch': 'master', 'web_branch': 'master', 'FTL_branch': 'master'}
2024-05-07 20:47:34.149 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole1 data in 0.005 seconds (success: True)
2024-05-07 20:47:44.021 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:44.022 DEBUG (MainThread) [hole] {'status': 'enabled'}
2024-05-07 20:47:44.154 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:44.154 DEBUG (MainThread) [hole] {'domains_being_blocked': 549084, 'dns_queries_today': 75565, 'ads_blocked_today': 50465, 'ads_percentage_today': 66.783562, 'unique_domains': 16387, 'queries_forwarded': 19514, 'queries_cached': 2834, 'clients_ever_seen': 2, 'unique_clients': 2, 'dns_queries_all_types': 75565, 'reply_UNKNOWN': 2754, 'reply_NODATA': 11375, 'reply_NXDOMAIN': 1360, 'reply_CNAME': 9566, 'reply_IP': 49688, 'reply_DOMAIN': 0, 'reply_RRNAME': 0, 'reply_SERVFAIL': 599, 'reply_REFUSED': 0, 'reply_NOTIMP': 0, 'reply_OTHER': 0, 'reply_DNSSEC': 5, 'reply_NONE': 0, 'reply_BLOB': 218, 'dns_queries_all_replies': 75565, 'privacy_level': 0, 'status': 'enabled', 'gravity_last_updated': {'file_exists': True, 'absolute': 1714896063, 'relative': {'days': 2, 'hours': 15, 'minutes': 46}}}
2024-05-07 20:47:44.156 DEBUG (MainThread) [hole] Response from *hole: 200
2024-05-07 20:47:44.156 DEBUG (MainThread) [hole] {'core_update': False, 'web_update': False, 'FTL_update': False, 'core_current': 'v5.18.2', 'web_current': 'v5.21', 'FTL_current': 'v5.25.1', 'core_latest': 'v5.18.2', 'web_latest': 'v5.21', 'FTL_latest': 'v5.25.1', 'core_branch': 'master', 'web_branch': 'master', 'FTL_branch': 'master'}
2024-05-07 20:47:44.156 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole1 data in 0.005 seconds (success: True)

Additional information

No response

home-assistant[bot] commented 4 months ago

Hey there @shenxn, mind taking a look at this issue as it has been labeled with an integration (pi_hole) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `pi_hole` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign pi_hole` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


pi_hole documentation pi_hole source (message by IssueLinks)

mwolter805 commented 4 months ago

I am having the same issue. HA container version 2024.5.4

mwolter805 commented 4 months ago

Also found that thepi_hole.disable service does not update the ad disable switch. However it does disable ad blocking in Pi-Hole for the duration.

  - service: pi_hole.disable
    data:
      duration: "00:01"
    target:
      device_id: <DEVICE_ID>
Stardust0766 commented 4 months ago

Hi @shenxn, I was able to fix this issue by adding an additional sleep between sending the command to Pi-hole and updating the status. This gives Pi-Hole time to execute the command before we ask for the status again. I am not sure if this is the correct way to fix this, but it seems to work. Below is the modification I have done in async_turn_on() and async_disable():

    async def async_turn_on(self, **kwargs: Any) -> None:
        """Turn on the service."""
        try:
            await self.api.enable()
            await asyncio.sleep(3)
            await self.async_update()
        except HoleError as err:
            _LOGGER.error("Unable to enable Pi-hole: %s", err)

    async def async_turn_off(self, **kwargs: Any) -> None:
        """Turn off the service."""
        await self.async_disable()

    async def async_disable(self, duration: Any = None) -> None:
        """Disable the service for a given duration."""
        duration_seconds = True  # Disable infinitely by default
        if duration is not None:
            duration_seconds = duration.total_seconds()
            _LOGGER.debug(
                "Disabling Pi-hole '%s' (%s) for %d seconds",
                self.name,
                self.api.host,
                duration_seconds,
            )
        try:
            await self.api.disable(duration_seconds)
            await asyncio.sleep(3)
            await self.async_update()
        except HoleError as err:
            _LOGGER.error("Unable to disable Pi-hole: %s", err)
ponG86 commented 4 months ago

I'm also facing the same behavior. Whenever I use the Switch or Service, I find "Unable to disable Pi-hole: Can not load data from *hole" error messages in the logs.

halfordfan commented 4 months ago

Hi @shenxn, I was able to fix this issue by adding an additional sleep between sending the command to Pi-hole and updating the status. This gives Pi-Hole time to execute the command before we ask for the status again. I am not sure if this is the correct way to fix this, but it seems to work. Below is the modification I have done in async_turn_on() and async_disable():

    async def async_turn_on(self, **kwargs: Any) -> None:
        """Turn on the service."""
        try:
            await self.api.enable()
            await asyncio.sleep(3)
            await self.async_update()
        except HoleError as err:
            _LOGGER.error("Unable to enable Pi-hole: %s", err)

    async def async_turn_off(self, **kwargs: Any) -> None:
        """Turn off the service."""
        await self.async_disable()

    async def async_disable(self, duration: Any = None) -> None:
        """Disable the service for a given duration."""
        duration_seconds = True  # Disable infinitely by default
        if duration is not None:
            duration_seconds = duration.total_seconds()
            _LOGGER.debug(
                "Disabling Pi-hole '%s' (%s) for %d seconds",
                self.name,
                self.api.host,
                duration_seconds,
            )
        try:
            await self.api.disable(duration_seconds)
            await asyncio.sleep(3)
            await self.async_update()
        except HoleError as err:
            _LOGGER.error("Unable to disable Pi-hole: %s", err)

@Stardust0766 have you tried some edge cases such as disabling for 1 second, etc. to see what happens? Did you try lower values before arriving at 3 seconds and if so, did they work?

This fix was along the lines I was thinking of trying.

Stardust0766 commented 4 months ago

@halfordfan

  1. Yes, I tried some edge cases and toggeled the switch e.g. multiple times within 3 s. It seems that Homeassistant executes the call to the above methods multiple times in parallel. Thus, 3s after the last call we will get the status updated the last time. This will give us the final status of Pi-Hole and that's probably what we want.
  2. Yes, I started with a 1 s and 2 s sleep time. These did not work reliably on my system. This is the most problematic part of this solution, as the required delay probably depends on the performance of the system running Pi-hole.
halfordfan commented 3 months ago

Thanks for the info on point 1 and totally agree on point 2. I get why they are using await and async calls for UI responsiveness, but there's a need for some blocking in here somewhere. I don't know that I understand the code well enough to attempt that.

Stardust0766 commented 3 months ago

@halfordfan - I don't think that there should be some blocking. I would change the implemention in a way that after sending the command to Pi-hole, the integration polls the status in the background without updating the entities in homeassistant until it receives the expected state. This polling can then be implemented with a timeout, that is much longer than the current 3 s delay and would also work with Pi-hole systems with lower performance.

warmfire540 commented 3 months ago

Also found that thepi_hole.disable service does not update the ad disable switch. However it does disable ad blocking in Pi-Hole for the duration.

  - service: pi_hole.disable
    data:
      duration: "00:01"
    target:
      device_id: <DEVICE_ID>

I'm having this issue. pi_hole.disable does disable the pi-hole, however in HA the status is still reflected as "on" and the switch shows blocking is enabled, contrary to what is in pi-hole.

As a workaround - can I request an update of the current states?

MathisP75 commented 1 month ago

I am still having this issue.

warmfire540 commented 1 month ago

Was this fixed? Today I clicked disable button in HA and my pi hole showed disabled in HA

this is after clicking the disable switch: IMG_5873

MathisP75 commented 1 month ago

@warmfire540 No, it is not fixed.

natefox commented 1 month ago

I've done some digging on my side. This is because the status internal to pihole doesnt get updated fast enough, and HA is grabbing the status too quickly. This is reproducible with a shell script (which pulls every docker container on dockerhub to test)

#!/usr/bin/env bash

## grab all docker tags
docker_tags=$(curl -s https://hub.docker.com/v2/repositories/pihole/pihole/tags | jq -r '.results[].name')

for tag in $docker_tags ; do
    echo $tag
    docker run --rm -d -p 8125:80 -e WEBPASSWORD="" --name "pihole-${tag}" "pihole/pihole:$tag"
    sleep 1 # let pihole start up

    curl -s 'http://localhost:8125/admin/api.php?disable=true&auth=' ; echo  # disable pihole - should respond {"status":"disabled"}
    curl -s 'http://localhost:8125/admin/api.php?summaryRaw=' | jq '.status' # get status. SHOULD respond "disabled" but usually doesnt
    sleep 0.1
    curl -s 'http://localhost:8125/admin/api.php?summaryRaw=' | jq '.status' # get status. Responds "disabled" cause we let it sleep
    docker rm -f "pihole-${tag}" ## cleanup
done

Output will look something like this (annotated):

dev  # echo $tag line
dfecf668108f90ddd8c8cb4a2e454b47e2ddd19f3ca9c7a40e20b3dabff89dbb
{"status":"disabled"} # response from disable=true
"enabled"  # first response of summaryRaw
"disabled" # second response of summaryRaw
pihole-dev

The ideal state is the first response of summaryRaw would match the response from the disabled=true call, but it rarely does. I've toyed with sleep timing, and even 50ms is too fast at times. 100ms is longer than I'd like, but stills seems unperceivable when clicking the gui button in HA.

Ultimately this is a pihole bug, but since older versions need to be supported, its probably not the end of the world to add this. I'll make an MR to the python-hole code shortly.

1onar commented 1 week ago

The integration appears to be malfunctioning.