Closed criticallimit closed 1 year ago
@criticallimit Hello, you have to wait because you are using a beta version. If you are an uninformed user, stay on the official versions or help solve the problems. Maybe we should wait for a bit of an answer here? https://github.com/home-assistant/core/pull/95547
Same error received today when upgrading to the official core version 2023.7
Logger: homeassistant.components.sensor Source: custom_components/bodymiscale/entity.py:40 Integration: Sensor (documentation, issues) First occurred: 7:30:58 AM (2 occurrences) Last logged: 7:30:58 AM
Error while setting up bodymiscale platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 353, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/bodymiscale/sensor.py", line 51, in async_setup_entry BodyScaleSensor( File "/config/custom_components/bodymiscale/sensor.py", line 165, in init super().init(handler, entity_description) File "/config/custom_components/bodymiscale/entity.py", line 40, in init if not self.entity_description.name.lower().startswith(name.lower()): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'UndefinedType' object has no attribute 'lower'
Same error on 2023.7:
Logger: homeassistant.components.sensor
Source: custom_components/bodymiscale/entity.py:40
Integration: Сенсор ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 11:21:11 (4 occurrences)
Last logged: 11:21:11
Error while setting up bodymiscale platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 353, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/bodymiscale/sensor.py", line 51, in async_setup_entry
BodyScaleSensor(
File "/config/custom_components/bodymiscale/sensor.py", line 165, in __init__
super().__init__(handler, entity_description)
File "/config/custom_components/bodymiscale/entity.py", line 40, in __init__
if not self.entity_description.name.lower().startswith(name.lower()):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'UndefinedType' object has no attribute 'lower'
@edenhaus Hi I hope you're fine. I need your help on this error. If I delete line 40 (entity.py) no worries but the names are inconsistent "normal". I don't understand their change.
Same 'Unavailable' errors for all entities since upgrade to official 2023.7.0!
I will have a look. HA 2023.7 change something on the nameming
when I exclude lines 38 to 44 in the entity.py everything is working normal in my existing installation, but don´t know the efect for new installations. That´s maybe a workaround for us till the fault is found.
# if self.entity_description.name:
# # Name provided, using the provided one
# if not self.entity_description.name.lower().startswith(name.lower()):
# # Entity name should start with configurated name
# self._attr_name = f"{name} {self.entity_description.name}"
# else:
# self._attr_name = f"{name} {self.entity_description.key.replace('_', ' ')}"
when I exclude lines 38 to 44 in the entity.py everything is working normal in my existing installation, but don´t know the efect for new installations. That´s maybe a workaround for us till the fault is found.
# if self.entity_description.name: # # Name provided, using the provided one # if not self.entity_description.name.lower().startswith(name.lower()): # # Entity name should start with configurated name # self._attr_name = f"{name} {self.entity_description.name}" # else: # self._attr_name = f"{name} {self.entity_description.key.replace('_', ' ')}"
I have tried to exclude those lines, but it has not worked for me, in my case, I have several users.
I hope there will be a solution soon
Somehow the self.entity_description.name
seems to be of type UndefinedType._singleton
. So it's neither None
nor does it provide the string.lower()
function.
These are just observations, I can't derive any meaning from that.
However, I get it to work in a multi user setup with disabling the first bit of the if clause:
# if self.entity_description.name:
if False:
# Name provided, using the provided one
if not self.entity_description.name.lower().startswith(name.lower()):
# Entity name should start with configurated name
self._attr_name = f"{name} {self.entity_description.name}"
else:
self._attr_name = f"{name} {self.entity_description.key.replace('_', ' ')}"
So maybe catching the UndefinedType would help.
Cheers
This solved the problem on my installation:
if self.entity_description.name and isinstance(self.entity_description.name, str):
my complete entity.py:
"""Bodymiscale entity module."""
from typing import Optional
from homeassistant.const import CONF_NAME
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
from .const import DOMAIN, NAME, VERSION
from .metrics import BodyScaleMetricsHandler
class BodyScaleBaseEntity(Entity): # type: ignore[misc]
"""Body scale base entity."""
_attr_should_poll = False
def __init__(
self,
handler: BodyScaleMetricsHandler,
entity_description: Optional[EntityDescription] = None,
):
"""Initialize the entity."""
super().__init__()
self._handler = handler
if entity_description:
self.entity_description = entity_description
elif not hasattr(self, "entity_description"):
raise ValueError(
'"entity_description" must be either set as class variable or passed on init!'
)
if not self.entity_description.key:
raise ValueError('"entity_description.key" must be either set!')
name = handler.config[CONF_NAME]
self._attr_unique_id = "_".join([DOMAIN, name, self.entity_description.key])
if self.entity_description.name and isinstance(self.entity_description.name, str):
# Name provided, using the provided one
if not self.entity_description.name.lower().startswith(name.lower()):
# Entity name should start with configurated name
self._attr_name = f"{name} {self.entity_description.name}"
else:
self._attr_name = f"{name} {self.entity_description.key.replace('_', ' ')}"
@property
def device_info(self) -> Optional[DeviceInfo]:
"""Return device specific attributes."""
return DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
name=NAME,
sw_version=VERSION,
identifiers={(DOMAIN, self._handler.config_entry_id)},
)
PR with fix is ready for testing. For feedback please comment directly in the PR
This is a new error after 2023.7.0 installed: