Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Add support for unique_id#55

Closed
mxr wants to merge 1 commit intodaenny:masterfrom
mxr:unique-id
Closed

Add support for unique_id#55
mxr wants to merge 1 commit intodaenny:masterfrom
mxr:unique-id

Conversation

@mxr
Copy link
Copy Markdown

@mxr mxr commented Aug 16, 2022

(need to figure out how to test this)

Resolves #52

@HarvsG
Copy link
Copy Markdown

HarvsG commented Oct 8, 2022

(need to figure out how to test this)

    config = {
        "binary_sensor": {
            "name": "Test_Binary",
            "platform": "bayesian",
            "unique_id": "3b4c9563-5e84-4167-8fe7-8f507e796d72",
            "device_class": "connectivity",
            "observations": [
                {
                    "platform": "state",
                    "entity_id": "sensor.test_monitored",
                    "to_state": "off",
                    "prob_given_true": 0.8,
                    "prob_given_false": 0.4,
                }
            ],
            "prior": 0.2,
            "probability_threshold": 0.32,
        }
    }

    hass.states.async_set("sensor.test_monitored", "off")
    await hass.async_block_till_done()

    assert await async_setup_component(hass, "binary_sensor", config)
    await hass.async_block_till_done()

    entity_registry = async_get_entities(hass)
    assert (
        entity_registry.entities["binary_sensor.test_binary"].unique_id
        == "bayesian-3b4c9563-5e84-4167-8fe7-8f507e796d72"
    )

This is how I test unqiue-ids. Baiscally just create an instance of your entity and then look for it's unique_id in the entity registry.

) -> None:
"""Initialize a climate group."""
self._name = name # type: str
self._unique_id = unique_id
Copy link
Copy Markdown

@HarvsG HarvsG Oct 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._attr_unique_id = unique_id and f"climate-group-{unique_id}"

self._attr_unique_id is what home assistant looks for when getting unique IDs
https://developers.home-assistant.io/docs/core/entity/

@mxr
Copy link
Copy Markdown
Author

mxr commented Oct 31, 2022

Thanks for the review @HarvsG I am expecting home-assistant/core#77737 to ship so I am closing this PR for now.

@mxr mxr closed this Oct 31, 2022
@mxr mxr deleted the unique-id branch October 31, 2022 12:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unique ID for climate_group

2 participants