New plugin development questions

Python and python framework

Moderator: leecollings

Post Reply
User avatar
pgielen
Posts: 90
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

New plugin development questions

Post by pgielen »

I am not an experienced Python developer, but using the plugin.py template mentioned in the Domoticz Wiki, I am trying to develop a new hardware plugin based on a standalone Python script that is running fine from the command line of my RPi4B.

Unfortunately, in Domoticz I am running into problems right away. After installation of the plugin from the hardware tab, I get error messages. Are there limitation as to what libs you can import? Apart from the Domoticz and sys lib, I have added:

import aiohttp
import asyncio
import pysmartthings

These libs have been installed in Python3.7 from the CLI first.

The log says:

2021-09-20 12:05:56.549 Error: STEST1A: (SmartThings) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/smartthings/:/usr/lib/python37.zip:/usr/lib/python3.7:/usr/lib/python3.7/lib-dynload:/usr/local/lib/python3.7/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.7/dist-packages'.
2021-09-20 12:05:56.549 Error: STEST1A: (STEST1A) Module Import failed, exception: 'SyntaxError'
2021-09-20 12:05:56.549 Error: STEST1A: (STEST1A) Import detail: File: , Line: 49, offset: 8
2021-09-20 12:05:56.549 Error: STEST1A: (STEST1A) Error Line ' async with aiohttp.ClientSession() as session:
2021-09-20 12:05:56.549 Error: STEST1A: (STEST1A) No traceback available

Line 49 is in this section in which I try to fill an array with available devices of my SmartThings setup on start:

Code: Select all

    def onStart(self):
        Domoticz.Log("onStart called")
        async with aiohttp.ClientSession() as session:
          api = pysmartthings.SmartThings(session, tokenSmartThings) 
          devices = await api.devices() 
It looks like the asyncio and/or the aiohttp lib is not loaded. Or did I make a mistake?
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: New plugin development questions

Post by waltervl »

I am not sure (also no Python developer) but I think you have to use the Plugin Framework Connections method.
https://www.domoticz.com/wiki/Developin ... onnections

https://github.com/domoticz/domoticz/bl ... es/HTTP.py

At least if you are connecting to an extrnal site...
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
breizhcat
Posts: 16
Joined: Tuesday 07 July 2020 17:51
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: New plugin development questions

Post by breizhcat »

Hi

I had the same issue with one library that i have installed through pip.
Unable to use it within my plugin. As it was a tiny library i put it directy into my plugin.py file as workaround.

I would like to have feedback and maybe a solution.

Br

Envoyé de mon Mi 9T Pro en utilisant Tapatalk

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest