Giter Club home page Giter Club logo

Comments (13)

erkr avatar erkr commented on June 25, 2024 1

@bdraco
I created my first architecture discussion. Hope I did it in the right way.
In the mean time, I managed to get the one method working in pyscript (cool):

@service(supports_response="only")
def entity_integration(entity_id: str):
    """Get the integration of an entity."""
    # fallback to just returning all entities for a domain
    from homeassistant.helpers.entity import entity_sources
    sources = entity_sources(hass)
    if entity_id in sources:
        return {"success":True, "result":sources[entity_id]["domain"]}
    return {"success":False, "result": None}

from core.

home-assistant avatar home-assistant commented on June 25, 2024

Hey there @OttoWinter, @jesserockz, @kbx81, @bdraco, mind taking a look at this issue as it has been labeled with an integration (esphome) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of esphome can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign esphome Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


esphome documentation
esphome source
(message by IssueLinks)

from core.

bdraco avatar bdraco commented on June 25, 2024

This is expected. A device required connections OR identifiers, but may use both. ESPHome only uses connections as there is no internal need for identifiers as the mac is always known in all places:

connections={(dr.CONNECTION_NETWORK_MAC, device_info.mac_address)}

"device info must include at least one of identifiers or connections",

from core.

erkr avatar erkr commented on June 25, 2024

@bdraco Thanks for educating πŸ‘
Bad luck for me, I use identifiers to lookup the integration that owns the device

from core.

bdraco avatar bdraco commented on June 25, 2024

While I don't know your specific use case, device_attr should be able to lookup connections as well

def device_attr(hass: HomeAssistant, device_or_entity_id: str, attr_name: str) -> Any:

This is how devices are usually looked up

def async_get_device(

from core.

erkr avatar erkr commented on June 25, 2024

Hi @bdraco

Just to explain, not a feature request.
My use case is to programmatically lookup the integration that owns an entity. I searched and googled, but this seems not supported.

Currently my approach is far from solid (I Know):

  • It only works for entities that are part of a device and support the attribute 'identifiers'.
  • it fails when devices own entities from multiple integrations

My template code to lookup the owning integration.

  {%- set ids = device_attr(entity_id, 'identifiers') -%}
  {%- set integration = 'unknown' if (not ids or ids|list|length == 0 or ids|list|first|length!=2) else ids|list|first|first -%}

This works for the majority, but fat from all entities.

The connections device attribute can indeed be queried, but the Mac doesn't help me to distill the integration:

{('mac', 'cc:8d:a2:50:90:e8')}

Bottom line two template methods are missing:

  • get_integrations() -> list
  • entity_integration(entity_id) -> string

Best Eric

from core.

bdraco avatar bdraco commented on June 25, 2024

Bottom line two template methods are missing:

  • get_integrations() -> list
  • entity_integration(entity_id) -> string

entity_sources(self.hass)[self.entity_id] = entity_info

Your template code trying to effectively reimplement a limited version entity_sources because its not exposed to the template engine.

from core.

bdraco avatar bdraco commented on June 25, 2024

These can both be likely implemented with a few lines of code to wrap the existing functions as the backends already exist.

If you plan on adding these new functions to the template engine I'd start with an architecture discussion https://github.com/home-assistant/architecture/discussions

from core.

erkr avatar erkr commented on June 25, 2024

I'm not really experienced in python and github delivery processes, but I can give it a try. Thanks for the information.

from core.

bdraco avatar bdraco commented on June 25, 2024

This commit is a rough implementation (without tests) 3270cad

I only did light testing with it
Screenshot 2024-05-26 at 10 19 50β€―AM
Screenshot 2024-05-26 at 10 20 02β€―AM

from core.

erkr avatar erkr commented on June 25, 2024

That looks really great and so simple it would be pity when we don't add it ☺️
If I start and drive the discussion, would you be willing to deliver this when the discussing ends positive?

from core.

bdraco avatar bdraco commented on June 25, 2024

I'm happy to write the code if the architecture discussion results in acceptance. Its not something I would use so it needs architecture champion who is willing to advocate for it.

from core.

erkr avatar erkr commented on June 25, 2024

Great thanks for your support πŸ‘ I will be the image ☺️
My first architectural discussion, looking forward how that evolves. will initiate it tomorrow

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.