AHA
view release on metacpan or search on metacpan
# Set to one if some debugging should be printed
my $DEBUG = 0;
=item $aha = new AHA({host => "fritz.box", password => "s!cr!t", user => "admin"})
=item $aha = new AHA("fritz.box","s!cr!t","admin")
Create a new AHA object for accessing a Fritz Box via the HTTP interface. The
parameters can be given as a hashref (for named parameters) or in a simple form
with host, password and user (optional) as unnamed arguments.
The named arguments which can be used:
=over
=item host
Name or IP of the Fritz box to access
=item port
Port to connect to. It's 80 by default
=item password
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;
$self->{user} = shift;
} else {
map { $self->{$_} = $arg1->{$_} } qw(host password user port);
}
die "No host given" unless $self->{host};
die "No password given" unless $self->{password};
my $base = $self->{port} ? $self->{host} . ":" . $self->{port} : $self->{host};
$self->{ua} = LWP::UserAgent->new;
$self->{login_url} = "http://" . $base . "/login_sid.lua";
$self->{ws_url} = "http://" . $base . "/webservices/homeautoswitch.lua";
$self->{ain_map} = {};
return bless $self,$class;
}
=item $switches = $aha->list()
List all switches know to AHA. An arrayref with L<AHA::Switch> objects is
returned, one for each device. When no switch is registered an empty arrayref
is returned.
=cut
sub list {
my $self = shift;
return [ map { new AHA::Switch($self,$_) } (split /\s*,\s*/,$self->_execute_cmd("getswitchlist")) ];
}
=item $aha->is_on($ain)
Check, whether the switch C<$ain> is in state "on", in which case this methods
returns 1. If it is "off", 0 is returned. If the switch is not connected,
C<undef> is returned.
=cut
sub is_on {
my $self = shift;
return &_inval_check($self->_execute_cmd("getswitchstate",$self->_ain(shift)));
}
=item $aha->on($ain)
Switch on the switch with the name or AIN C<$ain>.
=cut
sub on {
my $self = shift;
my $ain = $self->_ain(shift);
return $self->_execute_cmd("setswitchon",$ain);
}
=item $aha->off($ain)
Switch off the switch with the name or AIN C<$ain>.
=cut
sub off {
my $self = shift;
return $self->_execute_cmd("setswitchoff",$self->_ain(shift));
}
=item $is_present = $aha->is_present($ain)
Check whether the switch C<$ain> is present. This means, whether it is
registered at the Fritz Box at all in which case 1 is returned. If the switch
is not connected, 0 is returned.
=cut
sub is_present {
( run in 0.942 second using v1.01-cache-2.11-cpan-99c4e6809bf )