Where are the information stored?

Hello folks,
I’m on my way to write a component for Asus GPIO (you might see my several discussion), then I need to retrieve the pin assignment information in order to be able to prepare their states during HA boot.

So I thought that there’s a dictionary or json equivalent where the configuration.yaml is converted, please give some code to get the idea…

I can manage for my own setting, but I’d rather want to share my efforts to other tinker board owners.

#EDIT
I’m trying

$ python -q
>>> from homeassistant.core import HomeAssistant
>>> hass = HomeAssistant()
>>> from pprint import pprint as pp
>>> pp(hass.states.entity_ids('switch'))
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/homeassistant/core.py", line 803, in entity_ids
    return future.result()  # type: ignore
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 427, in result
    self._condition.wait(timeout)
  File "/usr/lib/python3.7/threading.py", line 296, in wait
    waiter.acquire()
KeyboardInterrupt
>>>

With such way I had to interrupt because it’s not responding any longer to the shell.

I can’t help you with that code snippet, because I don’t think that is how HA works.

However, are you aware that there is a whole website dedicated to developing extension for HA? It has detailed information and step-by-step examples on how to create a new integration:

So you want to get the settings in configuration.yaml into your python integration?

There is an example in the following code, which I know you have read as I know you are using the raspberry pi code as an example. See https://github.com/home-assistant/home-assistant/blob/e225243bc541b0b20f3d153a40c34b7b1ef01262/homeassistant/components/rpi_gpio/binary_sensor.py

Take a look at lines 35 to 46

def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Raspberry PI GPIO devices."""
    pull_mode = config.get(CONF_PULL_MODE)
    bouncetime = config.get(CONF_BOUNCETIME)
    invert_logic = config.get(CONF_INVERT_LOGIC)

    binary_sensors = []
    ports = config.get('ports')
    for port_num, port_name in ports.items():
        binary_sensors.append(RPiGPIOBinarySensor(
            port_name, port_num, pull_mode, bouncetime, invert_logic))
    add_entities(binary_sensors, True)

In particular config.get()

I read a part of it. Digging deeper I could identify the most part of interest. So I’ll keep reading through the following chapters/link.

@nickrout
Thank you (both) very much for your guidance. Perhaps I’m more used to learn by examples. Then I’d take some part of them to rearrange on my way.

Deeper analysis

Perhaps, like nickrout guessed, I’ll find the object hass inside the component I’m trying to get working (imitating the rpi_gpio). But for little step testing I’d rather try to call the python shell and move my course tests from within that. So how I import hass ?
I tried as above shown, but it is not responding.

Definitely I’m not a programmer, I’m just trying my way to solve some problem, which might lead to something inelegant.

1 Like