Skip to content

Commit

Permalink
Get infor about hubs and devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Jun 5, 2015
1 parent 97a3246 commit 792c7a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gettemp
Expand Up @@ -15,6 +15,6 @@ my $hive = Hive->new({
password => $pass,
});

foreach (qw[get_temperature get_target_temperature]) {
foreach (qw[get_temperature get_target_temperature hubs devices]) {
say Dumper $hive->$_;
}
}
22 changes: 21 additions & 1 deletion lib/Hive.pm
Expand Up @@ -75,14 +75,34 @@ sub _build_json {
return JSON->new->utf8;
}

has hubs => (
is => 'ro',
isa => 'ArrayRef[HashRef]',
traits => ['Array'],
handles => {
all_hubs => 'elements',
},
);

has devices => (
is => 'ro',
);

sub BUILD {
my $self = shift;

$self->post('/login', {
username => $self->username,
password => $self->password,
})
});

$self->{hubs} = $self->get_and_decode('/hubs');

foreach ($self->all_hubs) {
$_->{data} = $self->get_and_decode("/hubs/$_->{id}");
}

$self->{devices} = $self->get_and_decode('/widgets/climate');
}

sub get_temperature {
Expand Down

0 comments on commit 792c7a5

Please sign in to comment.