<commit_before>/*
 * Copyright (c) 2017-2018 dresden elektronik ingenieurtechnik gmbh.
 * All rights reserved.
 *
 * The software in this package is published under the terms of the BSD
 * style license a copy of which has been included with this distribution in
 * the LICENSE.txt file.
 *
 */

#ifndef DE_WEB_PLUGIN_PRIVATE_H
#define DE_WEB_PLUGIN_PRIVATE_H
#include <QtGlobal>
#include <QObject>
#include <QTime>
#include <QTimer>
#include <QElapsedTimer>
#include <stdint.h>
#include <queue>
#if QT_VERSION < 0x050000
#include <QHttpRequestHeader>
#endif
#include "sqlite3.h"
#include <deconz.h>
#include "resource.h"
#include "event.h"
#include "resource.h"
#include "rest_node_base.h"
#include "light_node.h"
#include "group.h"
#include "group_info.h"
#include "scene.h"
#include "sensor.h"
#include "resourcelinks.h"
#include "rule.h"
#include "bindings.h"
#include <math.h>
#include "websocket_server.h"

/*! JSON generic error message codes */
#define ERR_UNAUTHORIZED_USER          1
#define ERR_INVALID_JSON               2
#define ERR_RESOURCE_NOT_AVAILABLE     3
#define ERR_METHOD_NOT_AVAILABLE       4
#define ERR_MISSING_PARAMETER          5
#define ERR_PARAMETER_NOT_AVAILABLE    6
#define ERR_INVALID_VALUE              7
#define ERR_PARAMETER_NOT_MODIFIEABLE  8
#define ERR_TOO_MANY_ITEMS             11
#define ERR_DUPLICATE_EXIST            100 // de extension
#define ERR_NOT_ALLOWED_SENSOR_TYPE    501
#define ERR_SENSOR_LIST_FULL           502
#define ERR_RULE_ENGINE_FULL           601
#define ERR_CONDITION_ERROR            607
#define ERR_ACTION_ERROR               608
#define ERR_INTERNAL_ERROR             901

#define ERR_NOT_CONNECTED              950 // de extension
#define ERR_BRIDGE_BUSY                951 // de extension

#define ERR_LINK_BUTTON_NOT_PRESSED    101
#define ERR_DEVICE_OFF                 201
#define ERR_BRIDGE_GROUP_TABLE_FULL    301
#define ERR_DEVICE_GROUP_TABLE_FULL    302

#define ERR_DEVICE_SCENES_TABLE_FULL   402 // de extension

#define IDLE_LIMIT 30
#define IDLE_READ_LIMIT 120
#define IDLE_USER_LIMIT 20
#define IDLE_ATTR_REPORT_BIND_LIMIT 240
#define BUTTON_ATTR_REPORT_BIND_LIMIT 120
#define WARMUP_TIME 120

#define MAX_UNLOCK_GATEWAY_TIME 600
#define PERMIT_JOIN_SEND_INTERVAL (1000 * 1800)
#define EXT_PROCESS_TIMEOUT 10000
#define SET_ENDPOINTCONFIG_DURATION (1000 * 16) // time deCONZ needs to update Endpoints
#define OTA_LOW_PRIORITY_TIME (60 * 2)
#define CHECK_SENSOR_FAST_ROUNDS 3
#define CHECK_SENSOR_FAST_INTERVAL 100
#define CHECK_SENSOR_INTERVAL      1000
#define CHECK_SENSORS_MAX          10

#define DE_OTAU_ENDPOINT             0x50
#define DE_PROFILE_ID              0xDE00
#define ATMEL_WSNDEMO_PROFILE_ID   0x0001

// Generic devices
#define DEV_ID_ONOFF_SWITCH                 0x0000 // On/Off switch
#define DEV_ID_LEVEL_CONTROL_SWITCH         0x0001 // Level control switch
#define DEV_ID_ONOFF_OUTPUT                 0x0002 // On/Off output
#define DEV_ID_RANGE_EXTENDER               0x0008 // Range extender
#define DEV_ID_MAINS_POWER_OUTLET           0x0009 // Mains power outlet
#define DEV_ID_SMART_PLUG                   0x0051 // Smart plug
// HA lighting devices
#define DEV_ID_HA_ONOFF_LIGHT               0x0100 // On/Off light
#define DEV_ID_HA_DIMMABLE_LIGHT            0x0101 // Dimmable light
#define DEV_ID_HA_COLOR_DIMMABLE_LIGHT      0x0102 // Color dimmable light
#define DEV_ID_HA_ONOFF_LIGHT_SWITCH        0x0103 // On/Off light switch
#define DEV_ID_HA_DIMMER_SWITCH             0x0104 // Dimmer switch
#define DEV_ID_HA_LIGHT_SENSOR              0x0106 // Light sensor
#define DEV_ID_HA_OCCUPANCY_SENSOR          0x0107 // Occupancy sensor

//
#define DEV_ID_IAS_ZONE                     0x0402 // IAS Zone
// Smart Energy devices
#define DEV_ID_SE_METERING_DEVICE           0x0501 // Smart Energy metering device

// ZLL lighting devices
#define DEV_ID_ZLL_ONOFF_LIGHT              0x0000 // On/Off light
#define DEV_ID_ZLL_ONOFF_PLUGIN_UNIT        0x0010 // On/Off plugin unit
#define DEV_ID_ZLL_DIMMABLE_LIGHT           0x0100 // Dimmable light
#define DEV_ID_ZLL_DIMMABLE_PLUGIN_UNIT     0x0110 // Dimmable plugin unit
#define DEV_ID_ZLL_COLOR_LIGHT              0x0200 // Color light
#define DEV_ID_ZLL_EXTENDED_COLOR_LIGHT     0x0210 // Extended color light
#define DEV_ID_ZLL_COLOR_TEMPERATURE_LIGHT  0x0220 // Color temperature light
// ZigBee 3.0 lighting devices
#define DEV_ID_Z30_ONOFF_PLUGIN_UNIT        0x010a // On/Off plugin unit
#define DEV_ID_Z30_DIMMABLE_PLUGIN_UNIT     0x010b // Dimmable plugin unit
#define DEV_ID_Z30_COLOR_TEMPERATURE_LIGHT  0x010c // Color temperature light
#define DEV_ID_Z30_EXTENDED_COLOR_LIGHT     0x010d // Extended color light
// ZLL controller devices
#define DEV_ID_ZLL_COLOR_CONTROLLER         0x0800 // Color controller
#define DEV_ID_ZLL_COLOR_SCENE_CONTROLLER   0x0810 // Color scene controller
#define DEV_ID_ZLL_NON_COLOR_CONTROLLER     0x0820 // Non color controller
#define DEV_ID_ZLL_NON_COLOR_SCENE_CONTROLLER 0x0830 // Non color scene controller
#define DEV_ID_ZLL_CONTROL_BRIDGE           0x0840 // Control bridge
#define DEV_ID_ZLL_ONOFF_SENSOR             0x0850 // On/Off sensor

#define DEFAULT_TRANSITION_TIME 4 // 400ms
#define MAX_ENHANCED_HUE 65535
#define MAX_ENHANCED_HUE_Z 65278 // max supportet ehue of all devices

#define BASIC_CLUSTER_ID                      0x0000
#define POWER_CONFIGURATION_CLUSTER_ID        0x0001
#define IDENTIFY_CLUSTER_ID                   0x0003
#define GROUP_CLUSTER_ID                      0x0004
#define SCENE_CLUSTER_ID                      0x0005
#define ONOFF_CLUSTER_ID                      0x0006
#define ONOFF_SWITCH_CONFIGURATION_CLUSTER_ID 0x0007
#define LEVEL_CLUSTER_ID                      0x0008
#define ANALOG_INPUT_CLUSTER_ID               0x000C
#define MULTISTATE_INPUT_CLUSTER_ID           0x0012
#define OTAU_CLUSTER_ID                       0x0019
#define GREEN_POWER_CLUSTER_ID                0x0021
#define COLOR_CLUSTER_ID                      0x0300
#define ILLUMINANCE_MEASUREMENT_CLUSTER_ID    0x0400
#define ILLUMINANCE_LEVEL_SENSING_CLUSTER_ID  0x0401
#define TEMPERATURE_MEASUREMENT_CLUSTER_ID    0x0402
#define PRESSURE_MEASUREMENT_CLUSTER_ID       0x0403
#define RELATIVE_HUMIDITY_CLUSTER_ID          0x0405
#define OCCUPANCY_SENSING_CLUSTER_ID          0x0406
#define IAS_ZONE_CLUSTER_ID                   0x0500
#define IAS_WD_CLUSTER_ID                     0x0502
#define ELECTRICAL_MEASUREMENT_CLUSTER_ID     0x0B04
#define COMMISSIONING_CLUSTER_ID              0x1000
#define DE_CLUSTER_ID                         0xFC00
#define VENDOR_CLUSTER_ID                     0xFC00

#define GREEN_POWER_ENDPOINT 0xf2

#define ONOFF_COMMAND_OFF     0x00
#define ONOFF_COMMAND_ON      0x01
#define ONOFF_COMMAND_TOGGLE  0x02
#define ONOFF_COMMAND_OFF_WITH_EFFECT  0x040
#define ONOFF_COMMAND_ON_WITH_TIMED_OFF  0x42
#define LEVEL_COMMAND_MOVE_TO_LEVEL 0x00
#define LEVEL_COMMAND_MOVE 0x01
#define LEVEL_COMMAND_STEP 0x02
#define LEVEL_COMMAND_STOP 0x03
#define LEVEL_COMMAND_MOVE_TO_LEVEL_WITH_ON_OFF 0x04
#define LEVEL_COMMAND_MOVE_WITH_ON_OFF 0x05
#define LEVEL_COMMAND_STEP_WITH_ON_OFF 0x06
#define LEVEL_COMMAND_STOP_WITH_ON_OFF 0x07
#define SCENE_COMMAND_RECALL_SCENE 0x05
#define SCENE_COMMAND_IKEA_STEP_CT 0x07
#define SCENE_COMMAND_IKEA_MOVE_CT 0x08
#define SCENE_COMMAND_IKEA_STOP_CT 0x09

// read flags
#define READ_MODEL_ID          (1 << 0)<commit_msg>IAS Zone Types<commit_after>/*
 * Copyright (c) 2017-2018 dresden elektronik ingenieurtechnik gmbh.
 * All rights reserved.
 *
 * The software in this package is published under the terms of the BSD
 * style license a copy of which has been included with this distribution in
 * the LICENSE.txt file.
 *
 */

#ifndef DE_WEB_PLUGIN_PRIVATE_H
#define DE_WEB_PLUGIN_PRIVATE_H
#include <QtGlobal>
#include <QObject>
#include <QTime>
#include <QTimer>
#include <QElapsedTimer>
#include <stdint.h>
#include <queue>
#if QT_VERSION < 0x050000
#include <QHttpRequestHeader>
#endif
#include "sqlite3.h"
#include <deconz.h>
#include "resource.h"
#include "event.h"
#include "resource.h"
#include "rest_node_base.h"
#include "light_node.h"
#include "group.h"
#include "group_info.h"
#include "scene.h"
#include "sensor.h"
#include "resourcelinks.h"
#include "rule.h"
#include "bindings.h"
#include <math.h>
#include "websocket_server.h"

/*! JSON generic error message codes */
#define ERR_UNAUTHORIZED_USER          1
#define ERR_INVALID_JSON               2
#define ERR_RESOURCE_NOT_AVAILABLE     3
#define ERR_METHOD_NOT_AVAILABLE       4
#define ERR_MISSING_PARAMETER          5
#define ERR_PARAMETER_NOT_AVAILABLE    6
#define ERR_INVALID_VALUE              7
#define ERR_PARAMETER_NOT_MODIFIEABLE  8
#define ERR_TOO_MANY_ITEMS             11
#define ERR_DUPLICATE_EXIST            100 // de extension
#define ERR_NOT_ALLOWED_SENSOR_TYPE    501
#define ERR_SENSOR_LIST_FULL           502
#define ERR_RULE_ENGINE_FULL           601
#define ERR_CONDITION_ERROR            607
#define ERR_ACTION_ERROR               608
#define ERR_INTERNAL_ERROR             901

#define ERR_NOT_CONNECTED              950 // de extension
#define ERR_BRIDGE_BUSY                951 // de extension

#define ERR_LINK_BUTTON_NOT_PRESSED    101
#define ERR_DEVICE_OFF                 201
#define ERR_BRIDGE_GROUP_TABLE_FULL    301
#define ERR_DEVICE_GROUP_TABLE_FULL    302

#define ERR_DEVICE_SCENES_TABLE_FULL   402 // de extension

#define IDLE_LIMIT 30
#define IDLE_READ_LIMIT 120
#define IDLE_USER_LIMIT 20
#define IDLE_ATTR_REPORT_BIND_LIMIT 240
#define BUTTON_ATTR_REPORT_BIND_LIMIT 120
#define WARMUP_TIME 120

#define MAX_UNLOCK_GATEWAY_TIME 600
#define PERMIT_JOIN_SEND_INTERVAL (1000 * 1800)
#define EXT_PROCESS_TIMEOUT 10000
#define SET_ENDPOINTCONFIG_DURATION (1000 * 16) // time deCONZ needs to update Endpoints
#define OTA_LOW_PRIORITY_TIME (60 * 2)
#define CHECK_SENSOR_FAST_ROUNDS 3
#define CHECK_SENSOR_FAST_INTERVAL 100
#define CHECK_SENSOR_INTERVAL      1000
#define CHECK_SENSORS_MAX          10

#define DE_OTAU_ENDPOINT             0x50
#define DE_PROFILE_ID              0xDE00
#define ATMEL_WSNDEMO_PROFILE_ID   0x0001

// Generic devices
#define DEV_ID_ONOFF_SWITCH                 0x0000 // On/Off switch
#define DEV_ID_LEVEL_CONTROL_SWITCH         0x0001 // Level control switch
#define DEV_ID_ONOFF_OUTPUT                 0x0002 // On/Off output
#define DEV_ID_RANGE_EXTENDER               0x0008 // Range extender
#define DEV_ID_MAINS_POWER_OUTLET           0x0009 // Mains power outlet
#define DEV_ID_SMART_PLUG                   0x0051 // Smart plug
// HA lighting devices
#define DEV_ID_HA_ONOFF_LIGHT               0x0100 // On/Off light
#define DEV_ID_HA_DIMMABLE_LIGHT            0x0101 // Dimmable light
#define DEV_ID_HA_COLOR_DIMMABLE_LIGHT      0x0102 // Color dimmable light
#define DEV_ID_HA_ONOFF_LIGHT_SWITCH        0x0103 // On/Off light switch
#define DEV_ID_HA_DIMMER_SWITCH             0x0104 // Dimmer switch
#define DEV_ID_HA_LIGHT_SENSOR              0x0106 // Light sensor
#define DEV_ID_HA_OCCUPANCY_SENSOR          0x0107 // Occupancy sensor

//
#define DEV_ID_IAS_ZONE                     0x0402 // IAS Zone
// Smart Energy devices
#define DEV_ID_SE_METERING_DEVICE           0x0501 // Smart Energy metering device

// ZLL lighting devices
#define DEV_ID_ZLL_ONOFF_LIGHT              0x0000 // On/Off light
#define DEV_ID_ZLL_ONOFF_PLUGIN_UNIT        0x0010 // On/Off plugin unit
#define DEV_ID_ZLL_DIMMABLE_LIGHT           0x0100 // Dimmable light
#define DEV_ID_ZLL_DIMMABLE_PLUGIN_UNIT     0x0110 // Dimmable plugin unit
#define DEV_ID_ZLL_COLOR_LIGHT              0x0200 // Color light
#define DEV_ID_ZLL_EXTENDED_COLOR_LIGHT     0x0210 // Extended color light
#define DEV_ID_ZLL_COLOR_TEMPERATURE_LIGHT  0x0220 // Color temperature light
// ZigBee 3.0 lighting devices
#define DEV_ID_Z30_ONOFF_PLUGIN_UNIT        0x010a // On/Off plugin unit
#define DEV_ID_Z30_DIMMABLE_PLUGIN_UNIT     0x010b // Dimmable plugin unit
#define DEV_ID_Z30_COLOR_TEMPERATURE_LIGHT  0x010c // Color temperature light
#define DEV_ID_Z30_EXTENDED_COLOR_LIGHT     0x010d // Extended color light
// ZLL controller devices
#define DEV_ID_ZLL_COLOR_CONTROLLER         0x0800 // Color controller
#define DEV_ID_ZLL_COLOR_SCENE_CONTROLLER   0x0810 // Color scene controller
#define DEV_ID_ZLL_NON_COLOR_CONTROLLER     0x0820 // Non color controller
#define DEV_ID_ZLL_NON_COLOR_SCENE_CONTROLLER 0x0830 // Non color scene controller
#define DEV_ID_ZLL_CONTROL_BRIDGE           0x0840 // Control bridge
#define DEV_ID_ZLL_ONOFF_SENSOR             0x0850 // On/Off sensor

#define DEFAULT_TRANSITION_TIME 4 // 400ms
#define MAX_ENHANCED_HUE 65535
#define MAX_ENHANCED_HUE_Z 65278 // max supportet ehue of all devices

#define BASIC_CLUSTER_ID                      0x0000
#define POWER_CONFIGURATION_CLUSTER_ID        0x0001
#define IDENTIFY_CLUSTER_ID                   0x0003
#define GROUP_CLUSTER_ID                      0x0004
#define SCENE_CLUSTER_ID                      0x0005
#define ONOFF_CLUSTER_ID                      0x0006
#define ONOFF_SWITCH_CONFIGURATION_CLUSTER_ID 0x0007
#define LEVEL_CLUSTER_ID                      0x0008
#define ANALOG_INPUT_CLUSTER_ID               0x000C
#define MULTISTATE_INPUT_CLUSTER_ID           0x0012
#define OTAU_CLUSTER_ID                       0x0019
#define GREEN_POWER_CLUSTER_ID                0x0021
#define COLOR_CLUSTER_ID                      0x0300
#define ILLUMINANCE_MEASUREMENT_CLUSTER_ID    0x0400
#define ILLUMINANCE_LEVEL_SENSING_CLUSTER_ID  0x0401
#define TEMPERATURE_MEASUREMENT_CLUSTER_ID    0x0402
#define PRESSURE_MEASUREMENT_CLUSTER_ID       0x0403
#define RELATIVE_HUMIDITY_CLUSTER_ID          0x0405
#define OCCUPANCY_SENSING_CLUSTER_ID          0x0406
#define IAS_ZONE_CLUSTER_ID                   0x0500
#define IAS_WD_CLUSTER_ID                     0x0502
#define ELECTRICAL_MEASUREMENT_CLUSTER_ID     0x0B04
#define COMMISSIONING_CLUSTER_ID              0x1000
#define DE_CLUSTER_ID                         0xFC00
#define VENDOR_CLUSTER_ID                     0xFC00

#define GREEN_POWER_ENDPOINT 0xf2

#define ONOFF_COMMAND_OFF     0x00
#define ONOFF_COMMAND_ON      0x01
#define ONOFF_COMMAND_TOGGLE  0x02
#define ONOFF_COMMAND_OFF_WITH_EFFECT  0x040
#define ONOFF_COMMAND_ON_WITH_TIMED_OFF  0x42
#define LEVEL_COMMAND_MOVE_TO_LEVEL 0x00
#define LEVEL_COMMAND_MOVE 0x01
#define LEVEL_COMMAND_STEP 0x02
#define LEVEL_COMMAND_STOP 0x03
#define LEVEL_COMMAND_MOVE_TO_LEVEL_WITH_ON_OFF 0x04
#define LEVEL_COMMAND_MOVE_WITH_ON_OFF 0x05
#define LEVEL_COMMAND_STEP_WITH_ON_OFF 0x06
#define LEVEL_COMMAND_STOP_WITH_ON_OFF 0x07
#define SCENE_COMMAND_RECALL_SCENE 0x05
#define SCENE_COMMAND_IKEA_STEP_CT 0x07
#define SCENE_COMMAND_IKEA_MOVE_CT 0x08
#define SCENE_COMMAND_IKEA_STOP_CT 0x09

// IAS Zone Types
#define IAS_ZONE_TYPE_STANDARD_CIE            0x0000
#define IAS_ZONE_TYPE_MOTION_SENSOR           0x000d
#define IAS_ZONE_TYPE_CONTACT_SWITCH          0x0015
#define IAS_ZONE_TYPE_FIRE_SENSOR             0x0028
#define IAS_ZONE_TYPE_WATER_SENSOR            0x002a
#define IAS_ZONE_TYPE_CARBON_MONOXIDE_SENSOR  0x002b
#define IAS_ZONE_TYPE_WARNING_DEVICE          0x0225

// read flags
#define READ_MODEL_ID          (1 << 0)
{'fraction_non_alphanumeric': 0.047412375879529164, 'fraction_numerical': 0.06589070822647465, 'mean_word_length': 3.3776626367299944, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7212693', 'n_tokens_mistral': 6169, 'n_tokens_neox': 5506, 'n_words': 1201}