Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changed base URI. Fiddled with methods.
  • Loading branch information
davorg committed Jan 22, 2017
1 parent 1730f5a commit 5e50679
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
7 changes: 6 additions & 1 deletion gettemp
Expand Up @@ -17,6 +17,11 @@ my $hive = Hive->new({
password => $pass,
});

foreach (qw[get_temperature get_target_temperature hubs devices]) {
say $hive->get_temperature;
say $hive->get_target_temperature;
say $hive->dump_temperature;
say $hive->dump_target_temperature;

foreach (qw[hubs devices]) {
say Dumper $hive->$_;
}
28 changes: 24 additions & 4 deletions lib/Hive.pm
Expand Up @@ -41,13 +41,14 @@ sub _build_ua {

LWP::UserAgent->new(
cookie_jar => HTTP::Cookies->new,
agent => 'bg-hive-api/1.0.5',
);
}

has base_url => (
is => 'ro',
isa => 'HiveURI',
default => 'https://api.hivehome.com/v5/',
default => 'https://api-prod.bgchprod.info/api',
coerce => 1,
);

Expand Down Expand Up @@ -105,16 +106,33 @@ sub BUILD {
$self->{devices} = $self->get_and_decode('/widgets/climate');
}

sub dump_temperature {
my $self = shift;

my $resp = $self->get('/widgets/temperature');
return $resp->content;
}

sub get_temperature {
my $self = shift;

return $self->get_and_decode('/widgets/temperature');
my $dat = $self->get_and_decode('/widgets/temperature');
return "Inside: $dat->{inside}{now}$dat->{temperatureUnit}\n" .
"Outside: $dat->{outside}{now}$dat->{temperatureUnit}";
}

sub dump_target_temperature {
my $self = shift;

my $resp = $self->get('/widgets/climate/targetTemperature');
return $resp->content;
}

sub get_target_temperature {
my $self = shift;

return $self->get_and_decode('/widgets/climate/targetTemperature');
my $dat = $self->get_and_decode('/widgets/climate/targetTemperature');
return $dat->{temperature} . $dat->{formatting}{temperatureUnit};
}

sub get {
Expand All @@ -123,7 +141,9 @@ sub get {
my $url = $self->user_url . shift;

my $req = GET $url;
$self->ua->request($req);
my $resp = $self->ua->request($req);
return $resp if $resp->is_success;
die $resp->status_line;
}

sub get_and_decode {
Expand Down

0 comments on commit 5e50679

Please sign in to comment.