enkama / hass-variables

Home Assistant variables component
89 stars 12 forks source link

AttributeError: 'VariableNoRecorder' object has no attribute 'disable_recorder' #125

Closed danielbrunt57 closed 1 month ago

danielbrunt57 commented 1 month ago
Logger: homeassistant.components.binary_sensor
Source: helpers/entity_platform.py:364
integration: Binary sensor (documentation, issues)
First occurred: 7:34:02 PM (1 occurrences)
Last logged: 7:34:02 PM

Error while setting up variable platform for binary_sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/variable/binary_sensor.py", line 111, in async_setup_entry
    async_add_entities([VariableNoRecorder(hass, config, config_entry, unique_id)])
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/variable/binary_sensor.py", line 177, in __init__
    self.disable_recorder()
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'VariableNoRecorder' object has no attribute 'disable_recorder'. Did you mean: '_disabled_reported'?

binary_sensor.py Lines 176-177

        if self._exclude_from_recorder:
            self.disable_recorder()

disable_recorder is not defined.

danielbrunt57 commented 1 month ago

The code was there at this point: image

        _LOGGER.debug(f"({self._attr_name}) [init] entity_id: {self.entity_id}")
        if self._exclude_from_recorder:
            self.disable_recorder()

    def disable_recorder(self):
        if RECORDER_INSTANCE in self._hass.data:
            _LOGGER.info(f"({self._attr_name}) [disable_recorder] Disabling Recorder")
            recorder_prefilter.add_filter(self._hass, self.entity_id)

but disappeared here: image

danielbrunt57 commented 1 month ago

I tried adding that definition: image

But a new error is thrown:

Logger: homeassistant.components.binary_sensor
Source: helpers/entity_platform.py:364
integration: Binary sensor (documentation, issues)
First occurred: 7:52:03 PM (1 occurrences)
Last logged: 7:52:03 PM

Error while setting up variable platform for binary_sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/variable/binary_sensor.py", line 111, in async_setup_entry
    async_add_entities([VariableNoRecorder(hass, config, config_entry, unique_id)])
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/variable/binary_sensor.py", line 177, in __init__
    self.disable_recorder()
  File "/config/custom_components/variable/binary_sensor.py", line 180, in disable_recorder
    if RECORDER_INSTANCE in self._hass.data:
       ^^^^^^^^^^^^^^^^^
NameError: name 'RECORDER_INSTANCE' is not defined
danielbrunt57 commented 1 month ago

Thanks! That's the same fix that I decided to try...

        _LOGGER.debug(f"({self._attr_name}) [init] entity_id: {self.entity_id}")
#        if self._exclude_from_recorder:
#            self.disable_recorder()

    async def async_added_to_hass(self):
Snuffy2 commented 1 month ago

Sorry, I missed those 2 lines when I was quickly fixing the issues caused by Variables in HA 2024.7 in #121 .

Assuming you are running Variables v3.4.5: For now, you can just delete lines 176-177 in binary_sensor.py:

        if self._exclude_from_recorder:
            self.disable_recorder()
danielbrunt57 commented 1 month ago

Hey, it happens to the best of us from time to time and fortunately, I know a little python. Thanks again for the quick response!