core: Error adding entities for domain binary_sensor with platform pi_hole

The problem

Pi-hole integration no longer creates all entities without errors.

What version of Home Assistant Core has the issue?

2022.12.8

What was the last working version of Home Assistant Core?

2022.12.7

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?

2022-12-27 03:36:50.500 ERROR (MainThread) [homeassistant.components.binary_sensor] Error adding entities for domain binary_sensor with platform pi_hole
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 211, in state
    if (is_on := self.is_on) is None:
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/binary_sensor.py", line 87, in is_on
    return self.entity_description.state_value(self.api)
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/const.py", line 164, in <lambda>
    state_value=lambda api: bool(api.data.get("status") == "enabled"),
AttributeError: 'list' object has no attribute 'get'
2022-12-27 03:36:50.501 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform pi_hole
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 69, in native_value
    return round(self.api.data[self.entity_description.key], 2)
TypeError: list indices must be integers or slices, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 680, in state
    value = self.native_value
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 71, in native_value
    return self.api.data[self.entity_description.key]
TypeError: list indices must be integers or slices, not str
2022-12-27 03:36:50.526 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up pi_hole platform for binary_sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 211, in state
    if (is_on := self.is_on) is None:
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/binary_sensor.py", line 87, in is_on
    return self.entity_description.state_value(self.api)
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/const.py", line 164, in <lambda>
    state_value=lambda api: bool(api.data.get("status") == "enabled"),
AttributeError: 'list' object has no attribute 'get'
2022-12-27 03:36:50.527 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up pi_hole platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 69, in native_value
    return round(self.api.data[self.entity_description.key], 2)
TypeError: list indices must be integers or slices, not str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 680, in state
    value = self.native_value
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 71, in native_value
    return self.api.data[self.entity_description.key]
TypeError: list indices must be integers or slices, not str
2022-12-27 03:36:50.534 ERROR (MainThread) [homeassistant.components.binary_sensor] pi_hole: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 493, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 715, in async_device_update
    await task
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 392, in async_update
    await self.coordinator.async_request_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 175, in async_request_refresh
    await self._debounced_refresh.async_call()
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 82, in async_call
    await task
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 201, in async_refresh
    await self._async_refresh(log_failures=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 316, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 121, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 381, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 211, in state
    if (is_on := self.is_on) is None:
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/binary_sensor.py", line 87, in is_on
    return self.entity_description.state_value(self.api)
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/const.py", line 164, in <lambda>
    state_value=lambda api: bool(api.data.get("status") == "enabled"),
AttributeError: 'list' object has no attribute 'get'

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 8
  • Comments: 21 (2 by maintainers)

Most upvoted comments

Recent change to pihole is breaking an number of integrations (including homeassistant and flutterhole). See this issue: [https://github.com/pi-hole/AdminLTE/pull/2411#issue-1418795310]

Entering the API key still fails to pull statistics. Errors in the logs and shows unavailable on the front end.

2023-01-01 19:27:58.692 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform pi_hole
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 69, in native_value
return round(self.api.data[self.entity_description.key], 2)
TypeError: list indices must be integers or slices, not str
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 680, in state
value = self.native_value
File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 71, in native_value
return self.api.data[self.entity_description.key]
TypeError: list indices must be integers or slices, not str
2023-01-01 19:27:58.697 ERROR (MainThread) [homeassistant.components.switch] Error adding entities for domain switch with platform pi_hole
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 982, in state
if (is_on := self.is_on) is None:
File "/usr/src/homeassistant/homeassistant/components/pi_hole/switch.py", line 76, in is_on
return self.api.data.get("status") == "enabled" # type: ignore[no-any-return]
AttributeError: 'list' object has no attribute 'get'
2023-01-01 19:27:58.706 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up pi_hole platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 69, in native_value
return round(self.api.data[self.entity_description.key], 2)
TypeError: list indices must be integers or slices, not str
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 680, in state
value = self.native_value
File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 71, in native_value
return self.api.data[self.entity_description.key]
TypeError: list indices must be integers or slices, not str
2023-01-01 19:27:58.711 ERROR (MainThread) [homeassistant.components.switch] Error while setting up pi_hole platform for switch
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 982, in state
if (is_on := self.is_on) is None:
File "/usr/src/homeassistant/homeassistant/components/pi_hole/switch.py", line 76, in is_on
return self.api.data.get("status") == "enabled" # type: ignore[no-any-return]
AttributeError: 'list' object has no attribute 'get'
2023-01-01 19:27:58.718 ERROR (MainThread) [homeassistant.components.binary_sensor] pi_hole: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 69, in native_value
return round(self.api.data[self.entity_description.key], 2)
TypeError: list indices must be integers or slices, not str
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 493, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 715, in async_device_update
await task
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 392, in async_update
await self.coordinator.async_request_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 175, in async_request_refresh
await self._debounced_refresh.async_call()
File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 82, in async_call
await task
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 201, in async_refresh
await self._async_refresh(log_failures=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 316, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 121, in async_update_listeners
update_callback()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 381, in _handle_coordinator_update
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 680, in state
value = self.native_value
File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 71, in native_value
return self.api.data[self.entity_description.key]
TypeError: list indices must be integers or slices, not str

Thanks @dsegantx it finally works again using Pi-hole v5.14.2 und Home Assistant 2023.1.0. No need to reboot, just remove the old integration and re-add it using the following settings:

Screenshot-2023-01-05-at-16 56 31 Screenshot-2023-01-05-at-16 56 36

Some great investigative work tying this to pihole changes. I too broke after updating pi-hole. The above link seems to refer to underlying lattice for calling api’s. They seem to be noodling on some key decisions on how to gracefully handle any api provider that goes to enforcing a token.

It seems to me after deleting and reinstalling this integration and finding no spot to enter the api key from my pi-hole that we need to have a place at setup for adding the key. Is this the integration for that?

I believe you can enter the api key if you uncheck statistics only when setting up the integration.

Well I finally got it to work by removing integration, rebooting and attempting to add several times/remove/retry. I tried unchecking the “Check SSL” (last box) but that seemed to avoid asking for key. So removed again, rebooted, and added leaving that last box checked but still having the others unchecked and it is finally working….

Some great investigative work tying this to pihole changes. I too broke after updating pi-hole. The above link seems to refer to underlying lattice for calling api’s. They seem to be noodling on some key decisions on how to gracefully handle any api provider that goes to enforcing a token.

It seems to me after deleting and reinstalling this integration and finding no spot to enter the api key from my pi-hole that we need to have a place at setup for adding the key. Is this the integration for that?