Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined property: stdClass::$hue => sqmk/phue/library/Phue/Light.php->getHue() #125

Open
snaggor opened this issue Aug 2, 2017 · 0 comments

Comments

@snaggor
Copy link

snaggor commented Aug 2, 2017

There is an Error shown for (as I suspect) inactive devices.
Error message (edited):
ERROR: catched exception Notice: Undefined property: stdClass::$hue ["Message: Notice: Undefined property: stdClass::$hue\nStack Trace:
#0 vendor/sqmk/phue/library/Phue/Light.php(268): Symfony\Component\Debug\ErrorHandler->handleError(8, 'Undefined prope...', '/Users/xxx/...', 268, Array)\n
#1 src/SomeClass: Phue\Light->getHue()\n

Location:
sqmk/phue/library/Phue/Light.php(268)

 public function getHue()
    {
        return $this->attributes->state->hue;
    }

While debugging, the following properties are shown (correct scenario) :
$this = {Phue\Light} [3]
id = 1
attributes = {stdClass} [7]
state = {stdClass} [10]
on = false
bri = 143
hue = 0
sat = 0
effect = "none"
xy = {array} [2]
ct = 370
alert = "none"
colormode = "xy"
reachable = false
type = "someString"
name = "someString"
modelid = "someString"
manufacturername = "Philips"
uniqueid = "someId"
swversion = "someversion"
swconfigid = "someConfigId"
productid = "someProductId"
client = {Phue\Client} [3]

So hue = 0 is a proper object with a proper value.

Incorrect scenario (inactive hue device):
$this = {Phue\Light} [3]
id = 7
attributes = {stdClass} [9]
state = {stdClass} [6]
on = false
bri = 127
ct = 370
alert = "none"
colormode = "ct"
reachable = false
type = "someString"
name = "someString"
modelid = "someString"
manufacturername = "Philips"
uniqueid = "someId"
swversion = "someversion"
swconfigid = "someConfigId"
productid = "someProductId"
client = {Phue\Client} [3]

The object hue is missing here, I guess because of the inactive device, and the error message above is caused.

maybe you could edit this function a bit, so the returned value will be an int or null

 public function getHue()
    {
        $hue = $this->attributes->state->hue;
        return (isset($hue)) ? $hue : null;
    }

or maybe just return "0" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant