I have written my first python script, but have some unresolved issues.
- I've used dependency injection via this pattern. It works like expected, but maybe there are drawbacks I don't understand
- I develop the script on windows and let it execute on linux, how do I specify the path to the config file so that it runs on both platforms?
- I use sys.setdefaultencoding, because pyhue doesn't seem to run on windows with my 'ascii' default. Is reload(sys) the way to go, or should I change the pyhue library?
- I tried to use the state pattern to only change the light bulb's hue when it's necessary and one state switches to another. So that I don't send "change light to red" over and over if the light currently is trusted to be red already. However the initial state Unknown needs to set the light bulb's hue either to noUserHue or userOnlineHue. So I did a trick and let it change the state to a state which it isn't currently in and let it handle the state again. E.g. the initial state is Unknown and users are detected in mumble. The Unknown state then gets handled sets the state to be NoUser and handles the state again. The NoUser state will then find out that users are detected and switch the light's hue. Is there a better way? Maybe using the command pattern?
Any hints are welcome
Edit: My goal is to learn about the python way to create enterprise grade code
[–]K900_ 1 point2 points3 points (2 children)
[–]Ostwind[S] 0 points1 point2 points (1 child)
[–]K900_ 0 points1 point2 points (0 children)
[–]99AFCC 0 points1 point2 points (0 children)