| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055 |
- # $Id: 70_WINCONNECT.pm 15003 2017-09-04 21:22:16Z michael.winkler $
- ############################################################################
- # 2017-09-04, v0.0.23
- #
- # v0.0.23
- # - BUFIX: [FEHMModul] - Download gitlab GUI
- # - CHANGE [FEHMModul] - Download Timeout WinControl.exe = 30
- # - FEATURE: [WinWebGUI] - NotifyIcon - Kontextmenü
- #
- # v0.0.22
- # - BUFIX: [FEHMModul] - Überreste Attribut "http-noshutdown" entfernt
- # - FEATURE: [FEHMModul] - Attribut "autoupdatewincontrol:0,1" Standard = 1 / 0 = Hier kann das automatische GUI Update deaktiviert werden.
- # - CHANGE [WinWebGUI] - Autoupdate über Attribut steuerbar
- #
- # v0.0.21
- # - BUFIX: [WinWebGUI] - FHEM Server Connect / Reconnect
- # [WinWebGUI] - shutdown / standby / hibernate
- # [WinWebGUI] - accept trusted SSL certificat
- # [WinWebGUI] - battery_ChargeStatus 0 ersetzt in Middle
- # - CHANGE [WinWebGUI] - Autoupdate immer angeschalten
- # [WinWebGUI] - select SSL protocols ssl3, tls, tlsv11, tlsv12
- # - FEATURE: [WinWebGUI] - Icon FHEM Connect = blau
- # Icon FHEM Disconnect = rot
- # Icon FHEM Wrong Device = gelb
- # [WinWebGUI] - FQDN oder Netbios Name as FHEM Server
- # [WinWebGUI] - Support button / collect support informations
- # [WinWebGUI] - WMI Abfragen / WMI Wizard
- # [WinWebGUI] - Support Core Temp
- #
- # v0.0.20
- # - BUFIX: [FEHMModul] - $_ ersetzt durch $uResult
- # [FEHMModul] - reading "memory_available" und "memory_total" ohne Zusatz MB
- # [WinWebGUI] - Exit Messagebox entfernt
- # - FEATURE: [WinWebGUI] - Exit Menübutton
- #
- # v0.0.18
- # - BUFIX: [WinWebGUI] - Autoupdate
- # [WinWebGUI] - Shutdown Messagebox
- #
- # v0.0.17
- # - BUFIX: [FEHMModul] - Code Optimierungen
- # - CHANGE [WinWebGUI] - FHEM Devicename check auf Gültigkeit https://forum.fhem.de/index.php/topic,59251.msg667257.html#msg667257
- # - FEATURE: [WinWebGUI] - Fenster verstecken https://forum.fhem.de/index.php/topic,59251.msg665863.html#msg665863
- #
- # v0.0.16 erste SVN Version
- # - BUFIX: Refresh CSRFTOKEN nach einem reconnect
- # Readings zurücksetzen wenn Offline
- # os_RunTime_days,os_RunTime_hours und os_RunTime_minutes
- # printer_aktiv und printer_names
- # div. Optimierungen
- # - FEATURE Attribut "win_resetreadings:0,1" Standard = 1 / 1 = Readings zurücksetzen wenn Offline
- # Attribut "autoupdategitlab:0,1" Standard = 1 / 0 = Hier kann der automatische Download deaktiviert werden.
- # - CHANGE Attribut "http-noshutdown" Auf Standwardwert "0" gesetzt
- #
- # v0.0.15
- # - BUFIX: Start optimiert / Log sortiert
- #
- # v0.0.14
- # - FEATURE: Winconnect mit Windows starten
- # Ausführen (minimiert/normales Fenster)
- # checkprocess (prüft ob ein Prozess gestartet ist inkl. Anzahl)
- # wincontrol.exe.config wird nicht mehr benötigt
- # Windows Version (os_Version & os_ReleaseID ab Win10)
- # Benutzer / Hostname (os_Username, os_Computername & os_Domainname)
- # Performance: CPU, Festplatte, Netzwerk, RAM, …
- # Hardware Ausrüstung: Prozessor, BIOS & RAM (memory_*, bios_* und cpu_*)
- # VolumeDown, VolumeUp (mit attr volumeStep)
- # Laufzeiten in Tage/Stunden/Minuten (os_RunTime_minutes, os_RunTime_hours und os_RunTime_days)
- # - BUFIX: checkservice (im FHEM Reading wurde immer nur der erste Service eingetragen)
- #
- # v0.0.13
- # - FEATURE: Performance Optimierungen
- # set powermode add(standby/hibernate)
- # drive informations (Space in MB/change only > 10MB)
- # - BUFIX: div.
- # Programmabsturtz nach ca. 4-5 Tagen
- #
- # v0.0.12
- # - FEATURE: CSRFToken
- # - BUFIX: Detect Audio Sound
- #
- # v0.0.11
- # - FEATURE: ttsmsg play sound
- # messagebox play sound
- # set camera (on/off)
- # make picture (camera)
- # motion detect (camera)
- # Update Winconnect.exe (inkl. autoupdate)
- # microphone sound detection
- # Startscreen
- # - BUFIX: .NET Fehlermeldung
- # set screen on
- # set screen off
- # - Readings: audio_devicename
- # microphone_devicename
- #
- # v0.0.10
- # - FEATURE: send notifymsg (set notifymsg Ballon Tip)
- # send messagebox (set messagebox)
- # Verzeichnis überwachen
- # set powermode (shutdown/restart)
- #
- # v0.0.9
- # - FEATURE: FHEM SSL
- #
- # v0.0.8
- # - FEATURE: FHEM Anmeldung (basicAuth)
- # volume mute (on/off)
- # - BUGFIX: statusrequest (firststart)
- # - Readings: speecherrormessage
- # speecherrormessagequality
- # speechmessagequality
- # mute
- #
- # v0.0.7 - 20161107
- # - BUGFIX: Umlaute beim senden einer ttsmsg
- # - FEATURE: set commandhide
- # set user_aktividletime
- # printer_aktiv
- # Spracherkennung
- #
- # v0.0.6 - 20161025
- # - BUFIX: no audiodevice
- # - FEATURE: set brightness 0 - 100
- #
- # v0.0.5 - 20161024
- # - BUGFIX
- #
- # v0.0.4 - 20161024
- # - BUGFIX: (Bereinigung wincontrol / FHEM readings)
- # - FEATURE: send ttsmsg (TextToSpeech)
- # - Readings: os_StartTime = Startzeit Windows
- # wincontrol_starttime = Startzeit WinControl
- # wincontrol_user = Benutzer der Wintrol gestartet hat
- # battery_ChargeStatus
- # battery_LifePercent
- # battery_LifeRemainingsMin
- # battery_PowerLineStatus
- #
- # v0.0.3 - 20161020
- # - FEATURE: set command
- # set showfile
- # set checkservice
- #
- # v0.0.0 - 20161018
- # - FEATURE: ON/OFF Windows Screen
- # set volume
- # detect playing audio
- #
- # Copyright by Michael Winkler
- # e-mail: michael.winkler at online.de
- #
- # This file is part of fhem.
- #
- # Fhem is free software: you can redistribute it andor modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 2 of the License, or
- # (at your option) any later version.
- #
- # Fhem is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with fhem. If not, see <http://www.gnu.org/licenses/>.
- #
- ##############################################################################
- package main;
- use strict;
- use warnings;
- use HttpUtils;
- use Time::Piece;
- sub WINCONNECT_Set($@);
- sub WINCONNECT_GetStatus($;$);
- sub WINCONNECT_Define($$);
- sub WINCONNECT_Undefine($$);
- # Autoupdateinformationen
- my $DownloadURL = "https://gitlab.com/michael.winkler/winconnect/raw/master/WinControl_0.0.23.exe";
- my $DownloadVer = "0.0.23";
- my $DownloadError = "";
- ###################################
- sub WINCONNECT_Initialize($) {
- my ($hash) = @_;
- Log3 $hash, 5, "WINCONNECT_Initialize: Entering";
- $hash->{SetFn} = "WINCONNECT_Set";
- $hash->{DefFn} = "WINCONNECT_Define";
- $hash->{UndefFn} = "WINCONNECT_Undefine";
- $hash->{AttrList} = "volumeStep win_resetreadings:0,1 disable:0,1 autoupdategitlab:0,1 autoupdatewincontrol:0,1 " . $readingFnAttributes;
- return;
- }
- #####################################
- # Get Status
- #####################################
- sub WINCONNECT_GetStatus($;$) {
- my ($hash, $update ) = @_;
- my $name = $hash->{NAME};
- my $interval = $hash->{INTERVAL};
- my $filemtime = "";
-
- if ($DownloadError eq "") {$DownloadError = ReadingsVal( $name, "wincontrol_error", "Start WinControl....." );}
-
- return if ( AttrVal( $name, "disable", 0 ) == 1 );
-
- InternalTimer( gettimeofday() + $interval, "WINCONNECT_GetStatus", $hash, 0 );
-
- my $filename = '././www/winconnect/WinControl.exe';
- my $filedir = '././www/winconnect';
-
- if ((-e $filename)) {$filemtime = (stat $filename)[9];}
-
- Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_GetStatus()";
- Log3 $name, 5, "WINCONNECT $name: filename = " . $filename . " filemtime = " . $filemtime;
-
- #Alte Readings bereinigen
- print (fhem( "deletereading $name wincontrol_gitlap" )) if ( ReadingsVal( $name, "wincontrol_gitlap", "0" ) ne "0" ) ;
- print (fhem( "deletereading $name wincontrol_gitlap_url" )) if ( ReadingsVal( $name, "wincontrol_gitlap_url", "0" ) ne "0" ) ;
-
- readingsBeginUpdate($hash);
-
- #WinControl Versionsinformationen
- readingsBulkUpdateIfChanged( $hash, "wincontrol_gitlab", $DownloadVer );
- readingsBulkUpdateIfChanged( $hash, "wincontrol_gitlab_url", $DownloadURL);
-
- #WinControl Update Info eintragen
- readingsBulkUpdateIfChanged( $hash, "wincontrol_update", $filemtime );
- readingsBulkUpdateIfChanged( $hash, "model", ReadingsVal( $name, "os_Name", "unbekannt" ) );
-
- #WinControl Last Error
- readingsBulkUpdateIfChanged( $hash, "wincontrol_error", $DownloadError);
-
- readingsEndUpdate( $hash, 1 );
-
- #Autoupdatefile von Gitlab herunterladen
- if ($DownloadURL ne '' && !(-e $filename . "_" .$DownloadVer) && AttrVal( $name, "autoupdategitlab", "1" ) ) {
-
- #Verzeichnis anlegen
- mkdir($filedir, 0777) unless(-d $filedir );
- if(!open (FILE, ">". $filename . "_" .$DownloadVer)) {
- $DownloadError = "WINCONNECT [NEW] Download ERROR Can't write = " .$filename . "_" .$DownloadVer . " Error=" .$!;
- Log3 $name, 5, $DownloadError;
- }else {
-
- print FILE $name;
- close (FILE);
-
- #Delete old version
- if ((-e $filename)) {unlink $filename}
-
- HttpUtils_NonblockingGet({url=>$DownloadURL, timeout=>30, hash=>$hash, service=>"autoupdate", callback=>\&WINCONNECT_GetNewVersion});
- }
- }
-
- if ( !$update ) {
- WINCONNECT_SendCommand( $hash, "powerstate" );
- }
- else {
- WINCONNECT_SendCommand( $hash, "statusrequest" );
- }
-
- return;
- }
- sub WINCONNECT_GetNewVersion($$$) {
- my ($hash, $err, $data) = @_;
- my $filename = '././www/winconnect/WinControl.exe';
- my $name = $hash->{NAME};
- my $CheckFile = $filename . "_" .$DownloadVer;
-
- # Download neue Datei
- if(!open(FH, ">$filename")) {
- $DownloadError = "Download ERROR Can't write = " .$filename . " Error=" .$!;
- Log3 $name, 5, "WINCONNECT [NEW] " .$DownloadError;
- #Delete Version Flag
- if ((-e $CheckFile)) {unlink $CheckFile}
- }else{
- print FH $data;
- close(FH);
- # Prüfen ob die Dateigröße passt!
- if ((stat $filename)[7] < 600000) {
- #Download fehlgeschlagen!
- if ((-e $CheckFile)) {unlink $CheckFile}
-
- $DownloadError = "Download ERROR file to small. Filesize = " . (stat $filename)[7];
- Log3 $name, 5, "WINCONNECT [NEW] " .$DownloadError;
- }else{
- Log3 $name, 0, "WINCONNECT [NEW] Download new version URL = $DownloadURL";
- Log3 $name, 0, "WINCONNECT [NEW] Download new version OK";
- $DownloadError = "Download new version = $DownloadVer";
- }
- }
- }
- ###################################
- sub WINCONNECT_SendCommand($$;$$) {
- my ( $hash, $service, $cmd ) = @_;
- my $name = $hash->{NAME};
- my $address = $hash->{helper}{ADDRESS};
- my $serviceurl = "";
- my $PWRState = ReadingsVal( $name, "state", "" );
- my $Winconnect = ReadingsVal( $name, "wincontrol", "statusrequest" );
- my $WinconnectUPD = ReadingsVal( $name, "wincontrol_update", "0" );
- my $URL;
- Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_SendCommand()";
- # Check Service and change serviceurl
- if ($service eq "statusrequest") {
- $serviceurl = "statusrequest";
- }
- elsif ($service eq "volume") {
- $serviceurl = "volume";
- }
- elsif ($service eq "file_dir") {
- $serviceurl = "file_dir";
- }
- elsif ($service eq "picture_dir") {
- $serviceurl = "picture_dir";
- }
- elsif ($service eq "camera") {
- $serviceurl = "camera";
- }
- elsif ($service eq "file_order") {
- $serviceurl = "file_order";
- }
- elsif ($service eq "file_filter") {
- $serviceurl = "file_filter";
- }
- elsif ($service eq "mute") {
- $serviceurl = "volumemute";
- }
- elsif ($service eq "speechcommands") {
- $serviceurl = "speechcommands";
- }
- elsif ($service eq "speechquality") {
- $serviceurl = "speechquality";
- }
- elsif ($service eq "brightness") {
- $serviceurl = "brightness";
- }
- elsif ($service eq "user_aktividletime") {
- $serviceurl = "user_aktividletime";
- }
- elsif ($service eq "powerstate") {
- if ( AttrVal( $name, "autoupdatewincontrol", 1 ) == 1 ) {$serviceurl = "powerstate" . "=" . $PWRState . ";" . $Winconnect . ";" . $WinconnectUPD;}
- else {$serviceurl = "powerstate" . "=" . $PWRState . ";" . $Winconnect . ";0";}
- }
- elsif ($service eq "command") {
- $serviceurl = "command";
- }
- elsif ($service eq "commandhide") {
- $serviceurl = "commandhide";
- }
- elsif ($service eq "update") {
- $serviceurl = "update";
- }
- elsif ($service eq "checkservice") {
- $serviceurl = "checkservice";
- }
- elsif ($service eq "checkperformance") {
- $serviceurl = "checkperformance";
- }
- elsif ($service eq "checkperformance_interval") {
- $serviceurl = "checkperformance_interval";
- }
- elsif ($service eq "checkprocess") {
- $serviceurl = "checkprocess";
- }
- elsif ($service eq "showfile") {
- $serviceurl = "showfile";
- }
- elsif ($service eq "ttsmsg") {
- $serviceurl = "ttsmsg";
- }
- elsif ($service eq "powermode") {
- $serviceurl = "powermode";
- }
- elsif ($service eq "messagebox") {
- $serviceurl = "messagebox";
- }
- elsif ($service eq "notifymsg") {
- $serviceurl = "notifymsg";
- }
- elsif ($service eq "screenon") {
- $serviceurl = "screen=on";
- }
- elsif ($service eq "picture_make") {
- $serviceurl = "picture_make";
- }
- elsif ($service eq "screenoff") {
- $serviceurl = "screen=off";
- }
- else{
- $serviceurl = $service;
- }
- # URL zusammenbauen
- $cmd = ( defined($cmd) ) ? $cmd : "";
- $URL = "http://" . $address . ":8183/fhem/" . $serviceurl . $cmd ;
- $URL =~ tr/\r\n/|/;
-
- Log3 $name, 6, "WINCONNECT $name: GET " . urlDecode($URL);
- HttpUtils_NonblockingGet(
- {
- url => $URL,
- timeout => 10,
- noshutdown => 0,
- #data => undef, 2017.07.20 - enfernt
- hash => $hash,
- service => $service,
- cmd => $cmd,
- #type => $type, 2017.07.20 - enfernt
- callback => \&WINCONNECT_ReceiveCommand
- }
- );
- return;
- }
- ###################################
- sub WINCONNECT_Set($@) {
- my ( $hash, @a ) = @_;
- my $name = $hash->{NAME};
- my $state = ReadingsVal( $name, "state", "absent" );
- my $cmd = "";
- my $Value = "";
- my $Count = 0;
- my $SetValue = 0;
-
- Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_Set()";
- my $usage = "choose one of volume:slider,0,1,100 mute:on,off camera:on,off powermode:shutdown,restart,standby,hibernate volumeUp:noArg volumeDown:noArg brightness:slider,0,1,100 picture_make:noArg update:noArg speechquality:slider,0,1,100 statusRequest:noArg screenOn:noArg screenOff:noArg command commandhide showfile picture_dir checkperformance_interval checkperformance:textField-long checkservice checkprocess notifymsg messagebox file_dir file_filter file_order:ascending,descending ttsmsg user_aktividletime speechcommands";
- return "No Argument given" if ( !defined( $a[1] ) );
- # statusRequest
- if ( lc( $a[1] ) eq "statusrequest" ) {
- Log3 $name, 3, "WINCONNECT set $name " . $a[1];
- WINCONNECT_SendCommand( $hash, "statusrequest" );
- }
-
- # on
- elsif ( lc( $a[1] ) eq "on" ) {
- readingsSingleUpdate( $hash, "state", "on",1 );
- }
- # powerstate
- elsif ( lc( $a[1] ) eq "powerstate" ) {
- Log3 $name, 3, "WINCONNECT set $name " . $a[1];
- WINCONNECT_SendCommand( $hash, "powerstate" );
- }
- # update
- elsif ( lc( $a[1] ) eq "update" ) {
- Log3 $name, 3, "WINCONNECT set $name " . $a[1];
- WINCONNECT_SendCommand( $hash, "update" );
- }
-
- # off
- elsif ( lc( $a[1] ) eq "off" ) {
- readingsSingleUpdate( $hash, "state", "off",1 );
- }
-
- # screenOn
- elsif ( lc( $a[1] ) eq "screenon" ) {
- Log3 $name, 3, "WINCONNECT set $name " . $a[1];
- if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "screenon" );}else {return "Device needs to be ON to adjust screenon.";}
- }
-
- #screenOff
- elsif ( lc( $a[1] ) eq "screenoff" ) {
- Log3 $name, 3, "WINCONNECT set $name " . $a[1];
- if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "screenoff" );}else {return "Device needs to be ON to adjust screenoff.";}
- }
-
- # volume
- elsif ( lc( $a[1] ) eq "volume" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- $SetValue = $a[2];
- if ($SetValue >= 0 && $SetValue <= 100 ) {
- $cmd = $a[2];
- }
- else {
- return "Argument $SetValue does not seem to be a valid integer between 0 and 100";
- }
- WINCONNECT_SendCommand( $hash, "volume" , "=" . $cmd );
- readingsSingleUpdate( $hash, "volume", $cmd,1 );
- }
- else {return "Device needs to be ON to adjust volume.";}
- }
-
- # volumeUp
- elsif ( lc( $a[1] ) eq "volumeup" ) {
- my $volumeStep = int(AttrVal($name, "volumeStep", 5));
- my $volumenow = ReadingsVal( $name, "volume", 0);
- my $volumeNew = $volumenow + $volumeStep;
-
- if ($volumeNew > 100) {$volumeNew = 100;}
-
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $volumeNew;
- if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "volume" , "=" . $volumeNew );readingsSingleUpdate( $hash, "volume", $volumeNew,1 );}else {return "Device needs to be ON to adjust volume.";}
- }
-
- # volumeDown
- elsif ( lc( $a[1] ) eq "volumedown" ) {
- my $volumeStep = int(AttrVal($name, "volumeStep", 5));
- my $volumenow = ReadingsVal( $name, "volume", 0);
- my $volumeNew = $volumenow - $volumeStep;
-
- if ($volumeNew < 0) {$volumeNew = 0;}
-
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $volumeNew;
- if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "volume" , "=" . $volumeNew );readingsSingleUpdate( $hash, "volume", $volumeNew,1 );}else {return "Device needs to be ON to adjust volume.";}
- }
-
- # mute
- elsif ( lc( $a[1] ) eq "mute" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- WINCONNECT_SendCommand( $hash, "volumemute" , "=" . $a[2] );
- readingsSingleUpdate( $hash, "mute", $a[2],0 );
- }
- else {return "Device needs to be ON to adjust volume mute.";}
- }
- # powermode
- elsif ( lc( $a[1] ) eq "powermode" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- WINCONNECT_SendCommand( $hash, "powermode" , "=" . $a[2] );
- }
- else {return "Device needs to be ON to adjust powermode.";}
- }
-
- # user_aktividletime
- elsif ( lc( $a[1] ) eq "user_aktividletime" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- $SetValue = $a[2];
- if ($SetValue >= 0 && $SetValue <= 10000 ) {
- $cmd = $a[2];
- }
- else {
- return "Argument does not seem to be a valid integer between 0 and 10000";
- }
- WINCONNECT_SendCommand( $hash, "user_aktividletime" , "=" . $cmd );
- readingsSingleUpdate( $hash, "user_aktividletime", $cmd,1 );
- }
- else {return "Device needs to be ON to adjust user_aktividletime.";}
- }
-
- # brightness
- elsif ( lc( $a[1] ) eq "brightness" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- $SetValue = $a[2];
- if ($SetValue >= 0 && $SetValue <= 100 ) {
- $cmd = $a[2];
- }
- else {
- return "Argument does not seem to be a valid integer between 0 and 100";
- }
- WINCONNECT_SendCommand( $hash, "brightness" , "=" . $cmd );
- readingsSingleUpdate( $hash, "brightness", $cmd,1 );
- }
- else {return "Device needs to be ON to adjust brightness.";}
- }
-
- # speechquality
- elsif ( lc( $a[1] ) eq "speechquality" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- $SetValue = $a[2];
- if ($SetValue >= 0 && $SetValue <= 100 ) {
- $cmd = $a[2];
- }
- else {
- return "Argument does not seem to be a valid integer between 0 and 100";
- }
- WINCONNECT_SendCommand( $hash, "speechquality" , "=" . $cmd );
- readingsSingleUpdate( $hash, "speechquality", $cmd,1 );
- }
- else {return "Device needs to be ON to adjust speechquality.";}
- }
-
- # command
- elsif ( lc( $a[1] ) eq "command" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "command" , "=" . $cmd );
- }
- else {return "Device needs to be ON to execute command.";}
- }
-
- # commandhide
- elsif ( lc( $a[1] ) eq "commandhide" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "commandhide" , "=" . $cmd );
- }
- else {return "Device needs to be ON to execute commandhide.";}
- }
-
- # showfile
- elsif ( lc( $a[1] ) eq "showfile" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "showfile" , "=" . $cmd );
- }
- else {return "Device needs to be ON to showfile.";}
- }
-
- # ttsmsg
- elsif ( lc( $a[1] ) eq "ttsmsg" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "ttsmsg" , "=" . $cmd );
- readingsSingleUpdate( $hash, "ttsmsg", $Value,1 );
- }
- else {return "Device needs to be ON to send ttsmsg.";}
- }
- # messagebox
- elsif ( lc( $a[1] ) eq "messagebox" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "messagebox" , "=" . $cmd );
- readingsSingleUpdate( $hash, "messagebox", $Value,1 );
- }
- else {return "Device needs to be ON to send messagebox.";}
- }
-
- # notifymsg
- elsif ( lc( $a[1] ) eq "notifymsg" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "notifymsg" , "=" . $cmd );
- readingsSingleUpdate( $hash, "notifymsg", $Value,1 );
- }
- else {return "Device needs to be ON to send notifymsg.";}
- }
-
- # checkservice
- elsif ( lc( $a[1] ) eq "checkservice" ) {
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- readingsSingleUpdate( $hash, "checkservice", $Value,1 );
- WINCONNECT_SendCommand( $hash, "checkservice" , "=" . $cmd );
- }
- else {return "Device needs to be ON to checkservice.";}
- }
- # checkperformance
- elsif ( lc( $a[1] ) eq "checkperformance" ) {
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- readingsSingleUpdate( $hash, "checkperformance", $Value,1 );
- WINCONNECT_SendCommand( $hash, "checkperformance" , "=" . $cmd );
- }
- else {return "Device needs to be ON to checkperformance.";}
- }
- # checkperformance_interval
- elsif ( lc( $a[1] ) eq "checkperformance_interval" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- $SetValue = $a[2];
- if ($SetValue >= 10 && $SetValue <= 10000 ) {
- $cmd = $a[2];
- }
- else {
- return "Argument does not seem to be a valid integer between 10 and 10000";
- }
- WINCONNECT_SendCommand( $hash, "checkperformance_interval" , "=" . $cmd );
- readingsSingleUpdate( $hash, "checkperformance_interval", $cmd,0 );
- }
- else {return "Device needs to be ON to adjust checkperformance_interval.";}
- }
-
- # checkprocess
- elsif ( lc( $a[1] ) eq "checkprocess" ) {
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- readingsSingleUpdate( $hash, "checkprocess", $Value,1 );
- WINCONNECT_SendCommand( $hash, "checkprocess" , "=" . $cmd );
- }
- else {return "Device needs to be ON to checkprocess.";}
- }
-
- # speechcommands
- elsif ( lc( $a[1] ) eq "speechcommands" ) {
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "speechcommands" , "=" . $cmd );
- readingsSingleUpdate( $hash, "speechcommands", $Value,1 );
- }
- else {return "Device needs to be ON to speechcommands.";}
- }
- # file_dir
- elsif ( lc( $a[1] ) eq "file_dir" ) {
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "file_dir" , "=" . $cmd );
- readingsSingleUpdate( $hash, "file_dir", $Value,1 );
- }
- else {return "Device needs to be ON to file_dir.";}
- }
-
- # file_filter
- elsif ( lc( $a[1] ) eq "file_filter" ) {
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "file_filter" , "=" . $cmd );
- readingsSingleUpdate( $hash, "file_filter", $Value,0 );
- }
- else {return "Device needs to be ON to file_filter.";}
- }
- # file_order
- elsif ( lc( $a[1] ) eq "file_order" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- WINCONNECT_SendCommand( $hash, "file_order" , "=" . $a[2] );
- readingsSingleUpdate( $hash, "file_order", $a[2],1 );
- }
- else {return "Device needs to be ON to adjust file_order.";}
- }
- # picture_dir
- elsif ( lc( $a[1] ) eq "picture_dir" ) {
- if ( $state eq "on" ) {
-
- foreach (@a) {
- if ($cmd eq "") {$cmd = $_ ;} else {$cmd = $cmd . "%20" . $_ ;}
- $Count = $Count + 1;
- if ($Count >= 3 ) {if ($Value eq "") {$Value = $_ ;} else {$Value = $Value . " " . $_ ;}}
- }
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $cmd;
- WINCONNECT_SendCommand( $hash, "picture_dir" , "=" . $cmd );
- readingsSingleUpdate( $hash, "picture_dir", $Value,1 );
- }
- else {return "Device needs to be ON to picture_dir.";}
- }
- # picture_make
- elsif ( lc( $a[1] ) eq "picture_make" ) {
- Log3 $name, 3, "WINCONNECT set $name " . $a[1];
- if ( $state eq "on" ) {WINCONNECT_SendCommand( $hash, "picture_make" );}else {return "Device needs to be ON to adjust picture_make.";}
- }
- # camera
- elsif ( lc( $a[1] ) eq "camera" ) {
- return "No argument given" if ( !defined( $a[2] ) );
- Log3 $name, 3, "WINCONNECT set $name " . $a[1] . " " . $a[2];
- if ( $state eq "on" ) {
- WINCONNECT_SendCommand( $hash, "camera" , "=" . $a[2] );
- }
- else {return "Device needs to be ON to adjust camera.";}
- }
-
- # return usage hint
- else {return $usage;}
- return;
- }
- ###################################
- sub WINCONNECT_Define($$) {
- my ( $hash, $def ) = @_;
- my @a = split( "[ \t][ \t]*", $def );
- my $name = $hash->{NAME};
-
- Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_Define()";
- if ( int(@a) < 2 ) {
- my $msg = "Wrong syntax: define <name> WINCONNECT <ip-or-hostname> [<poll-interval>] ";
- Log3 $name, 4, $msg;
- return $msg;
- }
- $hash->{TYPE} = "WINCONNECT";
- my $address = $a[2];
- $hash->{helper}{ADDRESS} = $address;
- # use interval of 45sec if not defined
- my $interval = $a[3] || 45;
- $hash->{INTERVAL} = $interval;
-
- # set default settings on first define
- if ($init_done) {
- $attr{$name}{icon} = 'it_server';
- }
-
- # start the status update timer
- #RemoveInternalTimer($hash);
- InternalTimer( gettimeofday() + 2, "WINCONNECT_GetStatus", $hash, 1);
-
- return;
- }
- sub WINCONNECT_ReceiveCommand($) {
- my ($param, $err, $data) = @_;
- my $hash = $param->{hash};
- my $name = $hash->{NAME};
- my $VerWin = substr(ReadingsVal( $name, "wincontrol", "0.0.0.0" ),4);
- my $VerGit = substr(ReadingsVal( $name, "wincontrol_gitlab", "0.0.0.0" ),4);
- my $service = $param->{service};
-
- readingsBeginUpdate($hash);
-
- # Versionsnachricht
- my $Message = $name . "%20NOTIFYMSG%20Neue%20WinConnect%20Version%20verfügbar!%20Downloadlink%20=%20" . $DownloadURL;
-
- if($err ne "") {
- Log3 $name, 5, "WINCONNECT $name: error while requesting ".$param->{url}." - $err";
- readingsBulkUpdateIfChanged( $hash, "state", "off" );
- readingsBulkUpdateIfChanged( $hash, "audio", "off");
-
- if (AttrVal($name, "win_resetreadings", 1) eq '1') {
- readingsBulkUpdateIfChanged( $hash, "user_aktiv", "false" );
- readingsBulkUpdateIfChanged( $hash, "os_RunTime_days", "0" );
- readingsBulkUpdateIfChanged( $hash, "os_RunTime_hours", "0" );
- readingsBulkUpdateIfChanged( $hash, "os_RunTime_minutes", "0" );
- readingsBulkUpdateIfChanged( $hash, "printer_aktiv", "false" );
- readingsBulkUpdateIfChanged( $hash, "printer_names", "no_prining" );
- }
- }
-
- elsif($data ne "")
- {
- readingsBulkUpdateIfChanged( $hash, "state", "on" );
- Log3 $name, 5, "WINCONNECT $name: url ".$param->{url}." returned: $data";
-
- if(!defined($hash->{helper}{SENDVERSION})) {$hash->{helper}{SENDVERSION}='';}
-
- # 2017.07.26 - Check update
- if ( AttrVal( $name, "autoupdatewincontrol", 1 ) == 1 ) {
- if ($VerWin < $VerGit && $hash->{helper}{SENDVERSION} eq '2' && $service ne 'notifymsg') {
- # Neue Version vorhanden
- $hash->{helper}{SENDVERSION} = '1';
- WINCONNECT_SendCommand( $hash, "notifymsg" , "=" . $Message);
- } else{
- delete($hash->{helper}{SENDVERSION})
- }
- }
- }
- readingsEndUpdate( $hash, 1 );
- }
- ############################################################################################################
- #
- # Begin of helper functions
- #
- ############################################################################################################
- ###################################
- sub WINCONNECT_Undefine($$) {
- my ( $hash, $arg ) = @_;
- my $name = $hash->{NAME};
- Log3 $name, 5, "WINCONNECT $name: called function WINCONNECT_Undefine()";
- # Stop the internal GetStatus-Loop and exit
- RemoveInternalTimer($hash);
- return;
- }
- 1;
- =pod
- =item device
- =item summary control for Windows based systems via network connection
- =item summary_DE Steuerung von Windows basierte Systemen über das Netzwerk
- =begin html
- <a name="WINCONNECT"></a>
- <h3>WINCONNECT</h3>
- <ul>
- This module controls a Windows PC.
- <br><br>
-
- <ul>
- <a name="WINCONNECTdefine" id="WINCONNECTdefine"></a> <b>Define</b>
- <ul>
- <code>define <name> WINCONNECT <ip-address-or-hostname> [<poll-interval>]</code><br>
- <br>
- Defining an WINCONNECT device will schedule an internal task (interval can be set with optional parameter <poll-interval> in seconds, if not set, the value is 45 seconds), which periodically reads the status of the device and triggers notify/filelog commands.<br>
- <br>
- Example:<br>
- <ul>
- <code>define Buero.PC WINCONNECT 192.168.0.10<br>
- <br>
- # With custom interval of 60 seconds<br>
- define Buero.PC WINCONNECT 192.168.0.10 60<br></code>
- </ul>
- </ul>
- </ul>
-
- <br><br>
- More information on <a target="_blank" href="https://wiki.fhem.de/wiki/WINCONNECT">FHEM Wiki</a>.<br/>
- <br>
- </ul>
- =end html
- =begin html_DE
- <a name="WINCONNECT"></a>
- <h3>WINCONNECT</h3>
- <ul>
- Dieses Module dient zur Steuerung eines Windows PCs
- <br><br>
-
- <ul>
- <a name="WINCONNECTdefine" id="WINCONNECTdefine"></a> <b>Define</b>
- <ul>
- <code>define <name> WINCONNECT <ip-address-or-hostname> [<poll-interval>]</code><br>
- <br>
- Für definierte WINCONNECT Geräte wird ein interner Task angelegt, welcher periodisch die Readings aktualisiert. Der Standartpollintervall ist 45 Sekunden.<br>
- <br>
- Example:<br>
- <ul>
- <code>define Buero.PC WINCONNECT 192.168.0.10<br>
- <br>
- # Alternativer poll intervall von 60 seconds<br>
- define Buero.PC WINCONNECT 192.168.0.10 60<br></code>
- </ul>
- </ul>
- </ul>
- <br><br>
- Mehr Information im <a target="_blank" href="https://wiki.fhem.de/wiki/WINCONNECT">FHEM Wiki</a>.<br/>
- <br>
- </ul>
- =end html_DE
- =cut
|