Skip to content

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

@snaggor

Description

@snaggor

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" ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions