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);