Custom sensor causes strange malfunctions in HASS core

Hi all – apologies if this isn’t the best place for a code review, but I’d love to get your advice. :slight_smile:

I’ve created a custom sensor that deals with the trash/recycling schedule for my city. From what I can tell, it conforms to the style of other sensors and works well overall, but since I’ve installed it, I’ve noticed several oddities. The most visible is that my garage door cover (a Chamberlain MyQ) doesn’t update its state after being acted upon; when I remove my custom sensor, everything works as expected. So, I’m wondering if my sensor is somehow halting HASS from updating state correctly (of course, the logs don’t show any obvious errors).

Here’s a link to the sensor code; would love any input on a route forward: https://gist.github.com/bachya/ba8f063e188bfda91ae4c7777dc1d148

Feel free to punt me elsewhere if appropriate. Thanks!

Following up – I’ve solved the issue and wanted to post here for some future internet browser to stumble upon.

The problem lay inside pyden, the library I created to gather data for my sensor – specifically, it lay in the fact that pyden used requests-cache to cache response data. Although I couldn’t find anything explicit, a lot of the material I read implied that requests-cache’s in-memory caching isn’t thread safe (which would corroborate what I’m seeing – i.e., the HASS state machine being messed up). Therefore, I altered pyden to use the CacheControl library (which boasts a thread-safe in-memory cache) instead and it works like a charm.