hoffmation-base 0.1.14 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +2 -0
- package/lib/index.js +14 -0
- package/lib/models/actuatorSettings.d.ts +5 -0
- package/lib/models/actuatorSettings.js +11 -0
- package/lib/models/connectionCallbacks.d.ts +10 -0
- package/lib/models/connectionCallbacks.js +6 -0
- package/lib/models/daytime.d.ts +5 -0
- package/lib/models/daytime.js +10 -0
- package/lib/models/deviceConfig.d.ts +11 -0
- package/lib/models/deviceConfig.js +2 -0
- package/lib/models/dimmerSettings.d.ts +5 -0
- package/lib/models/dimmerSettings.js +11 -0
- package/lib/models/iTemperaturDataPoint.d.ts +9 -0
- package/lib/models/iTemperaturDataPoint.js +2 -0
- package/lib/models/index.d.ts +12 -0
- package/lib/models/index.js +24 -0
- package/lib/models/ledSettings.d.ts +19 -0
- package/lib/models/ledSettings.js +25 -0
- package/lib/models/logLevel.d.ts +9 -0
- package/lib/models/logLevel.js +13 -0
- package/lib/models/persistence/BasicRoomInfo.d.ts +5 -0
- package/lib/models/persistence/BasicRoomInfo.js +10 -0
- package/lib/models/persistence/CurrentIlluminationDataPoint.d.ts +8 -0
- package/lib/models/persistence/CurrentIlluminationDataPoint.js +13 -0
- package/lib/models/persistence/DailyMovementCount.d.ts +7 -0
- package/lib/models/persistence/DailyMovementCount.js +12 -0
- package/lib/models/persistence/RoomDetailInfo.d.ts +6 -0
- package/lib/models/persistence/RoomDetailInfo.js +11 -0
- package/lib/models/persistence/index.d.ts +6 -0
- package/lib/models/persistence/index.js +18 -0
- package/lib/models/persistence/temperaturDataPoint.d.ts +10 -0
- package/lib/models/persistence/temperaturDataPoint.js +14 -0
- package/lib/models/persistence/todaysCount.d.ts +5 -0
- package/lib/models/persistence/todaysCount.js +10 -0
- package/lib/models/rooms/RoomBase.d.ts +81 -0
- package/lib/models/rooms/RoomBase.js +309 -0
- package/lib/models/rooms/RoomSettings/RoomSettings.d.ts +57 -0
- package/lib/models/rooms/RoomSettings/RoomSettings.js +120 -0
- package/lib/models/rooms/RoomSettings/hmIPRoomSettings.d.ts +17 -0
- package/lib/models/rooms/RoomSettings/hmIPRoomSettings.js +51 -0
- package/lib/models/rooms/RoomSettings/iRoomDefaultSettings.d.ts +16 -0
- package/lib/models/rooms/RoomSettings/iRoomDefaultSettings.js +2 -0
- package/lib/models/rooms/RoomSettings/index.d.ts +4 -0
- package/lib/models/rooms/RoomSettings/index.js +16 -0
- package/lib/models/rooms/RoomSettings/zigbeeRoomSettings.d.ts +17 -0
- package/lib/models/rooms/RoomSettings/zigbeeRoomSettings.js +51 -0
- package/{models/rooms/iRoomImportEnforcer.ts → lib/models/rooms/iRoomImportEnforcer.d.ts} +1 -1
- package/lib/models/rooms/iRoomImportEnforcer.js +2 -0
- package/lib/models/rooms/index.d.ts +3 -0
- package/lib/models/rooms/index.js +15 -0
- package/lib/models/temperaturSettings.d.ts +9 -0
- package/lib/models/temperaturSettings.js +21 -0
- package/lib/models/timeCallback.d.ts +19 -0
- package/lib/models/timeCallback.js +73 -0
- package/lib/server/config/iConfig.d.ts +45 -0
- package/lib/server/config/iConfig.js +2 -0
- package/lib/server/config/index.d.ts +1 -0
- package/lib/server/config/index.js +13 -0
- package/lib/server/devices/DeviceInfo.d.ts +17 -0
- package/lib/server/devices/DeviceInfo.js +48 -0
- package/lib/server/devices/Griffe.d.ts +5 -0
- package/lib/server/devices/Griffe.js +31 -0
- package/lib/server/devices/Heizgruppen.d.ts +8 -0
- package/lib/server/devices/Heizgruppen.js +78 -0
- package/lib/server/devices/Rollos.d.ts +5 -0
- package/lib/server/devices/Rollos.js +43 -0
- package/lib/server/devices/deviceUpdater.d.ts +13 -0
- package/lib/server/devices/deviceUpdater.js +64 -0
- package/lib/server/devices/devices.d.ts +21 -0
- package/lib/server/devices/devices.js +172 -0
- package/lib/server/devices/groups/fensterGroup.d.ts +15 -0
- package/lib/server/devices/groups/fensterGroup.js +138 -0
- package/lib/server/devices/groups/heatGroup.d.ts +9 -0
- package/lib/server/devices/groups/heatGroup.js +33 -0
- package/lib/server/devices/groups/index.d.ts +8 -0
- package/lib/server/devices/groups/index.js +20 -0
- package/lib/server/devices/groups/lampenGroup.d.ts +18 -0
- package/lib/server/devices/groups/lampenGroup.js +95 -0
- package/lib/server/devices/groups/praesenzGroup.d.ts +18 -0
- package/lib/server/devices/groups/praesenzGroup.js +145 -0
- package/lib/server/devices/groups/smokeGroup.d.ts +8 -0
- package/lib/server/devices/groups/smokeGroup.js +18 -0
- package/lib/server/devices/groups/sonosGroup.d.ts +11 -0
- package/lib/server/devices/groups/sonosGroup.js +38 -0
- package/lib/server/devices/groups/tasterGroup.d.ts +8 -0
- package/lib/server/devices/groups/tasterGroup.js +43 -0
- package/lib/server/devices/groups/waterGroup.d.ts +8 -0
- package/lib/server/devices/groups/waterGroup.js +18 -0
- package/lib/server/devices/hmIPDevices/Fenster.d.ts +22 -0
- package/lib/server/devices/hmIPDevices/Fenster.js +100 -0
- package/lib/server/devices/hmIPDevices/FensterPosition.d.ts +5 -0
- package/lib/server/devices/hmIPDevices/FensterPosition.js +9 -0
- package/lib/server/devices/hmIPDevices/TuerPosition.d.ts +4 -0
- package/lib/server/devices/hmIPDevices/TuerPosition.js +8 -0
- package/lib/server/devices/hmIPDevices/hmIpBewegung.d.ts +25 -0
- package/lib/server/devices/hmIPDevices/hmIpBewegung.js +106 -0
- package/lib/server/devices/hmIPDevices/hmIpDevice.d.ts +19 -0
- package/lib/server/devices/hmIPDevices/hmIpDevice.js +72 -0
- package/lib/server/devices/hmIPDevices/hmIpDeviceType.d.ts +14 -0
- package/lib/server/devices/hmIPDevices/hmIpDeviceType.js +18 -0
- package/lib/server/devices/hmIPDevices/hmIpGriff.d.ts +22 -0
- package/lib/server/devices/hmIPDevices/hmIpGriff.js +117 -0
- package/lib/server/devices/hmIPDevices/hmIpHeizgruppe.d.ts +34 -0
- package/lib/server/devices/hmIPDevices/hmIpHeizgruppe.js +143 -0
- package/lib/server/devices/hmIPDevices/hmIpHeizung.d.ts +15 -0
- package/lib/server/devices/hmIPDevices/hmIpHeizung.js +54 -0
- package/lib/server/devices/hmIPDevices/hmIpLampe.d.ts +27 -0
- package/lib/server/devices/hmIPDevices/hmIpLampe.js +96 -0
- package/lib/server/devices/hmIPDevices/hmIpPraezenz.d.ts +22 -0
- package/lib/server/devices/hmIPDevices/hmIpPraezenz.js +89 -0
- package/lib/server/devices/hmIPDevices/hmIpRoll.d.ts +22 -0
- package/lib/server/devices/hmIPDevices/hmIpRoll.js +105 -0
- package/lib/server/devices/hmIPDevices/hmIpTaster.d.ts +13 -0
- package/lib/server/devices/hmIPDevices/hmIpTaster.js +78 -0
- package/lib/server/devices/hmIPDevices/hmIpTherm.d.ts +7 -0
- package/lib/server/devices/hmIPDevices/hmIpTherm.js +17 -0
- package/lib/server/devices/hmIPDevices/hmIpTuer.d.ts +16 -0
- package/lib/server/devices/hmIPDevices/hmIpTuer.js +94 -0
- package/lib/server/devices/hmIPDevices/hmIpWippe.d.ts +12 -0
- package/lib/server/devices/hmIPDevices/hmIpWippe.js +50 -0
- package/lib/server/devices/hmIPDevices/index.d.ts +16 -0
- package/lib/server/devices/hmIPDevices/index.js +28 -0
- package/lib/server/devices/iDeviceUpdater.d.ts +5 -0
- package/lib/server/devices/iDeviceUpdater.js +2 -0
- package/{server/devices/iIlluminationSensor.ts → lib/server/devices/iIlluminationSensor.d.ts} +1 -1
- package/lib/server/devices/iIlluminationSensor.js +2 -0
- package/lib/server/devices/iIoBrokerDevice.d.ts +30 -0
- package/lib/server/devices/iIoBrokerDevice.js +37 -0
- package/lib/server/devices/iLamp.d.ts +8 -0
- package/lib/server/devices/iLamp.js +2 -0
- package/lib/server/devices/iTaster.d.ts +7 -0
- package/lib/server/devices/iTaster.js +2 -0
- package/lib/server/devices/index.d.ts +16 -0
- package/lib/server/devices/index.js +28 -0
- package/lib/server/devices/taste.d.ts +15 -0
- package/lib/server/devices/taste.js +64 -0
- package/lib/server/devices/wledDevice.d.ts +38 -0
- package/lib/server/devices/wledDevice.js +97 -0
- package/lib/server/devices/zigbee/ZigbeeActuator.d.ts +17 -0
- package/lib/server/devices/zigbee/ZigbeeActuator.js +83 -0
- package/lib/server/devices/zigbee/index.d.ts +13 -0
- package/lib/server/devices/zigbee/index.js +25 -0
- package/lib/server/devices/zigbee/zigbeeAquaraMotion.d.ts +31 -0
- package/lib/server/devices/zigbee/zigbeeAquaraMotion.js +137 -0
- package/lib/server/devices/zigbee/zigbeeAquaraVibra.d.ts +23 -0
- package/lib/server/devices/zigbee/zigbeeAquaraVibra.js +121 -0
- package/lib/server/devices/zigbee/zigbeeAquaraWater.d.ts +18 -0
- package/lib/server/devices/zigbee/zigbeeAquaraWater.js +84 -0
- package/lib/server/devices/zigbee/zigbeeBlitzShp.d.ts +16 -0
- package/lib/server/devices/zigbee/zigbeeBlitzShp.js +64 -0
- package/lib/server/devices/zigbee/zigbeeDevice.d.ts +20 -0
- package/lib/server/devices/zigbee/zigbeeDevice.js +83 -0
- package/lib/server/devices/zigbee/zigbeeDeviceType.d.ts +14 -0
- package/lib/server/devices/zigbee/zigbeeDeviceType.js +18 -0
- package/lib/server/devices/zigbee/zigbeeHeimanSmoke.d.ts +18 -0
- package/lib/server/devices/zigbee/zigbeeHeimanSmoke.js +89 -0
- package/lib/server/devices/zigbee/zigbeeIkeaSteckdose.d.ts +10 -0
- package/lib/server/devices/zigbee/zigbeeIkeaSteckdose.js +26 -0
- package/lib/server/devices/zigbee/zigbeeIlluActuator.d.ts +11 -0
- package/lib/server/devices/zigbee/zigbeeIlluActuator.js +28 -0
- package/lib/server/devices/zigbee/zigbeeIlluDimmer.d.ts +23 -0
- package/lib/server/devices/zigbee/zigbeeIlluDimmer.js +128 -0
- package/lib/server/devices/zigbee/zigbeeIlluLampe.d.ts +10 -0
- package/lib/server/devices/zigbee/zigbeeIlluLampe.js +31 -0
- package/lib/server/devices/zigbee/zigbeeIlluLedRGBCCT.d.ts +22 -0
- package/lib/server/devices/zigbee/zigbeeIlluLedRGBCCT.js +122 -0
- package/lib/server/index.d.ts +4 -0
- package/lib/server/index.js +16 -0
- package/lib/server/ioBroker/connection.d.ts +160 -0
- package/lib/server/ioBroker/connection.js +1419 -0
- package/lib/server/ioBroker/index.d.ts +6 -0
- package/lib/server/ioBroker/index.js +18 -0
- package/lib/server/ioBroker/ioBroker.main.d.ts +15 -0
- package/lib/server/ioBroker/ioBroker.main.js +85 -0
- package/lib/server/ioBroker/socketIOAuthInfo.d.ts +5 -0
- package/lib/server/ioBroker/socketIOAuthInfo.js +6 -0
- package/lib/server/ioBroker/socketIOConnectOptions.d.ts +6 -0
- package/lib/server/ioBroker/socketIOConnectOptions.js +6 -0
- package/lib/server/ioBroker/socketIOLogging.d.ts +12 -0
- package/lib/server/ioBroker/socketIOLogging.js +32 -0
- package/lib/server/ioBroker/socketIOVisCommand.d.ts +6 -0
- package/lib/server/ioBroker/socketIOVisCommand.js +11 -0
- package/lib/server/services/HTTPSOptions.d.ts +12 -0
- package/lib/server/services/HTTPSOptions.js +16 -0
- package/lib/server/services/Sonos/OwnSonosDevices.d.ts +7 -0
- package/lib/server/services/Sonos/OwnSonosDevices.js +10 -0
- package/lib/server/services/Sonos/index.d.ts +4 -0
- package/lib/server/services/Sonos/index.js +16 -0
- package/lib/server/services/Sonos/mp3-server.d.ts +7 -0
- package/lib/server/services/Sonos/mp3-server.js +90 -0
- package/lib/server/services/Sonos/polly-service.d.ts +12 -0
- package/lib/server/services/Sonos/polly-service.js +117 -0
- package/lib/server/services/Sonos/sonos-service.d.ts +30 -0
- package/lib/server/services/Sonos/sonos-service.js +140 -0
- package/lib/server/services/Telegram/index.d.ts +3 -0
- package/lib/server/services/Telegram/index.js +15 -0
- package/lib/server/services/Telegram/telegram-Commands.d.ts +3 -0
- package/lib/server/services/Telegram/telegram-Commands.js +128 -0
- package/lib/server/services/Telegram/telegram-service.d.ts +19 -0
- package/lib/server/services/Telegram/telegram-service.js +150 -0
- package/lib/server/services/Telegram/telegramMessageCalback.d.ts +9 -0
- package/lib/server/services/Telegram/telegramMessageCalback.js +13 -0
- package/lib/server/services/calendar/index.d.ts +2 -0
- package/lib/server/services/calendar/index.js +14 -0
- package/lib/server/services/calendar/muell-tonne.d.ts +12 -0
- package/lib/server/services/calendar/muell-tonne.js +73 -0
- package/lib/server/services/calendar/m/303/274ll-service.d.ts +24 -0
- package/lib/server/services/calendar/m/303/274ll-service.js +108 -0
- package/lib/server/services/dbo/index.d.ts +1 -0
- package/lib/server/services/dbo/index.js +13 -0
- package/lib/server/services/dbo/persist.d.ts +27 -0
- package/lib/server/services/dbo/persist.js +107 -0
- package/lib/server/services/https-service.d.ts +6 -0
- package/lib/server/services/https-service.js +87 -0
- package/lib/server/services/index.d.ts +12 -0
- package/lib/server/services/index.js +24 -0
- package/lib/server/services/log-service.d.ts +14 -0
- package/lib/server/services/log-service.js +41 -0
- package/lib/server/services/news-service.d.ts +10 -0
- package/lib/server/services/news-service.js +90 -0
- package/lib/server/services/settings-service.d.ts +6 -0
- package/lib/server/services/settings-service.js +19 -0
- package/lib/server/services/time-callback-service.d.ts +39 -0
- package/lib/server/services/time-callback-service.js +182 -0
- package/lib/server/services/utils/index.d.ts +2 -0
- package/lib/server/services/utils/index.js +14 -0
- package/lib/server/services/utils/ringstorage.d.ts +8 -0
- package/lib/server/services/utils/ringstorage.js +27 -0
- package/lib/server/services/utils/utils.d.ts +9 -0
- package/lib/server/services/utils/utils.js +44 -0
- package/lib/server/services/weather/index.d.ts +9 -0
- package/lib/server/services/weather/index.js +21 -0
- package/lib/server/services/weather/weather-alert.d.ts +7 -0
- package/lib/server/services/weather/weather-alert.js +2 -0
- package/lib/server/services/weather/weather-current.d.ts +25 -0
- package/lib/server/services/weather/weather-current.js +2 -0
- package/lib/server/services/weather/weather-daily.d.ts +21 -0
- package/lib/server/services/weather/weather-daily.js +2 -0
- package/lib/server/services/weather/weather-feelsLike.d.ts +6 -0
- package/lib/server/services/weather/weather-feelsLike.js +2 -0
- package/lib/server/services/weather/weather-hourly.d.ts +16 -0
- package/lib/server/services/weather/weather-hourly.js +2 -0
- package/lib/server/services/weather/weather-item.d.ts +6 -0
- package/lib/server/services/weather/weather-item.js +2 -0
- package/lib/server/services/weather/weather-minutes.d.ts +4 -0
- package/lib/server/services/weather/weather-minutes.js +2 -0
- package/lib/server/services/weather/weather-service.d.ts +37 -0
- package/lib/server/services/weather/weather-service.js +173 -0
- package/lib/server/services/weather/weather-temp.d.ts +8 -0
- package/lib/server/services/weather/weather-temp.js +2 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +21 -10
- package/.eslintrc.js +0 -27
- package/.github/workflows/npm-publish.yml +0 -33
- package/.prettierrc.js +0 -9
- package/index.js +0 -1
- package/models/actuatorSettings.ts +0 -5
- package/models/connectionCallbacks.ts +0 -13
- package/models/daytime.ts +0 -3
- package/models/deviceConfig.ts +0 -8
- package/models/dimmerSettings.ts +0 -5
- package/models/iTemperaturDataPoint.ts +0 -9
- package/models/ledSettings.ts +0 -19
- package/models/logLevel.ts +0 -9
- package/models/persistence/BasicRoomInfo.ts +0 -3
- package/models/persistence/CurrentIlluminationDataPoint.ts +0 -9
- package/models/persistence/DailyMovementCount.ts +0 -3
- package/models/persistence/RoomDetailInfo.ts +0 -4
- package/models/persistence/temperaturDataPoint.ts +0 -12
- package/models/persistence/todaysCount.ts +0 -3
- package/models/rooms/RoomBase.ts +0 -358
- package/models/rooms/RoomSettings/RoomSettings.ts +0 -159
- package/models/rooms/RoomSettings/hmIPRoomSettings.ts +0 -53
- package/models/rooms/RoomSettings/iRoomDefaultSettings.ts +0 -17
- package/models/rooms/RoomSettings/readme.md +0 -18
- package/models/rooms/RoomSettings/zigbeeRoomSettings.ts +0 -51
- package/models/rooms/readme.md +0 -11
- package/models/temperaturSettings.ts +0 -22
- package/models/timeCallback.ts +0 -90
- package/server/config/config-readme.md +0 -19
- package/server/config/iConfig.ts +0 -53
- package/server/config/private/mainConfig.json +0 -64
- package/server/devices/DeviceInfo.ts +0 -66
- package/server/devices/Griffe.ts +0 -31
- package/server/devices/Heizgruppen.ts +0 -91
- package/server/devices/Rollos.ts +0 -48
- package/server/devices/deviceUpdater.ts +0 -72
- package/server/devices/devices.ts +0 -193
- package/server/devices/groups/fensterGroup.ts +0 -175
- package/server/devices/groups/heatGroup.ts +0 -32
- package/server/devices/groups/lampenGroup.ts +0 -106
- package/server/devices/groups/praesenzGroup.ts +0 -187
- package/server/devices/groups/smokeGroup.ts +0 -16
- package/server/devices/groups/sonosGroup.ts +0 -33
- package/server/devices/groups/tasterGroup.ts +0 -48
- package/server/devices/groups/waterGroup.ts +0 -16
- package/server/devices/hmIPDevices/Fenster.ts +0 -114
- package/server/devices/hmIPDevices/FensterPosition.ts +0 -5
- package/server/devices/hmIPDevices/TuerPosition.ts +0 -4
- package/server/devices/hmIPDevices/hmIpBewegung.ts +0 -145
- package/server/devices/hmIPDevices/hmIpDevice.ts +0 -90
- package/server/devices/hmIPDevices/hmIpDeviceType.ts +0 -14
- package/server/devices/hmIPDevices/hmIpGriff.ts +0 -143
- package/server/devices/hmIPDevices/hmIpHeizgruppe.ts +0 -172
- package/server/devices/hmIPDevices/hmIpHeizung.ts +0 -69
- package/server/devices/hmIPDevices/hmIpLampe.ts +0 -120
- package/server/devices/hmIPDevices/hmIpPraezenz.ts +0 -117
- package/server/devices/hmIPDevices/hmIpRoll.ts +0 -133
- package/server/devices/hmIPDevices/hmIpTaster.ts +0 -82
- package/server/devices/hmIPDevices/hmIpTherm.ts +0 -19
- package/server/devices/hmIPDevices/hmIpTuer.ts +0 -115
- package/server/devices/hmIPDevices/hmIpWippe.ts +0 -55
- package/server/devices/iDeviceUpdater.ts +0 -4
- package/server/devices/iIoBrokerDevice.ts +0 -44
- package/server/devices/iLamp.ts +0 -10
- package/server/devices/iTaster.ts +0 -6
- package/server/devices/taste.ts +0 -84
- package/server/devices/wledDevice.ts +0 -124
- package/server/devices/zigbee/ZigbeeActuator.ts +0 -113
- package/server/devices/zigbee/zigbeeAquaraMotion.ts +0 -205
- package/server/devices/zigbee/zigbeeAquaraVibra.ts +0 -171
- package/server/devices/zigbee/zigbeeAquaraWater.ts +0 -94
- package/server/devices/zigbee/zigbeeBlitzShp.ts +0 -77
- package/server/devices/zigbee/zigbeeDevice.ts +0 -115
- package/server/devices/zigbee/zigbeeDeviceType.ts +0 -14
- package/server/devices/zigbee/zigbeeHeimanSmoke.ts +0 -99
- package/server/devices/zigbee/zigbeeIkeaSteckdose.ts +0 -31
- package/server/devices/zigbee/zigbeeIlluActuator.ts +0 -37
- package/server/devices/zigbee/zigbeeIlluDimmer.ts +0 -166
- package/server/devices/zigbee/zigbeeIlluLampe.ts +0 -33
- package/server/devices/zigbee/zigbeeIlluLedRGBCCT.ts +0 -137
- package/server/ioBroker/connection.ts +0 -1655
- package/server/ioBroker/ioBroker.main.ts +0 -99
- package/server/ioBroker/socketIOAuthInfo.ts +0 -5
- package/server/ioBroker/socketIOConnectOptions.ts +0 -6
- package/server/ioBroker/socketIOLogging.ts +0 -29
- package/server/ioBroker/socketIOVisCommand.ts +0 -11
- package/server/services/HTTPSOptions.ts +0 -14
- package/server/services/Sonos/OwnSonosDevices.ts +0 -9
- package/server/services/Sonos/mp3-server.ts +0 -75
- package/server/services/Sonos/polly-service.ts +0 -100
- package/server/services/Sonos/sonos-service.ts +0 -194
- package/server/services/Telegram/telegram-Commands.ts +0 -237
- package/server/services/Telegram/telegram-service.ts +0 -177
- package/server/services/Telegram/telegramMessageCalback.ts +0 -11
- package/server/services/calendar/muell-tonne.ts +0 -82
- package/server/services/calendar/m/303/274ll-service.ts +0 -147
- package/server/services/dbo/persist.ts +0 -142
- package/server/services/https-service.ts +0 -71
- package/server/services/log-service.ts +0 -69
- package/server/services/news-service.ts +0 -81
- package/server/services/settings-service.ts +0 -15
- package/server/services/time-callback-service.ts +0 -223
- package/server/services/utils/ringstorage.ts +0 -24
- package/server/services/utils/utils.ts +0 -52
- package/server/services/weather/weather-alert.ts +0 -7
- package/server/services/weather/weather-current.ts +0 -26
- package/server/services/weather/weather-daily.ts +0 -22
- package/server/services/weather/weather-feelsLike.ts +0 -6
- package/server/services/weather/weather-hourly.ts +0 -17
- package/server/services/weather/weather-item.ts +0 -6
- package/server/services/weather/weather-minutes.ts +0 -4
- package/server/services/weather/weather-service.ts +0 -277
- package/server/services/weather/weather-temp.ts +0 -8
- package/tsconfig.json +0 -58
|
@@ -0,0 +1,1419 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IOBrokerConnection = void 0;
|
|
7
|
+
const socketIOAuthInfo_1 = require("./socketIOAuthInfo");
|
|
8
|
+
const socketIOLogging_1 = require("./socketIOLogging");
|
|
9
|
+
const socketIOVisCommand_1 = require("./socketIOVisCommand");
|
|
10
|
+
const connectionCallbacks_1 = require("../../models/connectionCallbacks");
|
|
11
|
+
const socket_io_client_1 = __importDefault(require("socket.io-client"));
|
|
12
|
+
const utils_1 = require("../services/utils/utils");
|
|
13
|
+
let session;
|
|
14
|
+
let app;
|
|
15
|
+
let socketSession;
|
|
16
|
+
let storage;
|
|
17
|
+
const socketNamespace = '';
|
|
18
|
+
const socketUrl = '';
|
|
19
|
+
const socketForceWebSockets = true;
|
|
20
|
+
class IOBrokerConnection {
|
|
21
|
+
//#endregion
|
|
22
|
+
constructor(connOptions = {}, connCallbacks = new connectionCallbacks_1.ConnectionCallbacks(), objectsRequired = false) {
|
|
23
|
+
this._isExecutedInBrowser = false;
|
|
24
|
+
this._authInfo = new socketIOAuthInfo_1.SocketIOAuthInfo();
|
|
25
|
+
this._authRunning = false;
|
|
26
|
+
this._cmdQueue = new Array();
|
|
27
|
+
this._connCallbacks = new connectionCallbacks_1.ConnectionCallbacks();
|
|
28
|
+
this._cmdInstance = '';
|
|
29
|
+
this._countDown = 0;
|
|
30
|
+
this._defaultMode = 0x644;
|
|
31
|
+
this._isAuthDone = false;
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
this._isAuthRequired = false;
|
|
34
|
+
this._isConnected = false;
|
|
35
|
+
this._isSecure = false;
|
|
36
|
+
this._namespace = 'vis.0';
|
|
37
|
+
this._reconnectInterval = 10000; // reconnect interval
|
|
38
|
+
this._reloadInterval = 30; // if connection was absent longer than 30 seconds
|
|
39
|
+
this._type = 'socket.io'; // [SignalR | socket.io | local]
|
|
40
|
+
this._timeout = 0; // 0 - use transport default timeout to detect disconnect
|
|
41
|
+
this._user = '';
|
|
42
|
+
this._useStorage = false;
|
|
43
|
+
// init namespace
|
|
44
|
+
if (typeof socketNamespace !== 'undefined')
|
|
45
|
+
this.namespace = socketNamespace;
|
|
46
|
+
if (!connOptions.name)
|
|
47
|
+
connOptions.name = this.namespace;
|
|
48
|
+
// To start vis as local use one of:
|
|
49
|
+
// - start vis from directory with name local, e.g. c:/blbla/local/ioBroker.vis/www/index.html
|
|
50
|
+
// - do not create "_socket/info.js" file in "www" directory
|
|
51
|
+
// - create "_socket/info.js" file with
|
|
52
|
+
// var socketUrl = "local"; var socketSession = ""; sysLang="en";
|
|
53
|
+
// in this case you can overwrite browser language settings
|
|
54
|
+
if (this._isExecutedInBrowser &&
|
|
55
|
+
(document.URL.split('/local/')[1] ||
|
|
56
|
+
(typeof socketUrl === 'undefined' && !connOptions.connLink) ||
|
|
57
|
+
(typeof socketUrl !== 'undefined' && socketUrl === 'local'))) {
|
|
58
|
+
this._type = 'local';
|
|
59
|
+
}
|
|
60
|
+
if (typeof session !== 'undefined') {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
const user = session.get('user');
|
|
63
|
+
if (user) {
|
|
64
|
+
this._authInfo.user = user;
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
this._authInfo.hash = session.get('hash');
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
this._authInfo.salt = session.get('salt');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
this._connCallbacks = connCallbacks;
|
|
72
|
+
let connLink = connOptions.connLink;
|
|
73
|
+
if (!connOptions.connLink && this._isExecutedInBrowser) {
|
|
74
|
+
connLink = window.localStorage.getItem('connLink');
|
|
75
|
+
}
|
|
76
|
+
// Connection data from "/_socket/info.js"
|
|
77
|
+
if (!connLink && typeof socketUrl !== 'undefined')
|
|
78
|
+
connLink = socketUrl;
|
|
79
|
+
if (!connOptions.socketSession && typeof socketSession !== 'undefined')
|
|
80
|
+
connOptions.socketSession = socketSession;
|
|
81
|
+
if (connOptions.socketForceWebSockets === undefined && typeof socketForceWebSockets !== 'undefined') {
|
|
82
|
+
connOptions.socketForceWebSockets = socketForceWebSockets;
|
|
83
|
+
}
|
|
84
|
+
connOptions.socketSession = connOptions.socketSession || 'nokey';
|
|
85
|
+
let url;
|
|
86
|
+
if (connLink) {
|
|
87
|
+
url = connLink;
|
|
88
|
+
if (typeof connLink !== 'undefined') {
|
|
89
|
+
if (connLink[0] === ':')
|
|
90
|
+
connLink = location.protocol + '://' + location.hostname + connLink;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
url = location.protocol + '//' + location.host;
|
|
95
|
+
}
|
|
96
|
+
const opts = {
|
|
97
|
+
query: 'key=' + connOptions.socketSession,
|
|
98
|
+
reconnectionDelayMax: 10000,
|
|
99
|
+
reconnectionAttempts: Infinity,
|
|
100
|
+
reconnection: false,
|
|
101
|
+
upgrade: !connOptions.socketForceWebSockets,
|
|
102
|
+
rememberUpgrade: connOptions.socketForceWebSockets,
|
|
103
|
+
transports: connOptions.socketForceWebSockets ? ['websocket'] : undefined,
|
|
104
|
+
};
|
|
105
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Trace, `Going to create socket for url ${url}`);
|
|
106
|
+
console.log(opts);
|
|
107
|
+
this._socket = (0, socket_io_client_1.default)(url, opts);
|
|
108
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Trace, 'Created socket');
|
|
109
|
+
this._socket.on('connect', () => {
|
|
110
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Trace, 'In Connect callback');
|
|
111
|
+
if (this._disconnectedSince) {
|
|
112
|
+
const offlineTime = new Date().getTime() - this._disconnectedSince.getTime();
|
|
113
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'was offline for ' + offlineTime / 1000 + 's');
|
|
114
|
+
// reload whole page if no connection longer than some period
|
|
115
|
+
if (this._isExecutedInBrowser && this._reloadInterval && offlineTime > this._reloadInterval * 1000) {
|
|
116
|
+
window.location.reload();
|
|
117
|
+
}
|
|
118
|
+
this._disconnectedSince = undefined;
|
|
119
|
+
}
|
|
120
|
+
if (this._connectInterval) {
|
|
121
|
+
clearInterval(this._connectInterval);
|
|
122
|
+
this._connectInterval = undefined;
|
|
123
|
+
}
|
|
124
|
+
if (this._countInterval) {
|
|
125
|
+
clearInterval(this._countInterval);
|
|
126
|
+
this._countInterval = undefined;
|
|
127
|
+
}
|
|
128
|
+
if (this.isExecutedInBrowser) {
|
|
129
|
+
const elem = document.getElementById('server-disconnect');
|
|
130
|
+
if (elem)
|
|
131
|
+
elem.style.display = 'none';
|
|
132
|
+
}
|
|
133
|
+
this._socket.emit('name', connOptions.name);
|
|
134
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, new Date().toISOString() + ' Connected => authenticate');
|
|
135
|
+
utils_1.Utils.guardedTimeout(() => {
|
|
136
|
+
const wait = utils_1.Utils.guardedTimeout(() => {
|
|
137
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Error, 'No answer from server');
|
|
138
|
+
if (this._isExecutedInBrowser)
|
|
139
|
+
window.location.reload();
|
|
140
|
+
}, 3000, this);
|
|
141
|
+
this._socket.emit('authenticate', (isOk, isSecure) => {
|
|
142
|
+
clearTimeout(wait);
|
|
143
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, new Date().toISOString() + ' Authenticated: ' + isOk);
|
|
144
|
+
if (isOk) {
|
|
145
|
+
this._onAuth(objectsRequired, isSecure);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'permissionError');
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}, 50, this);
|
|
152
|
+
});
|
|
153
|
+
this._socket.on('reauthenticate', () => {
|
|
154
|
+
if (this._connCallbacks.onConnChange) {
|
|
155
|
+
this._connCallbacks.onConnChange(false);
|
|
156
|
+
if (typeof app !== 'undefined') {
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
app.onConnChange(false);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Warn, 'reauthenticate');
|
|
162
|
+
if (this._isExecutedInBrowser)
|
|
163
|
+
window.location.reload();
|
|
164
|
+
});
|
|
165
|
+
this._socket.on('connect_error', (err) => {
|
|
166
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Error, `Couldn't Connect --> Reconecting (Error: ${err})`);
|
|
167
|
+
this.reconnect(connOptions);
|
|
168
|
+
});
|
|
169
|
+
this._socket.on('disconnect', () => {
|
|
170
|
+
this._disconnectedSince = new Date();
|
|
171
|
+
// called only once when connection lost (and it was here before)
|
|
172
|
+
this._isConnected = false;
|
|
173
|
+
if (this._connCallbacks.onConnChange !== undefined) {
|
|
174
|
+
utils_1.Utils.guardedTimeout(() => {
|
|
175
|
+
if (typeof this._connCallbacks.onConnChange !== 'undefined') {
|
|
176
|
+
this._connCallbacks.onConnChange(this._isConnected);
|
|
177
|
+
}
|
|
178
|
+
if (typeof app !== 'undefined') {
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
app.onConnChange(this._isConnected);
|
|
181
|
+
}
|
|
182
|
+
}, 5000, this);
|
|
183
|
+
}
|
|
184
|
+
// reconnect
|
|
185
|
+
this.reconnect(connOptions);
|
|
186
|
+
});
|
|
187
|
+
// after reconnect the "connect" event will be called
|
|
188
|
+
this._socket.on('reconnect', () => {
|
|
189
|
+
var _a;
|
|
190
|
+
const discoSinceTime = this._disconnectedSince === undefined ? 0 : (_a = this._disconnectedSince) === null || _a === void 0 ? void 0 : _a.getTime();
|
|
191
|
+
const offlineTime = new Date().getTime() - discoSinceTime;
|
|
192
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Info, `was offline for ${offlineTime / 1000}s`);
|
|
193
|
+
// reload whole page if no connection longer than one minute
|
|
194
|
+
if (this._reloadInterval && offlineTime > this._reloadInterval * 1000) {
|
|
195
|
+
window.location.reload();
|
|
196
|
+
}
|
|
197
|
+
// anyway "on connect" is called
|
|
198
|
+
});
|
|
199
|
+
this._socket.on('objectChange', (id, obj) => {
|
|
200
|
+
// If cache used
|
|
201
|
+
if (this._useStorage && typeof storage !== 'undefined') {
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
const objects = this._objects || storage.get('objects');
|
|
204
|
+
if (objects) {
|
|
205
|
+
if (obj) {
|
|
206
|
+
objects[id] = obj;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
if (objects[id])
|
|
210
|
+
delete objects[id];
|
|
211
|
+
}
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
storage.set('objects', objects);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (this._connCallbacks.onObjectChange) {
|
|
217
|
+
this._connCallbacks.onObjectChange(id, obj);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
this._socket.on('stateChange', (id, state) => {
|
|
221
|
+
if (!id || state === null || typeof state !== 'object')
|
|
222
|
+
return;
|
|
223
|
+
if (this._connCallbacks.onCommand && id === this.namespace + '.control.command') {
|
|
224
|
+
if (state.ack)
|
|
225
|
+
return;
|
|
226
|
+
if (state.val &&
|
|
227
|
+
typeof state.val === 'string' &&
|
|
228
|
+
state.val[0] === '{' &&
|
|
229
|
+
state.val[state.val.length - 1] === '}') {
|
|
230
|
+
try {
|
|
231
|
+
state.val = JSON.parse(state.val);
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'Command seems to be an object, but cannot parse it: ' + state.val);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// if command is an object {instance: 'iii', command: 'cmd', data: 'ddd'}
|
|
238
|
+
// @ts-ignore
|
|
239
|
+
if (state.val && typeof state.val === 'object' && state.val.instance) {
|
|
240
|
+
// vis only:
|
|
241
|
+
const visCommand = new socketIOVisCommand_1.SocketIOVisCommand(state.val);
|
|
242
|
+
if (this._connCallbacks.onCommand(visCommand.instance, visCommand.command, visCommand.data)) {
|
|
243
|
+
// clear state
|
|
244
|
+
this.setState(id, { val: '', ack: true });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
if (this._connCallbacks.onCommand(this._cmdInstance, state.val, this._cmdData)) {
|
|
249
|
+
// clear state
|
|
250
|
+
this.setState(id, { val: '', ack: true });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else if (id === this.namespace + '.control.data') {
|
|
255
|
+
this._cmdData = state.val;
|
|
256
|
+
}
|
|
257
|
+
else if (id === this.namespace + '.control.instance') {
|
|
258
|
+
this._cmdInstance = state.val;
|
|
259
|
+
}
|
|
260
|
+
else if (this._connCallbacks.onUpdate) {
|
|
261
|
+
this._connCallbacks.onUpdate(id, state);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
this._socket.on('permissionError', (err) => {
|
|
265
|
+
if (this._connCallbacks.onError) {
|
|
266
|
+
/* {
|
|
267
|
+
command:
|
|
268
|
+
type:
|
|
269
|
+
operation:
|
|
270
|
+
arg:
|
|
271
|
+
}*/
|
|
272
|
+
this._connCallbacks.onError(err);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'permissionError');
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
//#region GetterSetter
|
|
280
|
+
/**
|
|
281
|
+
* Getter isExecutedInBrowser
|
|
282
|
+
* @return {boolean }
|
|
283
|
+
*/
|
|
284
|
+
get isExecutedInBrowser() {
|
|
285
|
+
return this._isExecutedInBrowser;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Getter enums
|
|
289
|
+
* @return {unknown}
|
|
290
|
+
*/
|
|
291
|
+
get enums() {
|
|
292
|
+
return this._enums;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Getter isAuthDone
|
|
296
|
+
* @return {boolean }
|
|
297
|
+
*/
|
|
298
|
+
get isAuthDone() {
|
|
299
|
+
return this._isAuthDone;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Getter namespace
|
|
303
|
+
* @return {string }
|
|
304
|
+
*/
|
|
305
|
+
get namespace() {
|
|
306
|
+
return this._namespace;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Getter objects
|
|
310
|
+
* @return {unknown}
|
|
311
|
+
*/
|
|
312
|
+
get objects() {
|
|
313
|
+
return this._objects;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Getter type
|
|
317
|
+
* @return {string }
|
|
318
|
+
*/
|
|
319
|
+
get type() {
|
|
320
|
+
return this._type;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Getter timeout
|
|
324
|
+
* @return {number }
|
|
325
|
+
*/
|
|
326
|
+
get timeout() {
|
|
327
|
+
return this._timeout;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Getter user
|
|
331
|
+
* @return {unknown}
|
|
332
|
+
*/
|
|
333
|
+
get user() {
|
|
334
|
+
return this._user;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Setter enums
|
|
338
|
+
* @param {unknown} value
|
|
339
|
+
*/
|
|
340
|
+
set enums(value) {
|
|
341
|
+
this._enums = value;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Setter namespace
|
|
345
|
+
* @param {string } value
|
|
346
|
+
*/
|
|
347
|
+
set namespace(value) {
|
|
348
|
+
this._namespace = value;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Setter objects
|
|
352
|
+
* @param {unknown} value
|
|
353
|
+
*/
|
|
354
|
+
set objects(value) {
|
|
355
|
+
this._objects = value;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Setter type
|
|
359
|
+
* @param {string } value
|
|
360
|
+
*/
|
|
361
|
+
set type(value) {
|
|
362
|
+
this._type = value;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Setter timeout
|
|
366
|
+
* @param {number } value
|
|
367
|
+
*/
|
|
368
|
+
set timeout(value) {
|
|
369
|
+
this._timeout = value;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Setter user
|
|
373
|
+
* @param {unknown} value
|
|
374
|
+
*/
|
|
375
|
+
set user(value) {
|
|
376
|
+
this._user = value;
|
|
377
|
+
}
|
|
378
|
+
_checkConnection(pFunc, pArguments) {
|
|
379
|
+
if (!this._isConnected) {
|
|
380
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Warn, 'No connection!');
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
// @ts-ignore
|
|
384
|
+
if (this._queueCmdIfRequired(pFunc, pArguments)) {
|
|
385
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Warn, 'Command queued');
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
//socket.io
|
|
389
|
+
if (this._socket === null) {
|
|
390
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Warn, 'socket.io not initialized');
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
_monitor() {
|
|
396
|
+
if (this._timer !== undefined)
|
|
397
|
+
return;
|
|
398
|
+
const ts = new Date().getTime();
|
|
399
|
+
const lastTimerTime = this._lastTimer === undefined ? 0 : this._lastTimer.getTime();
|
|
400
|
+
if (this._reloadInterval && ts - lastTimerTime > this._reloadInterval * 1000) {
|
|
401
|
+
// It seems, that PC was in a sleep => Reload page to request authentication anew
|
|
402
|
+
if (this._isExecutedInBrowser)
|
|
403
|
+
window.location.reload();
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
this._lastTimer = new Date(ts);
|
|
407
|
+
}
|
|
408
|
+
this._timer = utils_1.Utils.guardedTimeout(() => {
|
|
409
|
+
this._timer = undefined;
|
|
410
|
+
this._monitor();
|
|
411
|
+
}, 10000, this);
|
|
412
|
+
}
|
|
413
|
+
_onAuth(pObjectsRequired, pIsSecure) {
|
|
414
|
+
this._isSecure = pIsSecure;
|
|
415
|
+
if (this._isSecure) {
|
|
416
|
+
this._lastTimer = new Date();
|
|
417
|
+
this._monitor();
|
|
418
|
+
}
|
|
419
|
+
this._socket.emit('subscribe', '*');
|
|
420
|
+
if (pObjectsRequired)
|
|
421
|
+
this._socket.emit('subscribeObjects', '*');
|
|
422
|
+
if (this._isConnected === true) {
|
|
423
|
+
// This seems to be a reconnect because we're already connected!
|
|
424
|
+
// -> prevent firing onConnChange twice
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
this._isConnected = true;
|
|
428
|
+
if (this._connCallbacks.onConnChange) {
|
|
429
|
+
utils_1.Utils.guardedNewThread(() => {
|
|
430
|
+
// @ts-ignore
|
|
431
|
+
this._socket.emit('authEnabled', (auth, user) => {
|
|
432
|
+
this._user = user;
|
|
433
|
+
if (typeof this._connCallbacks.onConnChange !== 'undefined') {
|
|
434
|
+
this._connCallbacks.onConnChange(this._isConnected);
|
|
435
|
+
}
|
|
436
|
+
if (typeof app !== 'undefined') {
|
|
437
|
+
// @ts-ignore
|
|
438
|
+
app.onConnChange(this._isConnected);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}, this);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
reconnect(pConnOptions) {
|
|
445
|
+
// reconnect
|
|
446
|
+
// @ts-ignore
|
|
447
|
+
if (this._connectInterval !== undefined || (pConnOptions.mayReconnect && !pConnOptions.mayReconnect())) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
this._connectInterval = utils_1.Utils.guardedInterval(() => {
|
|
451
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'Trying connect...');
|
|
452
|
+
this._socket.connect();
|
|
453
|
+
this._countDown = Math.floor(this._reconnectInterval / 1000);
|
|
454
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Trace, `Connection.ts: Connection Retry Countdown ${this._countDown}`);
|
|
455
|
+
}, this._reconnectInterval, this);
|
|
456
|
+
this._countDown = Math.floor(this._reconnectInterval / 1000);
|
|
457
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Trace, `Connection.ts: Connection Retry Countdown ${this._countDown}`);
|
|
458
|
+
this._countInterval = utils_1.Utils.guardedInterval(() => {
|
|
459
|
+
this._countDown--;
|
|
460
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Trace, `Connection.ts: Connection Retry Countdown ${this._countDown}`);
|
|
461
|
+
}, 1000, this);
|
|
462
|
+
}
|
|
463
|
+
// FIXME: CallBack Type
|
|
464
|
+
logout(callback) {
|
|
465
|
+
if (!this._isConnected) {
|
|
466
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'No connection!');
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
this._socket.emit('logout', callback);
|
|
470
|
+
}
|
|
471
|
+
// FIXME: CallBack Type
|
|
472
|
+
getVersion(callback) {
|
|
473
|
+
if (!this._checkConnection('getVersion', arguments)) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
this._socket.emit('getVersion',
|
|
477
|
+
// FIXME: version Type
|
|
478
|
+
(error, version) => {
|
|
479
|
+
if (callback) {
|
|
480
|
+
// @ts-ignore
|
|
481
|
+
callback(error, version);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
// FIXME: CallBack Type
|
|
486
|
+
_checkAuth(callback) {
|
|
487
|
+
if (!this._isConnected) {
|
|
488
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, '_checkAuth: No connection!');
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
//socket.io
|
|
492
|
+
if (this._socket === null) {
|
|
493
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.DeepTrace, '_checkAuth: socket.io not initialized');
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
this._socket.emit('getVersion',
|
|
497
|
+
// FIXME: CallBack Type
|
|
498
|
+
(error, version) => {
|
|
499
|
+
if (callback) {
|
|
500
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.DeepTrace, '_checkAuth: socket.io getVersion Callback');
|
|
501
|
+
// @ts-ignore
|
|
502
|
+
callback(error, version);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
readFile(filename, callback, isRemote) {
|
|
507
|
+
if (!callback)
|
|
508
|
+
throw 'No callback set';
|
|
509
|
+
if (this._type === 'local') {
|
|
510
|
+
try {
|
|
511
|
+
// @ts-ignore
|
|
512
|
+
const data = storage.get(filename);
|
|
513
|
+
// @ts-ignore
|
|
514
|
+
callback(null, data ? JSON.parse(storage.get(filename)) : null);
|
|
515
|
+
}
|
|
516
|
+
catch (err) {
|
|
517
|
+
// @ts-ignore
|
|
518
|
+
callback(err, undefined);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
if (!this._checkConnection('readFile', arguments))
|
|
523
|
+
return;
|
|
524
|
+
if (!isRemote && typeof app !== 'undefined') {
|
|
525
|
+
// @ts-ignore
|
|
526
|
+
app.readLocalFile(filename.replace(/^\/vis\.0\//, ''), callback);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
let adapter = this.namespace;
|
|
530
|
+
if (filename[0] === '/') {
|
|
531
|
+
const p = filename.split('/');
|
|
532
|
+
adapter = p[1];
|
|
533
|
+
p.splice(0, 2);
|
|
534
|
+
filename = p.join('/');
|
|
535
|
+
}
|
|
536
|
+
this._socket.emit('readFile', adapter, filename, (err, data, mimeType) => {
|
|
537
|
+
utils_1.Utils.guardedNewThread(() => {
|
|
538
|
+
callback(err, data, mimeType);
|
|
539
|
+
}, this);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
getMimeType(ext) {
|
|
545
|
+
if (ext.indexOf('.') !== -1) {
|
|
546
|
+
const regMatch = ext.toLowerCase().match(/\.[^.]+$/);
|
|
547
|
+
ext = regMatch !== null && regMatch.length > 0 ? regMatch[0] : '';
|
|
548
|
+
}
|
|
549
|
+
let _mimeType = '';
|
|
550
|
+
if (ext === '.css') {
|
|
551
|
+
_mimeType = 'text/css';
|
|
552
|
+
}
|
|
553
|
+
else if (ext === '.bmp') {
|
|
554
|
+
_mimeType = 'image/bmp';
|
|
555
|
+
}
|
|
556
|
+
else if (ext === '.png') {
|
|
557
|
+
_mimeType = 'image/png';
|
|
558
|
+
}
|
|
559
|
+
else if (ext === '.jpg') {
|
|
560
|
+
_mimeType = 'image/jpeg';
|
|
561
|
+
}
|
|
562
|
+
else if (ext === '.jpeg') {
|
|
563
|
+
_mimeType = 'image/jpeg';
|
|
564
|
+
}
|
|
565
|
+
else if (ext === '.gif') {
|
|
566
|
+
_mimeType = 'image/gif';
|
|
567
|
+
}
|
|
568
|
+
else if (ext === '.tif') {
|
|
569
|
+
_mimeType = 'image/tiff';
|
|
570
|
+
}
|
|
571
|
+
else if (ext === '.js') {
|
|
572
|
+
_mimeType = 'application/javascript';
|
|
573
|
+
}
|
|
574
|
+
else if (ext === '.html') {
|
|
575
|
+
_mimeType = 'text/html';
|
|
576
|
+
}
|
|
577
|
+
else if (ext === '.htm') {
|
|
578
|
+
_mimeType = 'text/html';
|
|
579
|
+
}
|
|
580
|
+
else if (ext === '.json') {
|
|
581
|
+
_mimeType = 'application/json';
|
|
582
|
+
}
|
|
583
|
+
else if (ext === '.xml') {
|
|
584
|
+
_mimeType = 'text/xml';
|
|
585
|
+
}
|
|
586
|
+
else if (ext === '.svg') {
|
|
587
|
+
_mimeType = 'image/svg+xml';
|
|
588
|
+
}
|
|
589
|
+
else if (ext === '.eot') {
|
|
590
|
+
_mimeType = 'application/vnd.ms-fontobject';
|
|
591
|
+
}
|
|
592
|
+
else if (ext === '.ttf') {
|
|
593
|
+
_mimeType = 'application/font-sfnt';
|
|
594
|
+
}
|
|
595
|
+
else if (ext === '.woff') {
|
|
596
|
+
_mimeType = 'application/font-woff';
|
|
597
|
+
}
|
|
598
|
+
else if (ext === '.wav') {
|
|
599
|
+
_mimeType = 'audio/wav';
|
|
600
|
+
}
|
|
601
|
+
else if (ext === '.mp3') {
|
|
602
|
+
_mimeType = 'audio/mpeg3';
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
_mimeType = 'text/javascript';
|
|
606
|
+
}
|
|
607
|
+
return _mimeType;
|
|
608
|
+
}
|
|
609
|
+
// FIXME: Callback Type
|
|
610
|
+
readFile64(filename, callback, isRemote) {
|
|
611
|
+
if (!callback) {
|
|
612
|
+
throw 'No callback set';
|
|
613
|
+
}
|
|
614
|
+
if (!this._checkConnection('readFile', arguments))
|
|
615
|
+
return;
|
|
616
|
+
if (!isRemote && typeof app !== 'undefined') {
|
|
617
|
+
// FIXME: data Type
|
|
618
|
+
// @ts-ignore
|
|
619
|
+
app.readLocalFile(filename.replace(/^\/vis\.0\//, ''), (err, data, mimeType) => {
|
|
620
|
+
utils_1.Utils.guardedNewThread(() => {
|
|
621
|
+
if (data) {
|
|
622
|
+
// @ts-ignore
|
|
623
|
+
callback(err, { mime: mimeType || this.getMimeType(filename), data: btoa(data) }, filename);
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
// @ts-ignore
|
|
627
|
+
callback(err, filename);
|
|
628
|
+
}
|
|
629
|
+
}, this);
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
let adapter = this.namespace;
|
|
634
|
+
if (filename[0] === '/') {
|
|
635
|
+
const p = filename.split('/');
|
|
636
|
+
adapter = p[1];
|
|
637
|
+
p.splice(0, 2);
|
|
638
|
+
filename = p.join('/');
|
|
639
|
+
}
|
|
640
|
+
this._socket.emit('readFile64', adapter, filename,
|
|
641
|
+
// FIXME: data Type
|
|
642
|
+
(err, data, mimeType) => {
|
|
643
|
+
utils_1.Utils.guardedNewThread(() => {
|
|
644
|
+
if (data) {
|
|
645
|
+
// @ts-ignore
|
|
646
|
+
callback(err, { mime: mimeType || this.getMimeType(filename), data: data }, filename);
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
// @ts-ignore
|
|
650
|
+
callback(err, { mime: mimeType || this.getMimeType(filename) }, filename);
|
|
651
|
+
}
|
|
652
|
+
}, this);
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
// @ts-ignore
|
|
657
|
+
writeFile(filename, data, mode, callback,
|
|
658
|
+
// @ts-ignore
|
|
659
|
+
...args) {
|
|
660
|
+
if (this._type === 'local') {
|
|
661
|
+
// @ts-ignore
|
|
662
|
+
storage.set(filename, JSON.stringify(data));
|
|
663
|
+
if (callback) {
|
|
664
|
+
callback();
|
|
665
|
+
}
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
if (!this._checkConnection('writeFile', arguments)) {
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
// @ts-ignore
|
|
672
|
+
const sData = typeof data === 'object' ? JSON.stringify(data, null, 2) : data;
|
|
673
|
+
const parts = filename.split('/');
|
|
674
|
+
const adapter = parts[1];
|
|
675
|
+
parts.splice(0, 2);
|
|
676
|
+
if (adapter === 'vis') {
|
|
677
|
+
this._socket.emit('writeFile', adapter, parts.join('/'), sData, mode ? { mode: this._defaultMode } : {}, callback);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
this._socket.emit('writeFile', this.namespace, filename, sData, mode ? { mode: this._defaultMode } : {}, callback);
|
|
681
|
+
}
|
|
682
|
+
// Write file base 64
|
|
683
|
+
writeFile64(filename, data, callback) {
|
|
684
|
+
if (!this._checkConnection('writeFile', arguments))
|
|
685
|
+
return;
|
|
686
|
+
const parts = filename.split('/');
|
|
687
|
+
const adapter = parts[1];
|
|
688
|
+
parts.splice(0, 2);
|
|
689
|
+
this._socket.emit('writeFile', adapter, parts.join('/'), atob(data), { mode: this._defaultMode }, callback);
|
|
690
|
+
}
|
|
691
|
+
readDir(dirname, callback) {
|
|
692
|
+
//socket.io
|
|
693
|
+
if (this._socket === null) {
|
|
694
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'socket.io not initialized');
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (!dirname)
|
|
698
|
+
dirname = '/';
|
|
699
|
+
const parts = dirname.split('/');
|
|
700
|
+
const adapter = parts[1];
|
|
701
|
+
parts.splice(0, 2);
|
|
702
|
+
this._socket.emit('readDir', adapter, parts.join('/'), { filter: true }, (err, data) => {
|
|
703
|
+
if (callback)
|
|
704
|
+
callback(err, data);
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
mkdir(dirname, callback) {
|
|
708
|
+
const parts = dirname.split('/');
|
|
709
|
+
const adapter = parts[1];
|
|
710
|
+
parts.splice(0, 2);
|
|
711
|
+
this._socket.emit('mkdir', adapter, parts.join('/'), (err) => {
|
|
712
|
+
callback && callback(err);
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
unlink(name, callback) {
|
|
716
|
+
const parts = name.split('/');
|
|
717
|
+
const adapter = parts[1];
|
|
718
|
+
parts.splice(0, 2);
|
|
719
|
+
this._socket.emit('unlink', adapter, parts.join('/'), (err) => {
|
|
720
|
+
callback && callback(err);
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
renameFile(oldname, newname, callback) {
|
|
724
|
+
const parts1 = oldname.split('/');
|
|
725
|
+
const adapter = parts1[1];
|
|
726
|
+
parts1.splice(0, 2);
|
|
727
|
+
const parts2 = newname.split('/');
|
|
728
|
+
parts2.splice(0, 2);
|
|
729
|
+
this._socket.emit('rename', adapter, parts1.join('/'), parts2.join('/'), (err) => {
|
|
730
|
+
callback && callback(err);
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
setState(pointId, state, callback) {
|
|
734
|
+
//socket.io
|
|
735
|
+
if (this._socket === null) {
|
|
736
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'socket.io not initialized');
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
if (!callback) {
|
|
740
|
+
callback = (err, id) => {
|
|
741
|
+
if (err) {
|
|
742
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Error, `socket.io setState Error: ${err}\nwith updating ${pointId} to value ${state}\nid:${id}`);
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
this._socket.emit('setState', pointId, state, callback);
|
|
747
|
+
}
|
|
748
|
+
sendTo(instance, command, payload, callback) {
|
|
749
|
+
//socket.io
|
|
750
|
+
if (this._socket === null) {
|
|
751
|
+
//SocketIoLogging.writeLog(SocketIoLogLevel.Debug,'socket.io not initialized');
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
this._socket.emit('sendTo', instance, command, payload, callback);
|
|
755
|
+
}
|
|
756
|
+
// callback(err: Error, data)
|
|
757
|
+
getStates(IDs, callback) {
|
|
758
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.DeepTrace, 'getStates');
|
|
759
|
+
if (this._type === 'local') {
|
|
760
|
+
return callback(null, {});
|
|
761
|
+
}
|
|
762
|
+
if (!this._checkConnection('getStates', arguments)) {
|
|
763
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'getStates: No Connection');
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
this._gettingStates = this._gettingStates || 0;
|
|
767
|
+
this._gettingStates++;
|
|
768
|
+
if (this._gettingStates > 1) {
|
|
769
|
+
// fix for slow devices
|
|
770
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Trace, 'Trying to get empty list, because the whole list could not be loaded');
|
|
771
|
+
// FIXME: Check if this is correct to get all
|
|
772
|
+
IDs = null;
|
|
773
|
+
}
|
|
774
|
+
this._socket.emit('getStates', IDs, (err, data) => {
|
|
775
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Trace, `getStates Callback; Error: "${err}"`);
|
|
776
|
+
this._gettingStates !== undefined && this._gettingStates--;
|
|
777
|
+
if (err || !data) {
|
|
778
|
+
if (callback) {
|
|
779
|
+
callback(err || new Error('Authentication required'));
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
else if (callback) {
|
|
783
|
+
callback(null, data);
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
// TODO: check if ioBroker.Object is correct
|
|
788
|
+
_fillChildren(objects) {
|
|
789
|
+
const items = [];
|
|
790
|
+
for (const id in objects) {
|
|
791
|
+
items.push(id);
|
|
792
|
+
}
|
|
793
|
+
items.sort();
|
|
794
|
+
for (let i = 0; i < items.length; i++) {
|
|
795
|
+
if (objects[items[i]].common) {
|
|
796
|
+
let j = i + 1;
|
|
797
|
+
const children = [];
|
|
798
|
+
const len = items[i].length + 1;
|
|
799
|
+
const name = items[i] + '.';
|
|
800
|
+
while (j < items.length && items[j].substring(0, len) === name) {
|
|
801
|
+
children.push(items[j++]);
|
|
802
|
+
}
|
|
803
|
+
objects[items[i]].children = children;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
// callback(err: Error, data)
|
|
808
|
+
getObjects(useCache, callback) {
|
|
809
|
+
if (typeof useCache === 'function') {
|
|
810
|
+
callback = useCache;
|
|
811
|
+
useCache = false;
|
|
812
|
+
}
|
|
813
|
+
// If cache used
|
|
814
|
+
if (this._useStorage && useCache) {
|
|
815
|
+
if (typeof storage !== 'undefined') {
|
|
816
|
+
// @ts-ignore
|
|
817
|
+
const objects = this._objects || storage.get('objects');
|
|
818
|
+
if (objects)
|
|
819
|
+
return callback(null, objects);
|
|
820
|
+
}
|
|
821
|
+
else if (this._objects) {
|
|
822
|
+
return callback(null, this._objects);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (!this._checkConnection('getObjects', arguments))
|
|
826
|
+
return;
|
|
827
|
+
this._socket.emit('getObjects', (err, data) => {
|
|
828
|
+
if (err) {
|
|
829
|
+
callback(err);
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
// Read all enums
|
|
833
|
+
this._socket.emit('getObjectView', 'system', 'enum', { startkey: 'enum.', endkey: 'enum.\u9999' }, (err, res) => {
|
|
834
|
+
if (err) {
|
|
835
|
+
callback(err);
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
const enums = {};
|
|
839
|
+
for (const row of res.rows) {
|
|
840
|
+
const currentId = row.id;
|
|
841
|
+
if (row.value !== null) {
|
|
842
|
+
data[currentId] = row.value;
|
|
843
|
+
enums[currentId] = row.value;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
// Read all adapters for images
|
|
847
|
+
this._socket.emit('getObjectView', 'system', 'instance', { startkey: 'system.adapter.', endkey: 'system.adapter.\u9999' }, (err, res) => {
|
|
848
|
+
if (err) {
|
|
849
|
+
callback(err);
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
for (const row of res.rows) {
|
|
853
|
+
if (row.value !== null) {
|
|
854
|
+
data[row.id] = row.value;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
// find out default file mode
|
|
858
|
+
if (data['system.adapter.' + this.namespace] &&
|
|
859
|
+
data['system.adapter.' + this.namespace].native &&
|
|
860
|
+
data['system.adapter.' + this.namespace].native.defaultFileMode) {
|
|
861
|
+
this._defaultMode = data['system.adapter.' + this.namespace].native.defaultFileMode;
|
|
862
|
+
}
|
|
863
|
+
// Read all channels for images
|
|
864
|
+
this._socket.emit('getObjectView', 'system', 'channel', { startkey: '', endkey: '\u9999' }, (err, res) => {
|
|
865
|
+
if (err) {
|
|
866
|
+
callback(err);
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
for (const row of res.rows) {
|
|
870
|
+
if (row.value !== null) {
|
|
871
|
+
data[row.id] = row.value;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
// Read all devices for images
|
|
875
|
+
this._socket.emit('getObjectView', 'system', 'device', { startkey: '', endkey: '\u9999' }, (err, res) => {
|
|
876
|
+
if (err) {
|
|
877
|
+
callback(err);
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
for (const row of res.rows) {
|
|
881
|
+
if (row.value !== null) {
|
|
882
|
+
data[row.id] = row.value;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (this._useStorage) {
|
|
886
|
+
this._fillChildren(data);
|
|
887
|
+
this._objects = data;
|
|
888
|
+
this._enums = enums;
|
|
889
|
+
if (typeof storage !== 'undefined') {
|
|
890
|
+
// @ts-ignore
|
|
891
|
+
storage.set('objects', data);
|
|
892
|
+
// @ts-ignore
|
|
893
|
+
storage.set('enums', enums);
|
|
894
|
+
// @ts-ignore
|
|
895
|
+
storage.set('timeSync', new Date().getTime());
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
if (callback)
|
|
899
|
+
callback(err, data);
|
|
900
|
+
});
|
|
901
|
+
});
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
// @ts-ignore
|
|
907
|
+
getChildren(id, useCache, callback,
|
|
908
|
+
// @ts-ignore
|
|
909
|
+
...args) {
|
|
910
|
+
if (!this._checkConnection('getChildren', arguments))
|
|
911
|
+
return;
|
|
912
|
+
if (!id)
|
|
913
|
+
return callback(new Error('getChildren: no id given'));
|
|
914
|
+
const data = {};
|
|
915
|
+
if (this._useStorage && useCache) {
|
|
916
|
+
if (typeof storage !== 'undefined') {
|
|
917
|
+
// @ts-ignore
|
|
918
|
+
const objects = storage.get('objects');
|
|
919
|
+
if (objects && objects[id] && objects[id].children) {
|
|
920
|
+
return callback(null, objects[id].children);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
// @ts-ignore
|
|
925
|
+
if (this._objects && this._objects[id] && this._objects[id].children) {
|
|
926
|
+
// @ts-ignore
|
|
927
|
+
return callback(null, this._objects[id].children);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
// Read all devices
|
|
932
|
+
this._socket.emit('getObjectView', 'system', 'device', { startkey: id + '.', endkey: id + '.\u9999' }, (err, res) => {
|
|
933
|
+
if (err) {
|
|
934
|
+
callback(err);
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
for (const row of res.rows) {
|
|
938
|
+
if (row.value !== null) {
|
|
939
|
+
data[row.id] = row.value;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
this._socket.emit('getObjectView', 'system', 'channel', { startkey: id + '.', endkey: id + '.\u9999' }, (err, res) => {
|
|
943
|
+
if (err) {
|
|
944
|
+
callback(err);
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
for (const row of res.rows) {
|
|
948
|
+
if (row.value !== null) {
|
|
949
|
+
data[row.id] = row.value;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
// Read all adapters for images
|
|
953
|
+
this._socket.emit('getObjectView', 'system', 'state', { startkey: id + '.', endkey: id + '.\u9999' }, (err, res) => {
|
|
954
|
+
if (err) {
|
|
955
|
+
callback(err);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
for (const row of res.rows) {
|
|
959
|
+
if (row.value !== null) {
|
|
960
|
+
data[row.id] = row.value;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
const list = [];
|
|
964
|
+
const count = id.split('.').length;
|
|
965
|
+
// find direct children
|
|
966
|
+
for (const _id in data) {
|
|
967
|
+
const parts = _id.split('.');
|
|
968
|
+
if (count + 1 === parts.length) {
|
|
969
|
+
list.push(_id);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
list.sort();
|
|
973
|
+
if (this._useStorage && typeof storage !== 'undefined') {
|
|
974
|
+
// @ts-ignore
|
|
975
|
+
const objects = storage.get('objects') || {};
|
|
976
|
+
for (const id_ in data) {
|
|
977
|
+
objects[id_] = data[id_];
|
|
978
|
+
}
|
|
979
|
+
if (objects[id] && objects[id].common) {
|
|
980
|
+
objects[id].children = list;
|
|
981
|
+
}
|
|
982
|
+
// Store for every element theirs children
|
|
983
|
+
const items = [];
|
|
984
|
+
for (const __id in data) {
|
|
985
|
+
items.push(__id);
|
|
986
|
+
}
|
|
987
|
+
items.sort();
|
|
988
|
+
for (let k = 0; k < items.length; k++) {
|
|
989
|
+
if (objects[items[k]].common) {
|
|
990
|
+
let j = k + 1;
|
|
991
|
+
const children = [];
|
|
992
|
+
const len = items[k].length + 1;
|
|
993
|
+
const name = items[k] + '.';
|
|
994
|
+
while (j < items.length && items[j].substring(0, len) === name) {
|
|
995
|
+
children.push(items[j++]);
|
|
996
|
+
}
|
|
997
|
+
objects[items[k]].children = children;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
// @ts-ignore
|
|
1001
|
+
storage.set('objects', objects);
|
|
1002
|
+
}
|
|
1003
|
+
if (callback)
|
|
1004
|
+
callback(err, list);
|
|
1005
|
+
});
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
getObject(id, useCache, callback) {
|
|
1010
|
+
if (!id)
|
|
1011
|
+
return callback(new Error('no id given'));
|
|
1012
|
+
// If cache used
|
|
1013
|
+
if (this._useStorage && useCache && typeof storage !== 'undefined') {
|
|
1014
|
+
if (typeof storage !== 'undefined') {
|
|
1015
|
+
// @ts-ignore
|
|
1016
|
+
const objects = this._objects || storage.get('objects');
|
|
1017
|
+
if (objects && objects[id])
|
|
1018
|
+
return callback(null, objects[id]);
|
|
1019
|
+
}
|
|
1020
|
+
else if (this._enums) {
|
|
1021
|
+
return callback(null, this._enums);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
this._socket.emit('getObject', id, (err, obj) => {
|
|
1025
|
+
if (err) {
|
|
1026
|
+
callback(err);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
if (this._useStorage && typeof storage !== 'undefined') {
|
|
1030
|
+
// @ts-ignore
|
|
1031
|
+
const objects = storage.get('objects') || {};
|
|
1032
|
+
objects[id] = obj;
|
|
1033
|
+
// @ts-ignore
|
|
1034
|
+
storage.set('objects', objects);
|
|
1035
|
+
}
|
|
1036
|
+
return callback(null, obj);
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
getEnums(enumName, useCache, callback) {
|
|
1040
|
+
// If cache used
|
|
1041
|
+
if (this._useStorage && useCache) {
|
|
1042
|
+
if (typeof storage !== 'undefined') {
|
|
1043
|
+
// @ts-ignore
|
|
1044
|
+
const enums = this._enums || storage.get('enums');
|
|
1045
|
+
if (enums)
|
|
1046
|
+
return callback(null, enums);
|
|
1047
|
+
}
|
|
1048
|
+
else if (this._enums) {
|
|
1049
|
+
return callback(null, this._enums);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
if (this._type === 'local') {
|
|
1053
|
+
return callback(null, {});
|
|
1054
|
+
}
|
|
1055
|
+
enumName = enumName ? enumName + '.' : '';
|
|
1056
|
+
// Read all enums
|
|
1057
|
+
this._socket.emit('getObjectView', 'system', 'enum', { startkey: 'enum.' + enumName, endkey: 'enum.' + enumName + '\u9999' }, (err, res) => {
|
|
1058
|
+
if (err) {
|
|
1059
|
+
callback(err);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
const enums = {};
|
|
1063
|
+
for (const row of res.rows) {
|
|
1064
|
+
if (row.value !== null) {
|
|
1065
|
+
enums[row.id] = row.value;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
if (this._useStorage && typeof storage !== 'undefined') {
|
|
1069
|
+
// @ts-ignore
|
|
1070
|
+
storage.set('enums', enums);
|
|
1071
|
+
}
|
|
1072
|
+
callback(null, enums);
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
// return time when the objects were synchronized
|
|
1076
|
+
getSyncTime() {
|
|
1077
|
+
if (this._useStorage && typeof storage !== 'undefined') {
|
|
1078
|
+
// @ts-ignore
|
|
1079
|
+
const timeSync = storage.get('timeSync');
|
|
1080
|
+
if (timeSync)
|
|
1081
|
+
return new Date(timeSync);
|
|
1082
|
+
}
|
|
1083
|
+
return new Date(0);
|
|
1084
|
+
}
|
|
1085
|
+
// FIXME finish implementation of this file
|
|
1086
|
+
// @ts-ignore
|
|
1087
|
+
addObject(objId, obj, callback) {
|
|
1088
|
+
if (!this._isConnected) {
|
|
1089
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'No connection!');
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
//socket.io
|
|
1093
|
+
if (this._socket === null) {
|
|
1094
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'socket.io not initialized');
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
delObject(objId) {
|
|
1099
|
+
if (!this._checkConnection('delObject', arguments))
|
|
1100
|
+
return;
|
|
1101
|
+
this._socket.emit('delObject', objId);
|
|
1102
|
+
}
|
|
1103
|
+
httpGet(url, callback) {
|
|
1104
|
+
if (!this._isConnected) {
|
|
1105
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'No connection!');
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
//socket.io
|
|
1109
|
+
if (this._socket === null) {
|
|
1110
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'socket.io not initialized');
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
this._socket.emit('httpGet', url, (data) => {
|
|
1114
|
+
if (callback)
|
|
1115
|
+
callback(data);
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
logError(errorText) {
|
|
1119
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'Error: ' + errorText);
|
|
1120
|
+
if (!this._isConnected) {
|
|
1121
|
+
//SocketIoLogging.writeLog(SocketIoLogLevel.Debug,'No connection!');
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
//socket.io
|
|
1125
|
+
if (this._socket === null) {
|
|
1126
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'socket.io not initialized');
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
this._socket.emit('log', 'error', 'Addon DashUI ' + errorText);
|
|
1130
|
+
}
|
|
1131
|
+
_queueCmdIfRequired(func, args) {
|
|
1132
|
+
if (this.isAuthDone) {
|
|
1133
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.DeepTrace, `_queueCmdIfRequired: Auth is already done`);
|
|
1134
|
+
return false;
|
|
1135
|
+
}
|
|
1136
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.DeepTrace, `_queueCmdIfRequired: Auth is not yet done`);
|
|
1137
|
+
// Queue command
|
|
1138
|
+
// @ts-ignore
|
|
1139
|
+
this._cmdQueue.push({ func: func, args: args });
|
|
1140
|
+
if (this._authRunning) {
|
|
1141
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.DeepTrace, `_queueCmdIfRequired: Authentication Process is already Running`);
|
|
1142
|
+
return true;
|
|
1143
|
+
}
|
|
1144
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.DeepTrace, `_queueCmdIfRequired: Starting Authentication Process`);
|
|
1145
|
+
this._authRunning = true;
|
|
1146
|
+
// Try to read version
|
|
1147
|
+
// @ts-ignore
|
|
1148
|
+
this._checkAuth((error, version) => {
|
|
1149
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.DeepTrace, `_queueCmdIfRequired: _checkAuth CB data: "${version}"`);
|
|
1150
|
+
// If we have got version string, so there is no authentication, or we are authenticated
|
|
1151
|
+
this._authRunning = false;
|
|
1152
|
+
if (!version) {
|
|
1153
|
+
// Auth required
|
|
1154
|
+
this._isAuthRequired = true;
|
|
1155
|
+
// What for AuthRequest from server
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
this._isAuthDone = true;
|
|
1159
|
+
// Repeat all stored requests
|
|
1160
|
+
const __cmdQueue = this._cmdQueue;
|
|
1161
|
+
// Trigger GC
|
|
1162
|
+
this._cmdQueue = undefined;
|
|
1163
|
+
this._cmdQueue = [];
|
|
1164
|
+
// @ts-ignore
|
|
1165
|
+
for (let t = 0, len = __cmdQueue.length; t < len; t++) {
|
|
1166
|
+
// @ts-ignore
|
|
1167
|
+
this[__cmdQueue[t].func].apply(this, __cmdQueue[t].args);
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
return true;
|
|
1171
|
+
}
|
|
1172
|
+
authenticate(user, password, salt) {
|
|
1173
|
+
this._authRunning = true;
|
|
1174
|
+
if (user !== undefined) {
|
|
1175
|
+
this._authInfo = {
|
|
1176
|
+
user: user,
|
|
1177
|
+
hash: password + salt,
|
|
1178
|
+
salt: salt,
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
if (!this._isConnected) {
|
|
1182
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'No connection!');
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
if (!this._authInfo) {
|
|
1186
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'No credentials!');
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
getConfig(useCache, callback,
|
|
1190
|
+
// @ts-ignore
|
|
1191
|
+
...args) {
|
|
1192
|
+
if (!this._checkConnection('getConfig', arguments))
|
|
1193
|
+
return;
|
|
1194
|
+
if (typeof useCache === 'function') {
|
|
1195
|
+
callback = useCache;
|
|
1196
|
+
useCache = false;
|
|
1197
|
+
}
|
|
1198
|
+
if (this._useStorage && useCache) {
|
|
1199
|
+
if (typeof storage !== 'undefined') {
|
|
1200
|
+
// @ts-ignore
|
|
1201
|
+
const objects = storage.get('objects');
|
|
1202
|
+
if (objects && objects['system.config']) {
|
|
1203
|
+
return callback(null, objects['system.config'].common);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
else if (this._objects && this._objects['system.config']) {
|
|
1207
|
+
return callback(null, this._objects['system.config'].common);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
this._socket.emit('getObject', 'system.config', (err, obj) => {
|
|
1211
|
+
if (err || !obj || !obj.common) {
|
|
1212
|
+
callback(new Error('Cannot read language'));
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
if (this._useStorage && typeof storage !== 'undefined') {
|
|
1216
|
+
// @ts-ignore
|
|
1217
|
+
const objects = storage.get('objects') || {};
|
|
1218
|
+
objects['system.config'] = obj;
|
|
1219
|
+
// @ts-ignore
|
|
1220
|
+
storage.set('objects', objects);
|
|
1221
|
+
}
|
|
1222
|
+
callback(null, obj.common);
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
sendCommand(instance, command, data, ack = true) {
|
|
1226
|
+
this.setState(this.namespace + '.control.instance', { val: instance || 'notdefined', ack: true });
|
|
1227
|
+
// @ts-ignore
|
|
1228
|
+
this.setState(this.namespace + '.control.data', { val: data, ack: true });
|
|
1229
|
+
this.setState(this.namespace + '.control.command', { val: command, ack: ack });
|
|
1230
|
+
}
|
|
1231
|
+
_detectViews(projectDir, callback) {
|
|
1232
|
+
this.readDir('/' + this.namespace + '/' + projectDir, (err, dirs) => {
|
|
1233
|
+
if (err) {
|
|
1234
|
+
callback(err);
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
// find vis-views.json
|
|
1238
|
+
if (dirs === undefined) {
|
|
1239
|
+
callback(new Error('No directories found'));
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
for (const dir of dirs) {
|
|
1243
|
+
if (dir.file === 'vis-views.json' && (!dir.acl || dir.acl.read)) {
|
|
1244
|
+
return callback(err, {
|
|
1245
|
+
name: projectDir,
|
|
1246
|
+
readOnly: dir.acl && !dir.acl.write,
|
|
1247
|
+
mode: dir.acl ? dir.acl.permissions : 0,
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
callback(err);
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
readProjects(callback) {
|
|
1255
|
+
this.readDir('/' + this.namespace, (err, dirs) => {
|
|
1256
|
+
const result = [];
|
|
1257
|
+
let count = 0;
|
|
1258
|
+
if (err) {
|
|
1259
|
+
callback(err);
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
if (dirs === undefined) {
|
|
1263
|
+
callback(new Error('No Dirs Found'));
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
for (const dir of dirs) {
|
|
1267
|
+
if (!dir.isDir) {
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
count++;
|
|
1271
|
+
this._detectViews(dir.file, (subErr, project) => {
|
|
1272
|
+
if (project)
|
|
1273
|
+
result.push(project);
|
|
1274
|
+
err = err || subErr;
|
|
1275
|
+
if (!--count)
|
|
1276
|
+
callback(err, result);
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
chmodProject(projectDir, mode, callback) {
|
|
1282
|
+
//socket.io
|
|
1283
|
+
if (this._socket === null) {
|
|
1284
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'socket.io not initialized');
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
this._socket.emit('chmodFile', this.namespace, projectDir + '*', { mode: mode }, (err, data, id) => {
|
|
1288
|
+
if (callback) {
|
|
1289
|
+
// @ts-ignore
|
|
1290
|
+
callback(err, data, id);
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
clearCache() {
|
|
1295
|
+
if (typeof storage !== 'undefined') {
|
|
1296
|
+
// @ts-ignore
|
|
1297
|
+
storage.empty();
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
getHistory(id, options, callback,
|
|
1301
|
+
// @ts-ignore
|
|
1302
|
+
...args) {
|
|
1303
|
+
if (!this._checkConnection('getHistory', arguments))
|
|
1304
|
+
return;
|
|
1305
|
+
if (!options)
|
|
1306
|
+
options = {};
|
|
1307
|
+
if (!options.timeout) {
|
|
1308
|
+
options.timeout = 2000;
|
|
1309
|
+
}
|
|
1310
|
+
let timeout = utils_1.Utils.guardedTimeout(() => {
|
|
1311
|
+
timeout = undefined;
|
|
1312
|
+
callback(new Error('timeout'));
|
|
1313
|
+
}, options.timeout, this);
|
|
1314
|
+
this._socket.emit('getHistory', id, options, (err, result) => {
|
|
1315
|
+
if (timeout) {
|
|
1316
|
+
clearTimeout(timeout);
|
|
1317
|
+
timeout = undefined;
|
|
1318
|
+
}
|
|
1319
|
+
callback(err, result);
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
getLiveHost(callback) {
|
|
1323
|
+
this._socket.emit('getObjectView', 'system', 'host', { startkey: 'system.host.', endkey: 'system.host.\u9999' }, (err, res) => {
|
|
1324
|
+
if (err || res === undefined || res.rows.length === 0) {
|
|
1325
|
+
callback('');
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
const _hosts = [];
|
|
1329
|
+
for (const row of res.rows) {
|
|
1330
|
+
_hosts.push(row.id + '.alive');
|
|
1331
|
+
}
|
|
1332
|
+
this.getStates(_hosts, (err, states) => {
|
|
1333
|
+
if (err) {
|
|
1334
|
+
callback('');
|
|
1335
|
+
}
|
|
1336
|
+
for (const h in states) {
|
|
1337
|
+
if (states[h].val) {
|
|
1338
|
+
callback(h.substring(0, h.length - '.alive'.length));
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
callback('');
|
|
1343
|
+
});
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
// @ts-ignore
|
|
1347
|
+
readDirAsZip(project, useConvert = false, callback) {
|
|
1348
|
+
if (!this._isConnected) {
|
|
1349
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'No connection!');
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
//socket.io
|
|
1353
|
+
if (this._socket === null) {
|
|
1354
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'socket.io not initialized');
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
if (project.match(/\/$/))
|
|
1358
|
+
project = project.substring(0, project.length - 1);
|
|
1359
|
+
this.getLiveHost((host) => {
|
|
1360
|
+
if (!host) {
|
|
1361
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Error, 'No active host found');
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
// to do find active host
|
|
1365
|
+
this._socket.emit('sendToHost', host, 'readDirAsZip', {
|
|
1366
|
+
id: this.namespace,
|
|
1367
|
+
name: project || 'main',
|
|
1368
|
+
options: {
|
|
1369
|
+
settings: useConvert,
|
|
1370
|
+
},
|
|
1371
|
+
},
|
|
1372
|
+
// (data: ioBroker.Message) => {
|
|
1373
|
+
// FIXME: ioBroker.Message has no attribute error
|
|
1374
|
+
(data) => {
|
|
1375
|
+
// @ts-ignore
|
|
1376
|
+
if (data.error)
|
|
1377
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Error, data.error);
|
|
1378
|
+
if (callback) {
|
|
1379
|
+
// @ts-ignore
|
|
1380
|
+
callback(data.error, data.data);
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
// @ts-ignore
|
|
1386
|
+
writeDirAsZip(project, base64, callback) {
|
|
1387
|
+
if (!this._isConnected) {
|
|
1388
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'No connection!');
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
//socket.io
|
|
1392
|
+
if (this._socket === null) {
|
|
1393
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Debug, 'socket.io not initialized');
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
if (project.match(/\/$/))
|
|
1397
|
+
project = project.substring(0, project.length - 1);
|
|
1398
|
+
this.getLiveHost((host) => {
|
|
1399
|
+
if (!host) {
|
|
1400
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Error, 'No active host found');
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
this._socket.emit('sendToHost', host, 'writeDirAsZip', {
|
|
1404
|
+
id: this.namespace,
|
|
1405
|
+
name: project || 'main',
|
|
1406
|
+
data: base64,
|
|
1407
|
+
}, (data) => {
|
|
1408
|
+
// @ts-ignore
|
|
1409
|
+
if (data.error)
|
|
1410
|
+
socketIOLogging_1.SocketIoLogging.writeLog(socketIOLogging_1.SocketIoLogLevel.Error, data.error);
|
|
1411
|
+
if (callback) {
|
|
1412
|
+
// @ts-ignore
|
|
1413
|
+
callback(data.error, data.message);
|
|
1414
|
+
}
|
|
1415
|
+
});
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
exports.IOBrokerConnection = IOBrokerConnection;
|