UNPKG

iobroker.esphome

Version:

Control your ESP8266/ESP32 with simple yet powerful configuration files created and managed by ESPHome

114 lines (109 loc) 4.89 kB
/** * @module class */ /** * Device Info a device status object to manage connections and relations * @returns {Object} ip IP-Address of device // * @param {string} apiPassword API password of device // * @param {boolean} encryptionKeyUsed Indicated if encryption must be used // * @param {string} encryptionKey Encryption key of device // * @param {string | undefined} [macAddress] MAC-Address of a device // * @param {string | undefined} [deviceName] Name of a device (MAC address without ":") // * @param {string | undefined} [deviceFriendlyName] Friendly name of a device taken from YAML configuration */ class DeviceInfo { //ToDO: this object should have deeper typ-definition to ensure code & module events are verified adapterObjects = { channels : [] }; /** @type {object | null} */ client= null; /** @type {boolean} */ connected = false; /** @type {boolean} */ connecting = false; /** @type {boolean} */ connectionError = false; /** @type {string} */ connectStatus = 'Initialisation needed'; /** @type {boolean} */ deletionRequested = false; /** @type {string | null} */ deviceFriendlyName = null; /** @type {object | null} */ deviceInfo = null; /** @type {string | null} */ deviceName= null; /** @type {boolean} */ initialized = false; /** @type {string | null} */ ip= null; /** @type {string | null} */ mac= null; } /** * Client detail object to handle all relevant information for connection status * @param {string | undefined} ip IP-Address of device * @param {string} apiPassword API password of device * @param {boolean} encryptionKeyUsed Indicated if encryption must be used * @param {string} encryptionKey Encryption key of device * @param {string | undefined} [macAddress] MAC-Address of a device * @param {string | undefined} [deviceName] Name of a device (MAC address without ":") * @param {string | undefined} [deviceFriendlyName] Friendly name of a device taken from YAML configuration */ class ClientDetails extends DeviceInfo{ /** * Store mandatory connection details * @param {string} ip IP-Address of device * @param {boolean} encryptionKeyUsed Indicated if encryption must be used * @param {string} [apiPassword] API password of device * @param {string} [encryptionKey] Encryption key of device * @param {string | undefined} [macAddress] MAC-Address of a device * @param {string | undefined} [deviceName] Name of a device (MAC address without ":") * @param {string | undefined} [deviceFriendlyName] Friendly name of a device taken from YAML configuration */ storeConnectDetails (ip, encryptionKeyUsed, apiPassword, encryptionKey, macAddress, deviceName, deviceFriendlyName){ this.apiPassword = apiPassword; this.deviceFriendlyName = deviceFriendlyName ? deviceFriendlyName : 'Initialisation needed'; this.deviceName = deviceName ? deviceName : 'Initialisation needed'; this.ip = ip; this.mac = macAddress = macAddress ? macAddress : 'Initialisation needed'; this.encryptionKey = encryptionKey; this.encryptionKeyUsed = encryptionKeyUsed ? encryptionKeyUsed : false; } /** * Store mandatory connection details of already known device * @param {string} ip IP-Address of device * @param {string} macAddress MAC-Address of a device * @param {string} deviceName Name of a device (MAC address without ":") * @param {string} deviceFriendlyName Friendly name of a device taken from YAML configuration */ storeDiscoveredDevice (ip, macAddress, deviceName, deviceFriendlyName){ this.connectStatus = 'newly discovered'; this.deviceFriendlyName = deviceFriendlyName; this.deviceName = deviceName; this.ip = ip; this.mac = macAddress; } /** * Store mandatory connection details of already known device * @param {string} ip IP-Address of device * @param {boolean} encryptionKeyUsed Indicated if encryption must be used * @param {string | undefined} macAddress MAC-Address of a device * @param {string | undefined} deviceName Name of a device (MAC address without ":") * @param {string | undefined} deviceFriendlyName Friendly name of a device taken from YAML configuration * @param {string} [apiPassword] API password of device * @param {string} [encryptionKey] Encryption key of device */ storeExistingDetails (ip, encryptionKeyUsed, macAddress, deviceName, deviceFriendlyName, apiPassword, encryptionKey){ this.apiPassword = !encryptionKeyUsed ? apiPassword : null; this.deviceFriendlyName = deviceFriendlyName ? deviceFriendlyName : 'Initialisation needed'; this.deviceName = deviceName ? deviceName : 'Initialisation needed'; this.ip = ip; this.mac = macAddress = macAddress ? macAddress : 'Initialisation needed'; this.encryptionKey = encryptionKeyUsed ? encryptionKey : null; this.encryptionKeyUsed = encryptionKeyUsed ? encryptionKeyUsed : false; } } module.exports = ClientDetails; //# sourceMappingURL=helpers.js.map