benleb / ad-automoli

💡 Fully automatic light management based on conditions like motion, illuminance, humidity, and other clever features
https://github.com/benleb/ad-automoli
MIT License
110 stars 29 forks source link

Does not work when there is only a single daytime #112

Open Ramblurr opened 1 year ago

Ramblurr commented 1 year ago

😩 Describe the issue/bug

Does not work when there is only a single daytime.

😒 Expected behavior

It should work with only a single daytime

🎛️ Configuration

---
toilet:
  module: automoli
  class: AutoMoLi
  room: toilet
  debug_log: true
  motion:
    - binary_sensor.wc_motion_sensor_occupancy
  delay: 5
  motion_state_on: "on"
  motion_state_off: "off"
  lights:
    - switch.toilet
  daytimes:
    - { name: alwayson, starttime: "00:00", light: 100 }

🧠 System

🗒️ Logs

When the app is loaded

2022-10-11 20:14:11.532271 WARNING toilet: Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/appdaemon/app_management.py", line 163, in initialize_app await init() File "/config/appdaemon/apps/automoli/automoli.py", line 448, in initialize "active_daytime": self.active_daytime, AttributeError: 'AutoMoLi' object has no attribute 'active_daytime' 

when the motion sensor is triggered:

2022-10-11 20:14:14.997915 WARNING toilet: Traceback (most recent call last): File "/usr/lib/python3.10/site-packages/appdaemon/threading.py", line 826, in async_worker await funcref( File "/config/appdaemon/apps/automoli/automoli.py", line 568, in motion_detected await self.motion_event("state_changed_detection", data, kwargs) File "/config/appdaemon/apps/automoli/automoli.py", line 597, in motion_event await self.lights_on() File "/config/appdaemon/apps/automoli/automoli.py", line 940, in lights_on raise ValueError( ValueError: invalid brightness/scene: None in <adutils.Room object at 0x7f98b8f27070>  

🧁 Additional context

This happens because the self.active_daytime is never set so an exception occurs on line 448.

self.active_daytime is not set because the code for it expects there to be at least two daytimes:

            # check if this daytime should ne active now
            if await self.now_is_between(str(dt_start), str(next_dt_start)):
                await self.switch_daytime(dict(daytime=daytime, initial=True))
                self.active_daytime = daytime.get("daytime")

Also this line should have self.room.name for a useful log output

mycanaletto commented 1 year ago

Doesn't work either if you don't put the daytime: line, which seems optional...