From fd940dc20fd06ec9f9ef8e203da4bb213047399b Mon Sep 17 00:00:00 2001 From: delmar <> Date: Sat, 20 Mar 2021 16:35:58 +0000 Subject: [PATCH] 72_TA_CMI_JSON: added set fixwertAnalog fixwertDigital git-svn-id: https://svn.fhem.de/fhem/trunk@24025 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/72_TA_CMI_JSON.pm | 217 +++++++++++++++++++----------------- 2 files changed, 116 insertions(+), 102 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index ac1d03541..4baaa5d9b 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 72_TA_CMI_JSON: added set fixwertAnalog fixwertDigital - change: 70_ZoneMinder: made Crypt dependency for v 1.30 optional - change: 48_BlinkCamera: Change to new Blink login API / add resetUniqueID - change: 47_OBIS: redesign of parser (major change) diff --git a/fhem/FHEM/72_TA_CMI_JSON.pm b/fhem/FHEM/72_TA_CMI_JSON.pm index 68487789e..695ad6ca4 100755 --- a/fhem/FHEM/72_TA_CMI_JSON.pm +++ b/fhem/FHEM/72_TA_CMI_JSON.pm @@ -43,6 +43,7 @@ use warnings; sub TA_CMI_JSON_Initialize { my ($hash) = @_; + $hash->{SetFn} = "TA_CMI_JSON::Set"; $hash->{GetFn} = "TA_CMI_JSON::Get"; $hash->{DefFn} = "TA_CMI_JSON::Define"; $hash->{UndefFn} = "TA_CMI_JSON::Undef"; @@ -135,7 +136,7 @@ BEGIN { )) }; -sub Define { +sub Define($$) { my ( $hash, $def ) = @_; my @a = split( "[ \t][ \t]*", $def ); @@ -164,7 +165,7 @@ sub Define { return undef; } -sub Notify { +sub Notify($$) { my ($own_hash, $dev_hash) = @_; my $ownName = $own_hash->{NAME}; # own name / hash @@ -179,7 +180,7 @@ sub Notify { } -sub SetupIntervals { +sub SetupIntervals($) { my ($hash) = @_; my $name = $hash->{NAME}; @@ -200,14 +201,14 @@ sub SetupIntervals { } -sub GetStatus { +sub GetStatus($) { my ( $hash ) = @_; my $name = $hash->{NAME}; PerformHttpRequest($hash); } -sub Undef { +sub Undef($$) { my ($hash, $arg) = @_; my $name = $hash->{NAME}; @@ -217,13 +218,13 @@ sub Undef { return undef; } -sub PerformHttpRequest { - my ($hash, $def) = @_; +sub PerformHttpRequest($) { + my ($hash) = @_; my $name = $hash->{NAME}; my $queryParam = $hash->{QUERYPARAM}; $queryParam = '' unless defined $queryParam; - my $url = "http://$hash->{CMIURL}/INCLUDE/api.cgi?jsonnode=$hash->{NODEID}&jsonparam=$queryParam"; + my $url = "http://$hash->{CMIURL}/INCLUDE/api.cgi?jsonnode=$hash->{NODEID}&jsonparam=$queryParam"."&_=".gettimeofday(); my $username = AttrVal($name, 'username', 'admin'); my $password = AttrVal($name, 'password', 'admin'); @@ -238,10 +239,11 @@ sub PerformHttpRequest { callback => \&ParseHttpResponse }; + Log3 $name, 4, "TA_CMI_JSON ($name) - PerformHttpRequest $url"; HttpUtils_NonblockingGet($param); } -sub ParseHttpResponse { +sub ParseHttpResponse($$$) { my ($param, $err, $data) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; @@ -311,17 +313,17 @@ sub ParseHttpResponse { return undef; } -sub extractDeviceName { +sub extractDeviceName($) { my ($input) = @_; return (defined($deviceNames{$input}) ? $deviceNames{$input} : 'unknown: ' . $input); } -sub extractVersion { +sub extractVersion($) { my ($input) = @_; return (defined($versions{$input}) ? $versions{$input} : 'unknown: ' . $input); } -sub extractReadings { +sub extractReadings($$$$) { my ( $hash, $keyValues, $id, $dataKey ) = @_; my $name = $hash->{NAME}; @@ -370,7 +372,80 @@ sub extractReadings { return undef; } -sub Get { +sub Set($$$@) { + my ( $hash, $name, $opt, @arg) = @_; + + Log3 $name, 5, "TA_CMI_JSON ($name) - Set: $name $opt ".join(' ', @arg); + + if ($opt eq 'fixwertAnalog' || $opt eq 'fixwertDigital') { + + my $index = $arg[0]; + my $value = $arg[1]; + + my $type; + if ($opt eq 'fixwertAnalog') { + $type = 'D1'; + } else { + $type = '1f'; + } + + FixwertChangeRequest($hash, $index, $value, $type); + + return undef; + } + + return 'fixwertAnalog fixwertDigital'; +} + +sub FixwertChangeRequest($$$$) { + my ($hash, $index, $value, $type) = @_; + my $name = $hash->{NAME}; + my $nodeId = $hash->{NODEID}; + my $cmiIp = $hash->{CMIURL}; + + my $hexNodeId = sprintf('%1x',$nodeId); + $hexNodeId = "0$hexNodeId" unless length($hexNodeId) == 2; + + $index--; #1 on the Web UI is index 0. 2 is 1, etc. + my $hexIndex = sprintf('%1x',$index); + $hexIndex = "0$hexIndex" unless length($hexIndex) == 2; + + my $referrer = "Referer: http://$cmiIp/menupagex.cgi?nodex2=".$hexNodeId."005800"; + my $url = "http://$cmiIp/INCLUDE/change.cgi?changeadrx2=".$hexNodeId."00".$hexIndex."4414".$type."01&changetox2=".$value."&_=".gettimeofday(); + my $username = AttrVal($name, 'username', 'admin'); + my $password = AttrVal($name, 'password', 'admin'); + + my $param = { + url => "$url", + timeout => 5, + hash => $hash, + method => "GET", + header => $referrer, + user => $username, + pwd => $password, + callback => \&FixwertChangeRequest_Callback + }; + + Log3 $name, 4, "TA_CMI_JSON ($name) - FixwertChangeRequest $url"; + HttpUtils_NonblockingGet($param); +} + +sub FixwertChangeRequest_Callback { +my ($param, $err, $data) = @_; + my $hash = $param->{hash}; + my $name = $hash->{NAME}; + + if($err ne "") { + Log3 $name, 0, "TA_CMI_JSON ($name) - error while calling ".$param->{url}." - $err"; + + } elsif($data ne "") { + Log3 $name, 5, "TA_CMI_JSON ($name) - FixwertChangeRequest_Callback: $data"; + } + + return undef; +} + +sub Get($$$$) { my ( $hash, $name, $opt, $args ) = @_; if ("update" eq $opt) { @@ -387,14 +462,14 @@ sub Get { return "Unknown argument $opt, choose one of update readOutputStates"; } -sub RequestOutputStates { +sub RequestOutputStates($) { my ($hash) = @_; my $name = $hash->{NAME}; my $nodeId = $hash->{NODEID}; my $hexNodeId = sprintf('%1x',$nodeId); $hexNodeId = "0$hexNodeId" unless length($hexNodeId) == 2; - my $url = "http://$hash->{CMIURL}/INCLUDE/agx2.cgi?nodex2=$hexNodeId"; + my $url = "http://$hash->{CMIURL}/INCLUDE/agx2.cgi?nodex2=$hexNodeId"."&_=".gettimeofday(); my $username = AttrVal($name, 'username', 'admin'); my $password = AttrVal($name, 'password', 'admin'); @@ -413,7 +488,7 @@ sub RequestOutputStates { HttpUtils_NonblockingGet($param); } -sub ParseOutputStateResponse { +sub ParseOutputStateResponse($$$) { my ($param, $err, $data) = @_; my $hash = $param->{hash}; my $name = $hash->{NAME}; @@ -471,90 +546,6 @@ sub ParseOutputStateResponse { return undef; } -my $counter = 0; - -sub DetailFn { - my $css = ''; - - -my $html = ' -
fixwertAnalog
set cmiNode fixwertAnalog <index> <value>
set cmiNode fixwertAnalog 3 64.0
fixwertDigital
set cmiNode fixwertDigital <index> <value>
set cmiNode fixwertDigital 2 1
update
fixwertAnalog
set cmiNode fixwertAnalog <index> <value>
set cmiNode fixwertAnalog 3 64.0
fixwertDigital
set cmiNode fixwertDigital <index> <value>
set cmiNode fixwertDigital 2 1
update