Open toolz0 opened 4 years ago
Hi Todd,
Thanks for opening this issue. I'm not working with Perl day to day right now, so I'm a little bit rusty, but looking at the code, I think the root of your issue is that getSystemInfo is a rather naive implementation that simply passes a get_sysinfo API call to the device and returns whatever the device sends back to the caller. There is a TODO comment indicating that I'd planned to come back and actually do something with the response, but I never came back around to it, probably because I realized that in my use case (hooking the TP-Link device to a voice assistant), I never actually needed to query the state of the relay.
If you'd like to work on a pull request, the relevant code is in https://github.com/verlin/Device-TPLink/blob/master/lib/Device/TPLink/SmartHome.pm
I'll leave your issue open for now, happy to discuss.
--Verlin
!/usr/bin/perl
use warnings; use Data::Dumper; use Device::TPLink::SmartHome::Direct; my $ip = '192.168.0.202'; print "IP=$ip\n"; my $foo = Device::TPLink::SmartHome::Direct->new({addr => "$ip", port => 9999}); $foo->on; sleep 2; $foo->off; print Dumper($foo->getSystemInfo),"\n\n"; print "Relay state: ",$foo->getSystemInfo->relay_state,"\n";
$foo->on turns on correctly
$foo->off turns off correctly
print Dumper shows: $VAR1 = { 'system' => { 'get_sysinfo' => { 'latitude_i' => 340713, 'hw_ver' => '2.1', 'status' => 'new', 'sw_ver' => '1.1.2 Build 191113 Rel.095623', 'led_off' => 0, 'rssi' => -40, 'alias' => 'Living room floor lamps', 'err_code' => 0, 'next_action' => { 'type' => -1 }, 'icon_hash' => '', 'hwId' => '18967AEED1C89BED1BBC7F62FD06468A', 'deviceId' => '8006B2DFDCB1890D4756EAECD0EA43811CC27008', 'active_mode' => 'none', 'oemId' => '24B27E003E98D053CF8B51CE8086FDA8', 'model' => 'HS103(US)', 'relay_state' => 0, 'updating' => 0, 'mac' => '1C:3B:F3:85:18:3E', 'longitude_i' => -845786, 'on_time' => 0, 'dev_name' => 'Smart Wi-Fi Plug Lite', 'feature' => 'TIM', 'mic_type' => 'IOT.SMARTPLUGSWITCH' } } };
print "Relay state: ",$foo->getSystemInfo->relay_state,"\n"; gives: Can't call method "relay_state" on unblessed reference at ./t.pl line 12.
Shouldn't it return '0'? I tried blessing the reference, but that did not help.