Skip to content

Commit

Permalink
Update fetch_all_device_data.fn to v2.2 (#1211)
Browse files Browse the repository at this point in the history
* Update fetch_all_device_data.fn to v2.2

- aktualisiert auf v2.2
- kleinere Optimierungen und Verbesserungen
- Fehlerbehandlung bei inkorrekter Interface-Übergabe / nicht vorhandenem Interface

* Format fetch_all_device_data.fn

---------

Co-authored-by: SukramJ <[email protected]>
  • Loading branch information
Baxxy13 and SukramJ authored Sep 28, 2023
1 parent 90c423e commit 6449c96
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions hahomematic/rega_scripts/fetch_all_device_data.fn
Original file line number Diff line number Diff line change
@@ -1,67 +1,69 @@
!# fetch_all_device_data.fn v2.1
!# fetch_all_device_data.fn v2.2
!# This script fetches all device data required to initialize the entities without affecting the duty cycle.
!#
!# Original script: https://github.com/ioBroker/ioBroker.hm-rega/blob/master/regascripts/datapoints.fn
!# datapoints.fn 1.9
!# 3'2013-9'2014 hobbyquaker https://github.com/hobbyquaker
!#
!# v2.0 - 09/2023
!# modified by Baxxy13 https://github.com/Baxxy13
!#
!#
!# Dieses Homematic-Script gibt eine Liste aller Datenpunkte, die zur Laufzeit einen validen Zeitstempel haben, als JSON String aus.
!#
!# v2.1 - 09/2023
!# modified by SukramJ https://github.com/SukramJ
!# modified by: SukramJ https://github.com/SukramJ && Baxxy13 https://github.com/Baxxy13
!# v2.2 - 09/2023
!#
!# Das abzufragende Interface muss in sUse_Interface eingetragen sein.
!# Das Interface wird durch die Integration an 'sUse_Interface' übergeben.
!# Nutzbare Interfaces: BidCos-RF, BidCos-Wired, HmIP-RF, VirtualDevices
!# Zum Testen direkt auf der Homematic-Zentrale muss das Interface wie folgt eingetragen werden: sUse_Interface = "HmIP-RF";

string sUse_Interface = "##interface##";
string sDevId;
string sChnId;
string sDPId;
string sValue;
string sDPId;
boolean dpFirst = true;
var vDPValue;
boolean bDPFirst = true;
object oInterface = interfaces.Get(sUse_Interface);

Write('{');
foreach (sDevId, root.Devices().EnumUsedIDs()) {
object oDevice = dom.GetObject(sDevId);
string ifacename = interfaces.Get ((dom.GetObject(oDevice).Interface())).Name();
boolean bDevReady = oDevice.ReadyConfig();
if ((bDevReady) && (sUse_Interface == ifacename)) {
foreach (sChnId, oDevice.Channels()) {
object oChannel = dom.GetObject(sChnId);
foreach(sDPId, oChannel.DPs().EnumUsedIDs()) {
object oDP = dom.GetObject(sDPId);
if (oDP && oDP.Timestamp()) {
if (oDP.TypeName() != "VARDP") {
if (dpFirst) {
dpFirst = false;
} else {
WriteLine(',');
}
string sValueType = oDP.ValueType();
Write('"');
WriteURL(oDP.Name());
Write('":');
if (sValueType == 20) {
Write('"');
WriteURL(oDP.Value());
if (oInterface) {
integer iInterface_ID = interfaces.Get(sUse_Interface).ID();
string sAllDevices = dom.GetObject(ID_DEVICES).EnumUsedIDs();
foreach (sDevId, sAllDevices) {
object oDevice = dom.GetObject(sDevId);
if ((oDevice) && (oDevice.ReadyConfig()) && (oDevice.Interface() == iInterface_ID)) {
foreach (sChnId, oDevice.Channels()) {
object oChannel = dom.GetObject(sChnId);
foreach(sDPId, oChannel.DPs().EnumUsedIDs()) {
object oDP = dom.GetObject(sDPId);
if (oDP && oDP.Timestamp()) {
if (oDP.TypeName() != "VARDP") {
if (bDPFirst) {
bDPFirst = false;
} else {
WriteLine(',');
}
integer sValueType = oDP.ValueType();
Write('"');
} else {
sValue = oDP.Value();
if (sValueType == 2) {
if (sValue) {
Write("true");
WriteURL(oDP.Name());
Write('":');
if (sValueType == 20) {
Write('"');
WriteURL(oDP.Value());
Write('"');
} else {
vDPValue = oDP.Value();
if (sValueType == 2) {
if (vDPValue) {
Write("true");
} else {
Write("false");
}
} else {
Write("false");
if (vDPValue == "") {
Write("0");
} else {
Write(vDPValue);
}
}
} else {
if (sValue == "") {
Write("0");
} else {
Write(sValue);
}
}
}
}
Expand Down

0 comments on commit 6449c96

Please sign in to comment.