sde1000 / python-dali

Library for controlling DALI lighting systems
Other
150 stars 71 forks source link

Add support for DALI Occupancy Sensor devices #108

Closed sl-wallace closed 1 year ago

sl-wallace commented 1 year ago

Implements support for commands, responses and events from IEC 62386 part 303: "Input devices — Occupancy sensor"

sl-wallace commented 1 year ago

Hi @sde1000 , I've had a go at implementing Occupancy Sensor support. It seems to work well with the sensor that I have, although so far I just have the one to try it with.

Really the only thing that stuck out as a bit tricky was the way the events are encoded - there's multiple properties per event notification. This is the list of events, which isn't the clearest way of explaining it but I suppose shows that there could be both a "Movement" and a "Still Occupied" event.

Screenshot from 2022-10-04 16-58-08

I decided to do a kind of bitmap type, using a Named Tuple. It means that things like e.g. this test code can work:

assert isinstance(decode_cmd, OccupancyEvent)
assert decode_cmd.movement
assert decode_cmd.occupied
assert not decode_cmd.repeat
assert decode_cmd.sensor_type == "movement"

Let me know what you think, I'd be happy to try some other way of representing the events if you can think of something neater.

sde1000 commented 1 year ago

That sounds sensible, and the pull request looks good to me on a first readthrough.

I'm afraid it will be a few more days before I have time to have a thorough look. Work deadlines :-(

sde1000 commented 1 year ago

All good, thank you.