コード例 #1
0
    def __checkIfNoBodyHome(self):
        result = False
        alarm = AlarmClass.AlarmClass()
        settings = self.__alarmActivatSettings
        currentTimestamp = time.time()

        sensors = alarm.getPresence()['presence']
        #logging.error(str(sensors))
        #print(sensors)
        for sensor in sensors:
            #todo : check if sensor exists in any room, if not then continue without checking (szambo case)
            if (sensor['name'] in settings['sensors']) and (sensor['presence']
                                                            == 'on'):
                result = True
                self.__alarmActivatedFlag = True
                self.__alarmActivatedTimestamp = currentTimestamp
            elif (sensor['name']
                  not in settings['sensors']) and (sensor['presence'] == 'on'):
                result = False
                self.__alarmActivatedFlag = False
                break

        #print(currentTimestamp - self.__alarmActivatedTimestamp)
        #print(int(settings['timeToActivate']) * 60)
        #print(self.__alarmActivatedFlag)
        if (currentTimestamp - self.__alarmActivatedTimestamp >=
            (int(settings['timeToActivate']) * 60)) and (
                self.__alarmActivatedFlag == True):
            return True
        else:
            return False
コード例 #2
0
    def timeEvent(self, tick):
        alarm = AlarmClass.AlarmClass()

        if tick % 5 == 0:
            try:
                statusSensors = self.__config.getDeviceSensors('status')
                inputSensors = alarm.getPresence()

                if inputSensors['error'] != 0:
                    raise Exception('Error Response',
                                    str(inputSensors['error']))

                self.__config.changeStatus('status', '0', '0')
                for statusSensor in statusSensors:
                    for inputSensor in inputSensors['presence']:
                        if statusSensor[1] == inputSensor['name'] \
                            and inputSensor['presence'] == 'on':

                            # print "---------------Status on for "+ inputSensor['name']

                            self.__config.changeStatus('status',
                                                       statusSensor[0], '1')
                        elif statusSensor[1] == inputSensor['name'] \
                            and inputSensor['presence'] == 'off':

                            # print "---------------Status off for "+ inputSensor['name']

                            self.__config.changeStatus('status',
                                                       statusSensor[0], '0')
            except:
                self.__config.changeStatus('status', '0', '1')
コード例 #3
0
    def actionOnGatePerm(self, param=''):
        alarm = AlarmClass.AlarmClass()
        threadTask = ActionThread.ActionThread()
        config = ConfigClass.ConfigClass()
        sensor = config.getDeviceSensor('gate', param)
        time = config.getDeviceSensorActionDuration('gate', param)
        url = alarm.getUpdateUrl(sensor, 1)
        threadTask.addTask(
            ActionThread.Task('set', ActionThread.UpdateParam('gate', param)))
        threadTask.addTask(
            ActionThread.Task('request', ActionThread.RequestParam(url)))
        threadTask.addTask(
            ActionThread.Task('delay', ActionThread.DelayParam(time)))

        threadTask.addTask(
            ActionThread.Task('request', ActionThread.RequestParam(url)))
        threadTask.addTask(
            ActionThread.Task('delay', ActionThread.DelayParam(2)))

        threadTask.addTask(
            ActionThread.Task('request', ActionThread.RequestParam(url)))

        threadTask.addTask(
            ActionThread.Task('clear', ActionThread.UpdateParam('gate',
                                                                param)))
        threadTask.start()
        threadTask.suspend()
        return time
コード例 #4
0
    def __controlSprinkler(self, ctrlType=0, ctrlParam='-1'):
        alarm = AlarmClass.AlarmClass()
        threadTask = ActionThread.ActionThread()
        config = ConfigClass.ConfigClass()

    # make sure all sprinklers are disabled - only one sprinkler can be enable in the same time

        sensors = config.getDeviceSensors('sprinkler')
        for item in sensors:
            sensor = item[1]
            id = item[0]
            url_off = alarm.getUpdateUrl(sensor, 0)
            threadTask.addTask(ActionThread.Task('request',
                               ActionThread.RequestParam(url_off)))
            threadTask.addTask(ActionThread.Task('clear',
                               ActionThread.UpdateParam('sprinkler',
                               id)))

    # enable one sprinkler device

        if ctrlType != 0:
            sensor = config.getDeviceSensor('sprinkler', ctrlParam)
            url_on = alarm.getUpdateUrl(sensor, 1)
            threadTask.addTask(ActionThread.Task('request',
                               ActionThread.RequestParam(url_on)))
            threadTask.addTask(ActionThread.Task('set',
                               ActionThread.UpdateParam('sprinkler',
                               ctrlParam)))

        threadTask.addTask(ActionThread.Task('notify',
                           ActionThread.NotifyParam()))
        threadTask.start()
        threadTask.suspend()
コード例 #5
0
    def getCurrentProduceEnergy(self):
        energy = {}
        try:
            alarm = AlarmClass.AlarmClass()
            energy = alarm.getEnergy()
        except:
            print("___________energy exception")

        return energy
コード例 #6
0
    def __getTemperatureFromDevice(self):
        config = ConfigClass.ConfigClass()
        alarm = AlarmClass.AlarmClass()
        thermDevices = alarm.getTemperature()
        temperature = 0
        isTemepratureInit = False
        thermalElements = 1
        status = 0

        if thermDevices['error'] != 0:
            status = 1
        else:
            thermData = config.getFirstThermDevices()
            while thermData['error'] == 0:
                for item in thermDevices['temperature']:
                    if thermData['name'] == item['name']:
                        tempValue = round(
                            float(item['value']) + float(thermData['offset']),
                            2)

                        if isTemepratureInit == False:
                            temperature = tempValue
                            isTemepratureInit = True
                        elif thermData['mode'] == 'max' and tempValue \
                            > temperature or thermData['mode'] == 'min' \
                            and tempValue < temperature:
                            temperature = tempValue
                        elif thermData['mode'] == 'avg' \
                            or isTemepratureInit == False:
                            temperature = (temperature + tempValue) \
                                / thermalElements

                        thermalElements = thermalElements + 1
                        break
                thermData = config.getNextThermDevices()

        return (status, temperature)
コード例 #7
0
    def manageHeaterState(
        self,
        dayOfWeek,
        hour,
        minute,
    ):
        config = ConfigClass.ConfigClass()
        weather = WeatherClass.WeatherClass()
        alarm = AlarmClass.AlarmClass()
        threadTask = None

        dayTemp = float(config.getDayTemp())
        nightTemp = float(config.getNightTemp())
        threshold = float(config.geTempThreshold())

        isDayMode = config.isDayMode(dayOfWeek, hour)

        (status, temp) = self.__getTemperatureFromDevice()
        if status != 0:
            return

        # new day - reset statistics

        if hour == 0 and minute == 0:
            HeaterClass.__heaterOnToday = 0
            HeaterClass.__data_per_day = []
        if HeaterClass.__lastState == HeaterClass.__StateOn:
            HeaterClass.__heaterOnToday = HeaterClass.__heaterOnToday \
                + 1

        if HeaterClass.__dayMode != isDayMode:

            # if mode has changed set heater state as 'unknown'(-1)

            HeaterClass.__lastState = HeaterClass.__StateUnknown

        self.__storeDataCounter = self.__storeDataCounter + 1
        HeaterClass.__dayMode = isDayMode

        sensor = config.getDeviceSensors('heater')[0]

        if isDayMode == True and temp + threshold <= dayTemp \
            or isDayMode == False and temp + threshold <= nightTemp:

            # turn on heater

            url = alarm.getUpdateUrl(sensor[1], 1)
            if HeaterClass.__lastState == HeaterClass.__StateOff \
                or HeaterClass.__lastState \
                == HeaterClass.__StateUnknown:
                threadTask = ActionThread.ActionThread()
                threadTask.addTask(
                    ActionThread.Task(
                        'set', ActionThread.UpdateParam('heater', sensor[0])))
            HeaterClass.__lastState = HeaterClass.__StateOn
        elif isDayMode == True and temp >= dayTemp + threshold \
            or isDayMode == False and temp >= nightTemp + threshold \
            or HeaterClass.__lastState == HeaterClass.__StateUnknown:

            # turn off heater

            url = alarm.getUpdateUrl(sensor[1], 0)
            if HeaterClass.__lastState == HeaterClass.__StateOn \
                or HeaterClass.__lastState \
                == HeaterClass.__StateUnknown:
                threadTask = ActionThread.ActionThread()
                threadTask.addTask(
                    ActionThread.Task(
                        'clear', ActionThread.UpdateParam('heater',
                                                          sensor[0])))
            HeaterClass.__lastState = HeaterClass.__StateOff

        if threadTask != None:
            threadTask.addTask(
                ActionThread.Task('request', ActionThread.RequestParam(url)))
            threadTask.addTask(
                ActionThread.Task('notify', ActionThread.NotifyParam()))
            threadTask.start()
            threadTask.suspend()

        # store data once per defined invokes (currently it means once per 10min) - not need so many data

        if self.__storeDataCounter % HeaterClass.__storeDataInterval \
            == 0:
            weatherData = weather.getCurrentWeather()
            if not weatherData:
                tempOutside = 0
            else:
                tempOutside = weatherData['temp']

            HeaterClass.__data.append(
                HeaterParam(temp, tempOutside, HeaterClass.__lastState,
                            isDayMode))
            HeaterClass.__data_per_day.append(
                HeaterParam(temp, tempOutside, HeaterClass.__lastState,
                            isDayMode))
            if len(HeaterClass.__data) > HeaterClass.__maxDataBuffer:
                HeaterClass.__data.pop(0)
コード例 #8
0
    def getRoomsData(self):
        config = ConfigClass.ConfigClass()
        switch = SwitchClass.SwitchClass()
        alarm = AlarmClass.AlarmClass()
        weather = WeatherClass.WeatherClass()
        try:
            tempOut = weather.getCurrentWeather()['temp']
        except:
            #dirty workaround must be fixed
            tempOut = 0

        roomsObj = {}
        rooms = []

        temperature = alarm.getTemperature()
        alerts = alarm.getAlerts()
        presence = alarm.getPresence()
        roomsObj['error'] = 0

        for item in config.getRooms():
            roomParams = {}
            roomlight = {}
            roomAlarm = {}
            roomTemp = {}
            roomPresence = {}

            roomParams['id'] = item['id']
            roomParams['name'] = item['name']

            roomlight['light_ip'] = item['light_ip']
            data = switch.getSwitchInfo(item['light_ip'])
            if data['error'] == 0:
                roomlight['light_state'] = data['data']['switch']
                roomlight['light_present'] = 1
            else:
                roomlight['light_state'] = 'off'
                roomlight['light_present'] = 0

            roomAlarm['presence'] = 'off'
            roomAlarm['alert'] = 'off'
            roomAlarm['present'] = 0
            try:
                for alarmSensor in item['alarmSensors']:
                    for alarmItem in alerts['alerts']:
                        if alarmItem['name'] == alarmSensor \
                            and roomAlarm['alert'] == 'off':
                            roomAlarm['alert'] = alarmItem['alert']
                            roomAlarm['present'] = 1

                    for presenceItem in presence['presence']:
                        if presenceItem['name'] == alarmSensor \
                            and roomAlarm['presence'] == 'off':
                            roomAlarm['presence'] = \
                                presenceItem['presence']
                            roomAlarm['present'] = 1
            except:

                roomsObj['error'] = 255

            roomTemp['id'] = item['tempId']
            roomTemp['temperature'] = ''
            roomTemp['thresholdExceeded'] = 'no'
            roomTemp['present'] = 0
            for tempItem in temperature['temperature']:
                if tempItem['name'] == item['tempId']:
                    roomTemp['temperature'] = (
                        tempItem['value'])[:tempItem['value'].find('.') + 2]
                    roomTemp['thresholdExceeded'] = \
                        tempItem['thresholdExceeded']
                    roomTemp['present'] = 1
                    break

            if item['tempId'] == 'weather':
                roomTemp['temperature'] = tempOut
                roomTemp['thresholdExceeded'] = 'no'
                roomTemp['present'] = 1

            roomParams['light'] = roomlight
            roomParams['alarm'] = roomAlarm
            roomParams['temperature'] = roomTemp
            rooms.append(roomParams)

        roomsObj['rooms'] = rooms
        return roomsObj