bruxy70 / Garbage-Collection

🗑 Custom Home Assistant sensor for scheduling garbage collection (or other regularly re-occurring events - weekly on given days, semi-weekly or monthly)
MIT License
383 stars 90 forks source link

Garbage collection schedule ignores first & last month #442

Closed msimecek closed 1 year ago

msimecek commented 1 year ago

Before you submit a new bug report, please check that

Describe the bug

When recently changing my weekly garbage collection frequency from March-October to February-November I noticed that the date range is ignored and garbage collection is scheduled in December and January too.

I tried with a new entity and the behavior is the same.

Configuration: image

Result in calendar: image

Configuration

Downloading diagnostics for this new entity doesn't work. Getting 500 error from HA.

Here's diagnostics of the updated entity (same config, same behavior):

{
  "home_assistant": {
    "installation_type": "Home Assistant Supervised",
    "version": "2022.12.0",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.7",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Prague",
    "os_name": "Linux",
    "os_version": "5.10.0-19-amd64",
    "supervisor": "2022.11.2",
    "host_os": "Debian GNU/Linux 11 (bullseye)",
    "docker_version": "20.10.21",
    "chassis": "desktop",
    "run_as_root": true
  },
  "custom_components": {
    "garbage_collection": {
      "version": "4.10.0",
      "requirements": [
        "python-dateutil>=2.8.2"
      ]
    },
    "hacs": {
      "version": "1.28.4",
      "requirements": [
        "aiogithubapi>=22.2.4"
      ]
    },
    "sonoff": {
      "version": "3.3.1",
      "requirements": [
        "pycryptodome>=3.6.6"
      ]
    }
  },
  "integration_manifest": {
    "domain": "garbage_collection",
    "name": "Garbage Collection",
    "version": "4.10.0",
    "documentation": "https://github.com/bruxy70/Garbage-Collection/",
    "issue_tracker": "https://github.com/bruxy70/Garbage-Collection/issues",
    "iot_class": "calculated",
    "integration_type": "helper",
    "dependencies": [],
    "config_flow": true,
    "codeowners": [
      "@bruxy70"
    ],
    "requirements": [
      "python-dateutil>=2.8.2"
    ],
    "is_built_in": false
  },
  "data": {
    "entity_id": "sensor.bio_odpad_leto",
    "state": 2,
    "attributes": {
      "days": 5,
      "last_collection": null,
      "last_updated": "2022-12-08T10:01:05.748210+01:00",
      "next_date": "2022-12-13T00:00:00+01:00",
      "device_class": "garbage_collection__schedule"
    },
    "config_entry": {
      "entry_id": "b79eeaf21da800fa2102896792e0515c",
      "version": 6,
      "domain": "garbage_collection",
      "title": "Bio odpad - l\u00e9to",
      "data": {
        "unique_id": "80920e3e-87bd-4295-b8d9-32c50a40afb7"
      },
      "options": {
        "frequency": "weekly",
        "icon_normal": "mdi:leaf",
        "icon_today": "mdi:delete-restore",
        "icon_tomorrow": "mdi:delete-circle",
        "first_month": "feb",
        "last_month": "nov",
        "collection_days": [
          "tue"
        ],
        "verbose_format": "on {date}, in {days} days",
        "date_format": "%d-%b-%Y",
        "verbose_state": false,
        "hidden": false,
        "manual_update": false,
        "expire_after": "00:00:00"
      },
      "pref_disable_new_entities": false,
      "pref_disable_polling": false,
      "source": "user",
      "unique_id": null,
      "disabled_by": null
    }
  }
}

Debug logs

No logs related to this newly created entity. This instead (probably unrelated to the scheduling issue):

Logger: aiohttp.server
Source: custom_components/garbage_collection/diagnostics.py:21
Integration: Garbage Collection (documentation, issues)
First occurred: 9:58:26 AM (3 occurrences)
Last logged: 10:03:17 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 81, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/diagnostics/__init__.py", line 211, in get
    data = await info[d_type.value](hass, config_entry)
  File "/config/custom_components/garbage_collection/diagnostics.py", line 18, in async_get_config_entry_diagnostics
    entity_data = [
  File "/config/custom_components/garbage_collection/diagnostics.py", line 21, in <listcomp>
    if entities[entity].unique_id == entry.data["unique_id"]
KeyError: 'unique_id'
msimecek commented 1 year ago

I confirm that https://github.com/bruxy70/Garbage-Collection/commit/ae73818b3b0786ebcf72b16a6f27428e516686e6 fixed this issue.

Thank you! The speed of updates that you provide is incredible!