Wirehome.Core
Wirehome.Core copied to clipboard
Why adapter code should write with Python?
Why adapter code should write with Python? Can i write it on C#?
I think that stront type language (C#) are more safe in this Domain (home automation) instead Python.
Choosing Python has several advantages over .net.
- It is a scripting language with OOP support. So you can build everything you want.
- Python is way mroe poerful than c#. Also the local pip repos is supported in Wirehome.Core. So you can install for example a IKEA tradfri library and just use it in the Python adapter. C# has DLL hell, requires recompilation etc.
- I want to keep the adapters open to allow easy modifications. If I rely on a apdater which is just a c# dll and out opf a sudden it gets no longer updates I am lost. Python adapters can be easily forked and changed etc.
- Not Python but IronPython gets compiled in IL (so same performance as c#) but it is more reliable because it will run even with syntax errors. If you have for example a syntax error in a birghtness function you can still turn the lamp on and off. Only setting the brightness will fail. That is want I prefer. Not a c# file which is unusable if there is just a small typo.
- The only compromise I can see is make use of csc and provide support für c# "script" files. But these also have some downsides because it is not flexible like Python is. I have to expose some interfaces etc.
- If you want to use a c# lib you can for sure do that. IronPyton allows importing c# classes and functions. So you can keep your Python code very small (just a wrapper) if you want.
I have spent some thought about this in the last year. My mental modelling was following by what the Language Server Protocol is doing in the space of editors. Build a out-of-proc model for sensos/actors and communicate with these sensor/actor-servers using a local communication protocol (pipes, HTTP, websockets, whatever).
sensor <-- whatever protocol --> sensor-server (however coded) <-- standard sensor protocol --> hub (in theory ... any supporting hub)
Like that you get the safety of isolation, the choice of language for the adapters, the interoperability/availability/reuse of sensor/actor connectors and as a hub developer just need to provide a single interface towards them. Mixed in with some docker usage, it can be very powerful ;). No idea if the space already has something like that, but it should. Helped in the editor space (VS Code, vim, sublime, etc) a lot.