hassio-addons / addon-appdaemon

AppDaemon4 - Home Assistant Community Add-ons
https://addons.community
MIT License
151 stars 47 forks source link

Error in threading.py #200

Closed mikastrup closed 2 years ago

mikastrup commented 2 years ago

Problem/Motivation

I get this error and can't see what I am doing wrong

The error

2022-06-18` 15:38:19.043285 WARNING Error: ------------------------------------------------------------
2022-06-18 15:38:49.125423 WARNING Home_or_nothome: ------------------------------------------------------------
2022-06-18 15:38:49.126589 WARNING Home_or_nothome: Unexpected error in worker for App Home_or_nothome:
2022-06-18 15:38:49.127446 WARNING Home_or_nothome: Worker Ags: {'id': 'effc2e3c112140a4821a65c11191c143', 'name': 'Home_or_nothome', 'objectid': '3790cf4b14a749d1b14f0c952ba52e4c', 'type': 'state', 'function': <bound method Home_or_nothome.Home_or_nothom of <Home_or_nothome.Home_or_nothome object at 0x7fb56ed900>>, 'attribute': 'state', 'entity': 'device_tracker.one', 'new_state': 'home', 'old_state': 'not_home', 'pin_app': True, 'pin_thread': 5, 'kwargs': {'__thread_id': 'thread-5'}}
2022-06-18 15:38:49.128301 WARNING Home_or_nothome: ------------------------------------------------------------
2022-06-18 15:38:49.129368 WARNING Home_or_nothome: Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/appdaemon/threading.py", line 917, in worker
    funcref(
TypeError: Home_or_nothome.Home_or_nothom() takes 2 positional arguments but 6 were given

2022-06-18 15:38:49.134513 WARNING Home_or_nothome: ------------------------------------------------------------

the code

import appdaemon.plugins.hass.hassapi as hass
import datetime
import pickle
import requests as req

Time_beteween_vacuum = 48*3600.0  #48*3600.0 #time beteween vaccums in sec
Someone_home_bol = None

class Home_or_nothome(hass.Hass):
    def initialize(self):
        self.listen_state(self.Home_or_nothom , "device_tracker.one")
        self.listen_state(self.Home_or_nothom, "device_tracker.iphone")
        self.check_vacuum_daily = self.run_daily(self.Home_or_nothom, "10:00:00")
        self.log("daily vacuum timer -->")
        self.log(self.info_timer(self.check_vacuum_daily))

    def Home_or_nothom(self, kwargs):
        self.log("                   ")
        global Someone_home_bol

    #-----------------------------------------determine if somene is home------------------------------------------------------------
        mik_home_str = self.get_state("device_tracker.one")
        Lou_home_str = self.get_state("device_tracker.iphone")

        if mik_home_str or Lou_home_str == "home":
            Someone_home_bol = True
        if mik_home_str != "home" and Lou_home_str != "home":
            Someone_home_bol = False

    #-----------------------------------------arrive home------------------------------------------------------------
        if Someone_home_bol: #Hjemme
            self.log("nogen er hjemme --> " + str(Someone_home_bol))

            if self.get_state("sensor.yunldr") < self.get_state("input_number.lysvaerdi_for_taend_lys_hjemkomst"):
                self.turn_on("light.john_john", brightness=180, color_temp=432)
                self.turn_on("light.kokkeno", brightness=180, color_temp=432)

        #----------Vacuum-----------------
            try:
                self.cancel_timer(self.vacuum_delay_start_timer)
                self.log("Vacuum timer canceld")
            except:
                self.log("no Vacuum timer enabled...")

            req.get("http://192.168.1.165:3000/api/local/action/pause") # Pause vaccum when comming home

    #-----------------------------------------leve home------------------------------------------------------------
        if Someone_home_bol == False: #Ikke hjemme
            self.log("nogen er hjemme --> " + str(Someone_home_bol))
        #-----------------Stop mediaplyers-----------------
            for entity in self.get_state():
                if "media_player" in entity:
                    self.call_service("media_player/media_pause", entity_id = entity)

                if "light" in entity:
                    self.turn_off(entity)
        #--------------start vacuum-------------------------
            vacuum_check_start(self)

    def vacuum_check_start(self):
        global Someone_home_bol
        global Time_beteween_vacuum

        pickle_file = open('/config/appdaemon/data/vacuum.pkl','rb')
        previusTime_vacuum_clean = pickle.load(pickle_file)
        pickle_file.close()
        self.log("previusTime_vacuum_clean ->")
        self.log(previusTime_vacuum_clean)
        self.log(type(previusTime_vacuum_clean))

        time_since_vacuum = datetime.datetime.now() - previusTime_vacuum_clean

        try:
            self.cancel_timer(self.vacuum_delay_start_timer)
            self.log("vacuum timer canceld")
        except:
            self.log("no vacuum timer enabled...")

        if self.get_state("input_boolean.stovsug_nar_ingen_er_hjemme") and Someone_home_bol == False:
            self.log(time_since_vacuum.total_seconds())

            if float(time_since_vacuum.total_seconds()) > Time_beteween_vacuum:
                self.log("vacuum timer stratet")
                self.vacuum_delay_start_timer = self.run_in(self.vacuum_start, 3600) #delay for start vacuum

                self.log(self.info_timer(self.vacuum_delay_start_timer))

    def vacuum_start(self,kwargs):
        self.log("vacuum startet...")
        pickle_file = open('/config/appdaemon/data/vacuum.pkl','wb')
        pickle.dump(datetime.datetime.now(), pickle_file)
        pickle_file.close()
        #self.turn_on("light.kontor_4")
        self.call_service("input_text/set_value", entity_id = "input_text.vacuum_rooms", value="alrum,sovevaerelse,kontor")
        self.call_service("automation/trigger", entity_id = "automation.vacuum_clean_rooms")
frenck commented 2 years ago

This is not an add-on issue, so closing the issue for that reason.

Nevertheless, looking at the code; I think you meant to use:

def Home_or_nothom(self, *args, **kwargs):