ntation on the TP-Link smart plug devices, including a more-or-less complete documentation of the JSON API.
=item * GadgetReactor's "pyHS100" project on GitHub
L<https://github.com/GadgetReactor/pyH
w();
...
=head1 SUBROUTINES/METHODS
=head2 passthrough
Recieves an object, formats it as a JSON command and passes it to the device. Returns a response object.
=cut
sub passthrough {
my $se
my $json = JSON->new->allow_nonref;
# Fun fact: For the HS105, your JSON cannot have any newlines in it, so no pretty JSON for us...
# $json = $json->pretty(1);
my $plaintext = $json->encode
$responseLength = 0; }
}
$responseData = decrypt($responseData);
my $responseDataScalar = $json->decode($responseData);
return $responseDataScalar;
}
=head2 function2
=cut
# Pass the comma
ce::TPLink::Kasa;
use 5.008003;
use Moose;
use Carp;
use JSON; # The Kasa API is JSON based
use LWP::JSON::Tiny; # Simplify working with JSON requests
use UUID::Generator::PurePerl; # Used to generat
= {
method => 'login',
params => $credentials
};
my $user_agent = LWP::UserAgent::JSON->new;
# Uncomment the next two lines if you need to debug...
#$user_agent->add_handler("reque
= HTTP::Request::JSON->new(POST => "https://wap.tplinkcloud.com");
$request->header('Accept' => '*/*'); # Really, really annoying, but required by Kasa service...
$request->json_content( $request
package Device::TPLink::SmartHome::Kasa;
use 5.008003;
use Moose;
use LWP::JSON::Tiny;
extends 'Device::TPLink::SmartHome';
has token => (
is => 'rw',
isa => 'Str',
);
=head1 NAME
Device::TPL
INES/METHODS
=head2 passthrough
Passes an arbitrary object to the device after converting it to JSON and wrapping it in a Kasa request. Used internally to package commands and send them to the devic
= @_;
my $json = JSON->new->allow_nonref;
$json = $json->pretty(1);
my $user_agent = LWP::UserAgent::JSON->new;
my $params = { deviceId => $self->deviceId, requestData => $json->encode($req
package Device::TPLink::SmartHome;
use 5.008003;
use Moose;
use Carp;
use JSON;
=head1 NAME
Device::TPLink::SmartHome - Base class for TPLink Smart Home devices
=head1 VERSION
Version 0.02
=cut
{
my $requestData = { system => { reboot => { delay => 1 }}};
return $requestData;
}
sub TO_JSON { return { %{ shift() } }; }
=head1 AUTHOR
Verlin Henderson, C<< <verlin at gmail.com> >>
=h