######################################################################################################################## # $Id: $ ######################################################################################################################### # 60_Watches.pm # # (c) 2018 by Heiko Maaz # e-mail: Heiko dot Maaz at t-online dot de # # This script is part of fhem. # # Fhem is free software: you can redistribute it and/or 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 . # # The script is based on sources from following sites: # # modern clock: https://www.w3schools.com/graphics/canvas_clock_start.asp # # station clock: http://www.3quarks.com/de/Bahnhofsuhr/ # # digital clock: http://www.3quarks.com/de/Segmentanzeige/index.html # ######################################################################################################################### package main; use strict; use warnings; # Versions History intern our %Watches_vNotesIntern = ( "0.4.0" => "20.11.2018 text display ", "0.3.0" => "19.11.2018 digital clock added ", "0.2.0" => "14.11.2018 station clock added ", "0.1.0" => "13.11.2018 initial Version with modern analog clock" ); sub Watches_modern($); ################################################################ sub Watches_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "Watches_Define"; $hash->{AttrList} = "digitalColorBackground:colorpicker ". "digitalColorDigits:colorpicker ". "digitalDisplayPattern:text,watch ". "digitalDisplayText ". "modernColorBackground:colorpicker ". "modernColorHand:colorpicker ". "modernColorFigure:colorpicker ". "modernColorFace:colorpicker ". "modernColorRing:colorpicker ". "modernColorRingEdge:colorpicker ". "stationSecondHand:Bar,HoleShaped,NewHoleShaped,No ". "stationSecondHandBehavoir:Bouncing,Overhasty,Creeping,ElasticBouncing ". "stationMinuteHandBehavoir:Bouncing,Creeping,ElasticBouncing ". "stationBoss:Red,Black,Vienna,No ". "stationMinuteHand:Bar,Pointed,Swiss,Vienna ". "stationHourHand:Bar,Pointed,Swiss,Vienna ". "stationStrokeDial:GermanHour,German,Austria,Swiss,Vienna,No ". "stationBody:Round,SmallWhite,RoundGreen,Square,Vienna,No ". "disable:1,0 ". "htmlattr ". "hideDisplayName:1,0 " ; $hash->{FW_summaryFn} = "Watches_FwFn"; $hash->{FW_detailFn} = "Watches_FwFn"; $hash->{AttrFn} = "Watches_Attr"; $hash->{FW_hideDisplayName} = 1; # Forum 88667 # $hash->{FW_addDetailToSummary} = 1; $hash->{FW_atPageEnd} = 1; # wenn 1 -> kein Longpoll ohne informid in HTML-Tag } ################################################################ sub Watches_Define($$) { my ($hash, $def) = @_; my $name = $hash->{NAME}; my @a = split("[ \t][ \t]*", $def); if(!$a[2]) { return "You need to specify more parameters.\n". "Format: define Watches [Modern | Station | Digital]"; } $hash->{MODEL} = $a[2]; $hash->{VERSION} = $hash->{VERSION} = (reverse sort(keys %Watches_vNotesIntern))[0]; readingsSingleUpdate($hash,"state", "initialized", 1); # Init für "state" return undef; } ################################################################ sub Watches_Attr($$$$) { my ($cmd,$name,$aName,$aVal) = @_; my $hash = $defs{$name}; my ($do,$val); # $cmd can be "del" or "set" # $name is device name # aName and aVal are Attribute name and value if ($cmd eq "set" && $hash->{MODEL} !~ /modern/i && $aName =~ /^modern.*/) { return "\"$aName\" is only valid for Watches model \"Modern\""; } if ($cmd eq "set" && $hash->{MODEL} !~ /station/i && $aName =~ /^station.*/) { return "\"$aName\" is only valid for Watches model \"Station\""; } if ($cmd eq "set" && $hash->{MODEL} !~ /digital/i && $aName =~ /^digital.*/) { return "\"$aName\" is only valid for Watches model \"Digital\""; } if ($aName eq "disable") { if($cmd eq "set") { $do = ($aVal) ? 1 : 0; } $do = 0 if($cmd eq "del"); $val = ($do == 1 ? "disabled" : "initialized"); readingsSingleUpdate($hash, "state", $val, 1); } return undef; } ################################################################ sub Watches_FwFn($$$$) { my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn. my $hash = $defs{$d}; my $alias = AttrVal($d, "alias", $d); # Linktext als Aliasname oder Devicename setzen my $dlink = "$alias"; my $ret = ""; $ret .= "$dlink
" if(!AttrVal($d,"hideDisplayName",0)); if(IsDisabled($d)) { if(AttrVal($d,"hideDisplayName",0)) { $ret .= "Watch $d is disabled"; } else { $ret .= "Watch is disabled"; } } else { $ret .= Watches_modern($d) if($hash->{MODEL} =~ /modern/i); $ret .= Watches_station($d) if($hash->{MODEL} =~ /station/i); $ret .= Watches_digital($d) if($hash->{MODEL} =~ /digital/i); } return $ret; } ################################################################ sub Watches_digital($) { my ($d) = @_; my $hash = $defs{$d}; my $hattr = AttrVal($d,"htmlattr","width='150' height='50'"); my $bgc = AttrVal($d,"digitalColorBackground","C4C4C4"); my $dcd = AttrVal($d,"digitalColorDigits","000000"); my $ddp = AttrVal($d,"digitalDisplayPattern","watch"); my $ddt = AttrVal($d,"digitalDisplayText","Play"); if($ddp eq "watch") { $ddp = "##:##:##"; $ddt = " "."((hours < 10) ? ' ' : '') + hours + ':' + ((minutes < 10) ? '0' : '') + minutes + ':' + ((seconds < 10) ? '0' : '') + seconds"; } elsif($ddp eq "text") { $ddp = "##########"; my $txtc = length($ddt); $ddp = ""; for(my $i = 0; $i <= $txtc; $i++) { $ddp .= "#"; } $ddt = "' ".$ddt."'"; } # Segmentanzeige aus: http://www.3quarks.com/de/Segmentanzeige/index.html return " "; } ################################################################ sub Watches_station($) { my ($d) = @_; my $hash = $defs{$d}; my $ssh = AttrVal($d,"stationSecondHand","Bar")."SecondHand"; my $shb = AttrVal($d,"stationSecondHandBehavoir","Bouncing")."SecondHand"; my $smh = AttrVal($d,"stationMinuteHand","Pointed")."MinuteHand"; my $mhb = AttrVal($d,"stationMinuteHandBehavoir","Bouncing")."MinuteHand"; my $shh = AttrVal($d,"stationHourHand","Pointed")."HourHand"; my $sb = AttrVal($d,"stationBoss","Red")."Boss"; my $ssd = AttrVal($d,"stationStrokeDial","Swiss")."StrokeDial"; my $sbody = AttrVal($d,"stationBody","Round")."Body"; my $hattr = AttrVal($d,"htmlattr","width='150' height='150'"); # Bahnhofsuhr aus http://www.3quarks.com/de/Bahnhofsuhr/ return " "; } ################################################################ sub Watches_modern($) { my ($d) = @_; my $hash = $defs{$d}; my $facec = AttrVal($d,"modernColorFace","FFFEFA"); my $bgc = AttrVal($d,"modernColorBackground","333"); my $fc = AttrVal($d,"modernColorFigure","333"); my $hc = AttrVal($d,"modernColorHand","333"); my $fr = AttrVal($d,"modernColorRing","FFFFFF"); my $fre = AttrVal($d,"modernColorRingEdge","333"); my $hattr = AttrVal($d,"htmlattr","width='150' height='150'"); # moderne Uhr aus https://www.w3schools.com/graphics/canvas_clock_start.asp return " "; } 1; =pod =item helper =item summary create a watch in modern, station or digital style =item summary_DE erstellt eine Uhr: Modern, Bahnhofsuhr oder Digital =begin html

Watches


Das Modul Watches stellt eine Modern-, Bahnhofs- oder Digitalanzeige als Device zur Verfügung.
Die Uhren basieren auf Skripten dieser Seiten:
moderne Uhr, Bahnhofsuhr, Digitalanzeige

=end html =begin html_DE

Watches


Das Modul Watches stellt eine Modern-, Bahnhofs- oder Digitalanzeige als Device zur Verfügung.
Die Uhren basieren auf Skripten dieser Seiten:
moderne Uhr, Bahnhofsuhr, Digitalanzeige

=end html_DE =cut