Python Plugin Proposal
This page is work in progress before any code is written, feel free to comment.
This page is for brainstorming on easier API for Python plugins based on experiences of the current plugin system. The discussion started with .
- Create objects for the various sensor types with methods specific for that type of sensor
- Use Python naming conventions, see 
- Use classes for various sensor types.
The plugin definition of the current plugin is working well.
Use lowercase name as Domoticz module
Having a list of all devices with the unit number as index works well. Reuse the standard list methods to interact with the devices list.
if not domoticz.devices: # same as if len(domoticz.devices) == 0: mysensor = domoticz.OnOffSwitch(name='Living Room Temp', on_delay=1, off_delay=3) mysensor.on_action = 'http://localhost/temp/on' domoticz.devices.append(mysensor)
Create the various sensor types as classes:
Make the sensor properties available as getter, and (if allowed) as setter as seen in the example above for on_action.
Common attributes like name should be part of the base Sensor class. With read-only attributes idx, id, unit and type.
Q & A
--DebugBill: Give ability to aggregate sensors to create composites in order to avoid the need of creating
- Temp + Baro
- Temp + Humidity
- Temp + Baro + Humidity
- Baro + Humidity
..... as it is today Composites will share logs and graphs, separate sensors will not. Choice is left to the programmer.
--Oohlaf (talk) 23:30, 4 April 2017 (CEST) How is this currently done in C++? When I browse the hardwaretypes.h file, I see a type per combination, not the composition you speak of. Not sure what you would like to see. Can you give an (pseudo) code example of how you'd want to see it used?
--DebugBill: Is this for Python only, or C++ too?
--GizMoCuz I would create on create function for a switch and specify the type as parameter. Also i would start all create functions with 'Create'
domoticz.CreateSwitch(name='Dashboard Light', type=OnOff, on_delay=1, off_delay=3)
--Dnpwwo - 14th April 2017
I like the idea of adding devices by appending them to domoticz.devices.
I also like having more specific classes for sensor types based on a base class because it is an actual step towards object orientation. I considered this when I first created devices but didn't have the time.
I agree with Oohlaf, if we are trying to move towards a move natural Python implementation we should do this the Python way (Python doc), just instantiate the class and add it to the devices dictionary if you want to add it to Domoticz