# $Id$
###############################################################################
#
# This file 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 .
#
#
###############################################################################
package main;
use 5.018;
use feature qw( lexical_subs );
use strict;
use warnings;
use utf8;
use Time::HiRes qw( gettimeofday tv_interval );
use HttpUtils;
no warnings qw( experimental::lexical_subs );
sub GSI_Initialize {
my ($hash) = @_;
$hash->{'DefFn'} = 'GSI_Define';
$hash->{'UndefFn'} = 'GSI_Undef';
$hash->{'NotifyFn'} = 'GSI_Notify';
$hash->{'FW_detailFn'} = 'GSI_FW_detailFn';
$hash->{'AttrList'} = "continuous:1,0 $readingFnAttributes ";
$hash->{'NOTIFYDEV'} = 'TYPE=Global';
return undef;
};
sub GSI_Define {
my ($hash, $def) = @_;
my ($name, $type, $plz) = split /\s/, $def;
my $cvsid = '$Id$';
$cvsid =~ s/^.*pm\s//;
$cvsid =~ s/Z\s\S+\s\$$//;
return "German ZIP code required" unless ($plz =~ m/\d{5}/);
$hash->{'ZIP'} = $plz;
$hash->{'SVN'} = $cvsid;
$attr{$name}{'devStateIcon'} = '{GSI::devStateIcon($name)}';
GSI_Run($hash) if ($init_done);
return undef;
};
sub GSI_Undef {
my ($hash) = @_;
RemoveInternalTimer($hash, \&GSI_ApiRequest);
RemoveInternalTimer($hash, \&GSI_doReadings);
return undef;
};
sub GSI_Notify {
my ($hash, $dev) = @_;
my $name = $hash->{'NAME'};
return undef if(IsDisabled($name));
my $events = deviceEvents($dev, 1);
return if(!$events);
foreach my $event (@{$events}) {
my @e = split /\s/, $event;
Log3 ($name, 5, sprintf('[%s] event:[%s], device:[%s]', $name, $event, $dev->{'NAME'}));
if ($dev->{'TYPE'} eq 'Global') {
if ($e[0] and $e[0] eq 'INITIALIZED') {
GSI_Run($hash);
};
};
};
};
sub GSI_FW_detailFn {
my ($FW_wname, $name, $FW_room) = @_;
my $hash = $defs{$name};
my $ret;
if (exists($hash->{'forecast'}) and scalar @{$hash->{'forecast'}}) {
my $fc = $hash->{'forecast'};
$ret = '
';
$ret .= sprintf(<<'HTML', 'Zeit', 'Index (EE)', 'Co2 (EE)', 'Co2 (Std.Mix)');
|
|
|
|
HTML
$ret .= '';
my $i = 0;
foreach my $e (@{$fc}) {
last if ($i++ == 24);
my $p0 = ($i % 2 == 1)?'odd':'even';
my $p1 = POSIX::strftime('%a %R (%D)', localtime($e->{'epochtime'}));
my $p2 = $e->{'eevalue'};
my $p3 = $e->{'co2_g_oekostrom'};
my $p4 = $e->{'co2_g_standard'};
$ret .= sprintf(<<'HTML', $p0, $p1, $i, $p2, $i, $p3, $i, $p4);
%s |
%i |
%s g/kWh |
%s g/kWh |
HTML
};
return "$ret