home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.68k stars 30.43k forks source link

Xiaomi vacuum cleaner entity not available on the last day of month #42688

Closed ladzar closed 3 years ago

ladzar commented 3 years ago

The problem

My HA installation stopped recognizing my Xiaomi Miio Robot Vacuum device today (31.10.). I see message "Entity not available: vacuum.xiaomi_vacuum_cleaner" on the lovelace. I suspect the problem happened because of the invalid CRON expression (0 15 32 10 *) due to the last day of month - the day 32 doesn't exist - see the logs.

Environment

Problem-relevant configuration.yaml

  - platform: xiaomi_miio
    host: 192.168.100.171
    name: XXX
    token: XXXXXXXXXXXXXXXXXXXXXXXXXX

Traceback/Error logs

2020-10-31 19:58:55 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1837960808] [0 15 32 10 *] is not acceptable, out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1448, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1483, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 499, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 283, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 323, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/vacuum.py", line 339, in device_state_attributes
    if self.timers:
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/vacuum.py", line 284, in timers
    return [
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/vacuum.py", line 288, in <listcomp>
    "next_schedule": as_utc(timer.next_schedule),
  File "/usr/local/lib/python3.8/site-packages/miio/vacuumcontainers.py", line 445, in next_schedule
    cron = croniter(self.cron, start_time=local_tz.localize(datetime.now()))
  File "/usr/local/lib/python3.8/site-packages/croniter/croniter.py", line 109, in __init__
    self.expanded, self.nth_weekday_of_month = self.expand(expr_format)
  File "/usr/local/lib/python3.8/site-packages/croniter/croniter.py", line 602, in expand
    raise CroniterBadCronError(
croniter.croniter.CroniterBadCronError: [0 15 32 10 *] is not acceptable, out of range

Additional information

probot-home-assistant[bot] commented 3 years ago

Hey there @rytilahti, @syssi, @starkillerog, mind taking a look at this issue as its been labeled with an integration (xiaomi_miio) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

rytilahti commented 3 years ago

This should be fixed in upstream, so please create an issue at https://github.com/rytilahti/python-miio/, thanks! The cron data is coming directly from the device, so the solution would be to ignore such invalid cases before handing out the list of timers.

edit: oopsie, we can leave this open until this gets fixed upstream & the dependency gets bumped.