gcobb321 / recorder_history_prefilter

Custom component to filter entities from the HA Recorder History database. (HA v2023.06+)
MIT License
2 stars 1 forks source link

recorder_prefilter.py: recorder_entity_filter(entity_id): TypeError: 'NoneType' object is not callable #3

Open Snuffy2 opened 1 month ago

Snuffy2 commented 1 month ago

Just adding this here for tracking: https://github.com/gcobb321/icloud3/issues/349 https://github.com/enkama/hass-variables/issues/120

2024-07-03 13:47:04.948 ERROR (MainThread) [homeassistant.core] Error running job: <Job listen * HassJobType.Callback <function Recorder.async_initialize.._event_listener at 0x7fc27ff76480>>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/core.py", line 1559, in async_fire_internal
self._hass.async_run_hass_job(job, event)
File "/usr/src/homeassistant/homeassistant/core.py", line 938, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 330, in _event_listener
if entity_filter(entity_id):
^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/icloud3/support/recorder_prefilter.py", line 123, in entity_filter
return recorder_entity_filter(entity_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not callable

Likely from changes made as part of this: https://developers.home-assistant.io/blog/2024/06/22/excluding-state-attributes-from-recording-match-all/ https://developers.home-assistant.io/docs/core/entity/#excluding-state-attributes-from-recorder-history

Snuffy2 commented 1 month ago

https://github.com/home-assistant/core/issues/121218

Snuffy2 commented 1 month ago

Architecture Discussion: https://github.com/home-assistant/architecture/discussions/1106

Snuffy2 commented 1 month ago

FYI, for places and hass-variables, I've implemented a kinda klunky workaround by having a child class that inherits from my main entity class that sets _unrecorded_attributes = frozenset({MATCH_ALL}) as a class attribute. Then in async_setup_entry calling async_add_entities for the normal vs the no-recorder class.

So I'm not using recorder_history_prefilter at all at least for now. From the architecture discussion, it sounds like they're at least considering the ability to disable a recorder by entity. Fingers crossed.

https://github.com/custom-components/places/pull/290 https://github.com/enkama/hass-variables/pull/121

gcobb321 commented 1 month ago

I sent bbdraco a msg about the reasons being the prefilter and received a note about joining a discussion on discord. See here. Also another link here

gcobb321 commented 1 month ago

I am home from Switzerland and have fixed the iCloud3 recorder-history issue. I had several hardware issues to fix before I could get into it. I turned on my computer and saw smoke coming from inside it's case. It turned out that the video card was fried, probably from some electrical storms and power outages we had while I was away. My Rpi was also fried and failed to boot. Fortunately, I had an older one with 2Gb of memory that was sitting in a closet. I am now using that while I wait for Amazon to bring me a new 8Gb model.

In any case, you will find iCloud3 v3.0.5.5 below. Can you unzip it into the icloud3 directory and restart. Everything should now work as expected. I'll issue a new release if everything is OK.

I found that the _unrecorded_attributes = frozenset({MATCH_ALL}) was not working. All of the sensor attributes were still being added to the HA recorder history database. I have the sensor Classes structured in a way to have a class for distance, time, text, info, battery, etc. sensors that generate the attributes associated with a parent class for the general updating for the Sensor Entity.

Class DeviceSensor_Base(SensorEntity):
   def __init__(---):
   --- lots of code ---

Class Sensor_Timer(DeviceSensor_Base):
   _unrecorded_attributes = frozenset({MATCH_ALL})

    def attribute_code():
      --- code for attributes

That was not working. Nothing was being excluded. I changed the structure to:

Class DeviceSensor_Base():
   def __init__(---):
   --- lots of code ---

Class Sensor_Timer(DeviceSensor_Base, SensorEntity):
   _unrecorded_attributes = frozenset({MATCH_ALL})

   def attribute_code():
      --- code for attributes

That also did not work. What got everything running was specifying the attributes to be excluded for each type of sensor instead of using the MATCH_ALL.

_unrecorded_attributes = frozenset(['integration', 'sensor_updated', 'icon', 'friendly_name', 'last_located',...])

This may have been caused by various timer type sensors with different attributes that all use the 'Sensor_Timer' class and the class attribute was turning into an instance attribute. I don't know but wanted to give you a heads up on what I ran into.

The places-attrs-ha-history.txt file is the entry in the home-assistant_v2.db history database showing the places attributes when the extended attributes is enabled and disabled. It seemed like a lot of attributes and I'm not sure if the ones that should be excluded are really being excluded. I'm using SQLite Expert Personal to display the ha database (sensor_attributes table).

icloud3 v3.0.5.5.zip places-attrs-in-ha-recorder.txt

Snuffy2 commented 1 month ago

Wow! I hope your trip was amazing though. Seems like your tech missed you and revolted (both software and hardware) in response.

It's really weird that specifying SensorEntity in your base class doesn't work but doing it in the inherited child class does. Not sure why that would be. Might be worth a question to HA, but not if you think it will derail the architecture discussion for a better fix in process.

I loaded v3.0.5.5 and everything seems to be ok. However, a number of caveats from my end:

Regarding MATCH_ALL in places: