Skip Menu |

This queue is for tickets about the Power-Outlet CPAN distribution.

Report information
The Basics
Id: 123965
Status: resolved
Worked: 2 hours (120 min)
Priority: 0/
Queue: Power-Outlet

People
Owner: MRDVT [...] cpan.org
Requestors: manee12 [...] student.sdu.dk
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.16
Fixed in: 0.17



Subject: Bug in Philips Hue
Date: Fri, 29 Dec 2017 21:24:27 +0100
To: <bug-Power-Outlet [...] rt.cpan.org>
From: Mathias Neerup <manee12 [...] student.sdu.dk>
Hi, I hope I'm reporting this bug to the right place. When I try to run the following snippet: #!/usr/bin/perl use Power::Outlet::Hue; my $lamp=Power::Outlet::Hue->new(host=>"Philips-hue.local", id=>2, username=>"userid"); print $lamp->off, "\n"; The script dies and says: Error: (on) "method, PUT, not available for resource, /2/state" at /usr/local/share/perl/5.22.1/Power/Outlet/Hue.pm line 195. I've attached a patch that solves the issue for me. Thanks :) \Mathias Neerup

Message body is not shown because sender requested not to inline it.

On Fri Dec 29 15:57:03 2017, manee12@student.sdu.dk wrote: Show quoted text
> my $lamp=Power::Outlet::Hue->new(host=>"Philips-hue.local", id=>2, > username=>"userid"); > > The script dies and says: > > Error: (on) "method, PUT, not available for resource, /2/state" at > /usr/local/share/perl/5.22.1/Power/Outlet/Hue.pm line 195. >
I personally do not own a Hue bridge all testing was done with the simulator but it looks like your bridge implements the "resource" concept from this documentation. https://developers.meethue.com/documentation/core-concepts I could add a resource method but I think setting the id to id=>"lights/1" should work as well. Let me know if it works and I can either update the documentation or add the resource method. Something like this. --- lib/Power/Outlet/Hue.pm (revision 10513) +++ lib/Power/Outlet/Hue.pm (working copy) @@ -54,6 +54,33 @@ sub _id_default {1}; +=head2 resource + +Resource for the particular object as presented on the Philips Hue Bridge + +Default: undef (not passed since this is the old API + +Current supported Resources from L<https://developers.meethue.com/documentation/core-concepts> + + lights - resource which contains all the light resources + groups - resource which contains all the groups + config - resource which contains all the configuration items + schedules - which contains all the schedules + scenes - which contains all the scenes + sensors - which contains all the sensors + rules - which contains all the rules + +=cut + +sub resource { + my $self=shift; + $self->{"resource"}=shift if @_; + $self->{"resource"}=$self->_resource_default unless defined $self->{"resource"}; + return $self->{"resource"}; +} + +sub _resource_default {undef}; + =head2 host Sets and returns the hostname or IP address. @@ -183,18 +210,19 @@ #url configuration my $url = $self->url; #isa URI from Power::Outlet::Common::IP::HTTP - $url->path(sprintf("/api/%s/%s/state", $self->username, $self->id)); + my $path = join('/', '', 'api', $self->username, (defined($self->resource) ? $self->resource : ()), $self->id, 'state'); + $url->path($path);
Subject: Re: [rt.cpan.org #123965] Bug in Philips Hue
Date: Sun, 31 Dec 2017 02:35:29 +0100
To: <bug-Power-Outlet [...] rt.cpan.org>
From: Mathias Neerup <manee12 [...] student.sdu.dk>
Den 30-12-2017 kl. 22:25 skrev Michael R. Davis via RT: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=123965 > > > On Fri Dec 29 15:57:03 2017, manee12@student.sdu.dk wrote:
>> my $lamp=Power::Outlet::Hue->new(host=>"Philips-hue.local", id=>2, >> username=>"userid"); >> >> The script dies and says: >> >> Error: (on) "method, PUT, not available for resource, /2/state" at >> /usr/local/share/perl/5.22.1/Power/Outlet/Hue.pm line 195. >>
> > I personally do not own a Hue bridge all testing was done with the simulator but it looks like your bridge implements the "resource" concept from this documentation. > > https://developers.meethue.com/documentation/core-concepts > > I could add a resource method but I think setting the id to id=>"lights/1" should work as well. >
It does, however it complains: Error: (off) Unkown success state at /usr/local/share/perl/5.22.1/Power/Outlet/Hue.pm line 200. my $key = sprintf("/lights/%s/state/on", $self->id); Which makes sense as 'lights' is already there when it tries to receive the new state of the lamp. Show quoted text
> Let me know if it works and I can either update the documentation or add the resource method. > > Something like this. > > --- lib/Power/Outlet/Hue.pm (revision 10513) > +++ lib/Power/Outlet/Hue.pm (working copy) > @@ -54,6 +54,33 @@ > > sub _id_default {1}; > > +=head2 resource > + > +Resource for the particular object as presented on the Philips Hue Bridge > + > +Default: undef (not passed since this is the old API > + > +Current supported Resources from L<https://developers.meethue.com/documentation/core-concepts> > + > + lights - resource which contains all the light resources > + groups - resource which contains all the groups > + config - resource which contains all the configuration items > + schedules - which contains all the schedules > + scenes - which contains all the scenes > + sensors - which contains all the sensors > + rules - which contains all the rules > + > +=cut > + > +sub resource { > + my $self=shift; > + $self->{"resource"}=shift if @_; > + $self->{"resource"}=$self->_resource_default unless defined $self->{"resource"}; > + return $self->{"resource"}; > +} > + > +sub _resource_default {undef}; > + > =head2 host > > Sets and returns the hostname or IP address. > @@ -183,18 +210,19 @@ > > #url configuration > my $url = $self->url; #isa URI from Power::Outlet::Common::IP::HTTP > - $url->path(sprintf("/api/%s/%s/state", $self->username, $self->id)); > + my $path = join('/', '', 'api', $self->username, (defined($self->resource) ? $self->resource : ()), $self->id, 'state'); > + $url->path($path); > >
I can't apply your patch. I've tried with git apply and patch but it seems like you forgot to change some numbers(18,19) in the second block. However; I've applied the changes manually, and they work:) I've edited the query() method so that it returns the state of the sensor when resource="sensors" is used :> If no resource is specified, it uses "lights" as default. I've attached a patch that works. \Mathias Neerup

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #123965] Bug in Philips Hue
Date: Sun, 31 Dec 2017 03:43:17 +0100
To: <bug-Power-Outlet [...] rt.cpan.org>
From: Mathias Neerup <manee12 [...] student.sdu.dk>
I've added a couple of lines so that it works with all resources. I've attached patch and my testscript. \Mathias

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

On Sat Dec 30 21:43:33 2017, manee12@student.sdu.dk wrote: Show quoted text
> I've added a couple of lines so that it works with all resources.
I refactored the code a bit and uploaded version 0.17 to CPAN. All tests passed with HueEmulator-v0.7.jar. Thanks! mrdvt92