Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

FR: add unique hub-id/bridgeid to sensor for multi-hub setup #227

Open
Mariusthvdb opened this issue Mar 10, 2020 · 0 comments
Open

FR: add unique hub-id/bridgeid to sensor for multi-hub setup #227

Mariusthvdb opened this issue Mar 10, 2020 · 0 comments

Comments

@Mariusthvdb
Copy link
Contributor

HI, as explained here: #222

I seek assistance adding a unique hub-id/bridgeid to a PHD sensor (which isn't yet in the intregration, but running fully functionally in my local setup)

def parse_phd(response):
    """Parse the json for a PHD Daylight sensor and return the data."""
    if response["type"] == "Daylight":
        daylight = response["state"]["daylight"]
        name_raw = response["name"]
        name = "Hue " + name_raw + " custom"

        if daylight is True:
            state = STATE_ON
        else:
            state = STATE_OFF
        if daylight is not None:
            data = {
                "model": "PHD",
                "state": state,
                "on": response["config"]["on"],
                "configured": response["config"]["configured"],
                "sunrise_offset": response["config"]["sunriseoffset"],
                "sunset_offset": response["config"]["sunsetoffset"],
                "name": name,
                "type": response["type"],
                "modelid": response["modelid"],
                "swversion": response["swversion"],
                "daylight": daylight,
                "last_updated": response["state"]["lastupdated"].split("T"),
                "manufacturername": response["manufacturername"]
            }
        else:
            data = {
                "model": "PHD",
                "state": "No Daylight data",
                "on": None,
                "configured": None,
                "sunrise_offset": None,
                "sunset_offset": None,
                "name": None,
                "type": None,
                "modelid": None,
                "swversion": None,
                "daylight": "No Daylight data",
                "last_updated": None,
                "manufacturername": None
            }

    return data

is what the sensor currently is made of, with a suffix custom in the name.
Ideally the entity_id should get a unique humid too, so in multiple hub setups, these entities can be distinguished from each other. This is a Hub builtin sensor called Daylight.

please consider adding this to the integration, and please help me adding the unique hubid previously done like this:

        if modelid == "PHD":
            _key = modelid + "_" + bridgeid
            if _key not in data_dict:
                data_dict[_key] = parse_phd(sensor)
            else:
                data_dict[_key].update(parse_phd(sensor))

and now added to the hue_api(repsonse) as follows:

        elif modelid == "PHD":
            _key = modelid
            if _key not in data_dict:
                data_dict[_key] = parse_phd(sensor)
            else:
                data_dict[_key].update(parse_phd(sensor))

thanks for having a look and considering!

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

No branches or pull requests

1 participant