Hi, I am having difficulties developing AppDaemon apps, here is my setup
Using VSCode for writing any Python code
Samba share enabled and accessing the /config folder inside VSCode directly for making any changes to the configuration
Python 3 extensions installed for VSCode
Now, the apps that I’m writing are working fine, however, pylint tells me that there is an error in import appdaemon.plugins.hass.hassapi as hass, No name ‘plugins’ in ‘appdaemon’. How do I resolve this?
Your editor is spawning a python process to run pylint on your local machine. One solution is to make it the same python environment that appdaemon is installed in. For example, if I install appdaemon in a conda environment so as long as I activate that conda environment before running my editor (emacs), python checks work fine. That may mean that working on a remote machine won’t work, but you can probably install python and appdaemon on your remote machine to duplicate what you have running and it will work fine then (but remember to keep them in sync). Or maybe set your PYTHONPATH to point at the mounted directory so that your local python can find appdaemon.
This looks interesting, I’ll try it out to see if this works, but are you aware what will be the path here? is it going to be the appdaemon folder under config? or something else. PS: I am running it via hassio add-on.
This now makes me wonder what is the recommended or official way of developing the apps. The current documentation doesn’t talk about any environment settings (hope I didn’t miss anything).
apps run the second you save them and when you look at the logs you know what is wrong.
i dont know what environment settings you mean.
the way i develop is:
build the appframe (mostly copy paste) then add code.
i also find it very helpfull to realise that you dont create an enourmous framework of complicated programming. an app is something small and on its own.
for example this is an entire app creating a sensor:
import appdaemon.plugins.hass.hassapi as hass
import datetime
import time
import psutil
import os
class setsensors(hass.Hass):
def initialize(self):
runtime = datetime.datetime.now()
addseconds = (round((runtime.minute*60 + runtime.second)/300)+1)*300
runtime = runtime.replace(minute=0, second=0, microsecond=0) + datetime.timedelta(seconds=addseconds)
self.run_every(self.set_mem_sensor,runtime,300)
def set_mem_sensor(self, kwargs):
attributes={"friendly_name": "Memory use from Appdaemon"}
process = psutil.Process(os.getpid())
kilobyte = process.memory_info().rss//1024
children = process.children(recursive=True)
attributespid = ""
counter = 0
for child in children:
if attributespid == "":
attributespid = child.name() + "(" + str(child.pid) + ")"
else:
attributespid = attributespid + ", " + child.name() + "(" + str(child.pid) + ")"
counter = counter +1
attributes["proc subs"] = attributespid
attributes["proc amount"] = str(counter)
self.set_state("sensor.appdaemon_memory", state=kilobyte, attributes=attributes)