AHA
view release on metacpan or search on metacpan
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
example/lava_lamp.pl view on Meta::CPAN
=item list
This scripts logs all activities in a log file C<$LOG_FILE>. With the "list"
mode, all history entries can be viewed.
=back
=cut
# ===========================================================================
# Configuration section
# Configuration required for accessing the switch.
my $SWITCH_CONFIG =
{
# AVM AHA Host for controlling the devices
host => "fritz.box",
# AVM AHA Password for connecting to the $AHA_HOST
password => "s!cr!t",
# AVM AHA user role (undef if no roles are in use)
user => undef,
# Name of AVM AHA switch
id => "Lava Lamp"
};
# Time how long the lamp should be at least be kept switched off (seconds)
my $LAMP_REST_TIME = 60 * 60;
# Maximum time a lamp can be on
my $LAMP_MAX_TIME = 5 * 60 * 60; # 5 hours
# When the lamp can be switched on. The values can contain multiple time
# windows defined as arrays
my $LAMP_ON_TIME_TABLE =
{
"Sun" => [ ["7:55", "23:00"] ],
example/lava_lamp.pl view on Meta::CPAN
# File holding the lamp's status
my $STATUS_FILE = "/var/run/lamp.status";
# Log file where to log to
my $LOG_FILE = "/var/log/lamp.log";
# Stop file, when, if exists, keeps the lamp off
my $OFF_FILE = "/tmp/lamp_off";
# Time back in passed assumed when switching was done manually (seconds)
# I.e. if a manual state change is detected, it is assumed that it was back
# that amount of seconds in the past (5 minutes here)
my $MANUAL_DELTA = 5 * 60;
# Maximum number of history entries to store
my $MAX_HISTORY_ENTRIES = 1000;
# ============================================================================
# End of configuration
use Storable qw(fd_retrieve store_fd store retrieve);
use Data::Dumper;
example/lava_lamp.pl view on Meta::CPAN
# If it is a problem and the lamp is not on, switch it on,
# but only if the lamp is not 'hot' (i.e. was not switch off only
# $LAMP_REST_TIME
my $last_hist = get_last_entry($status);
my $rest_time = time - $LAMP_REST_TIME;
if (!$last_hist || $last_hist->[0] < $rest_time) {
$lamp->on();
update_status($status,1,$mode,time,$opts{label});
} else {
info("Lamp not switched on because the lamp was switched off just before ",
time - $last_hist->[0]," seconds");
}
} else {
# Notification received offtime, remember to switch on the lamp
# when in time
info("Notification received in an off-period: type = ",$type," | ",$opts{label});
set_trigger($status,$opts{label});
}
} elsif (lc($type) eq 'recovery') {
if ($is_on) {
# If it is a recovery switch it off
Password for connecting to the Fritz Box
=item user
User role for login. Only required if a role based login is configured for the
Fritz box
=back
If used without an hashref as argument, the first argument must be the host,
the second the password and the third optionally the user.
=cut
sub new {
my $class = shift;
my $self = {};
my $arg1 = shift;
if (ref($arg1) ne "HASH") {
$self->{host} = $arg1;
$self->{password} = shift;
=cut
sub logout {
my $self = shift;
return unless $self->{sid};
# Send a post request as defined in
# http://www.avm.de/de/Extern/files/session_id/AVM_Technical_Note_-_Session_ID.pdf
my $req = HTTP::Request->new(POST => $self->{login_url});
$req->content_type("application/x-www-form-urlencoded");
my $login = "sid=".$self->{sid}."&security:command/logout=fcn";
$req->content($login);
my $resp = $self->{ua}->request($req);
die "Cannot logout SID ",$self->{sid},": ",$resp->status_line unless $resp->is_success;
print "--- Logout ",$self->{sid} if $DEBUG;
delete $self->{sid};
}
=back
lib/AHA/Switch.pm view on Meta::CPAN
=over
=cut
package AHA::Switch;
use vars qw{$AUTOLOAD};
=item $switch = new AHA::Switch($aha,$ain)
Create a new switch object. The first object must be an L<"AHA"> instance,
which is responsible for the HTTP communication. The second argument Many must
be an 8-digit AIN (actor id) or a symbolic name. This symbolic name
can be configured in the admin UI of the Fritz Box.
=cut
sub new {
my $class = shift;
my $aha = shift;
my $self = {
aha => $aha,
( run in 0.588 second using v1.01-cache-2.11-cpan-39bf76dae61 )