{"id":3954,"date":"2024-02-06T16:29:01","date_gmt":"2024-02-06T14:29:01","guid":{"rendered":"https:\/\/mummila.net\/nuudelisoppa\/?p=3954"},"modified":"2024-02-06T16:29:01","modified_gmt":"2024-02-06T14:29:01","slug":"notes-as-i-go-my-attempt-to-develop-a-home-assistant-integration-part-3","status":"publish","type":"post","link":"https:\/\/mummila.net\/nuudelisoppa\/2024\/02\/06\/notes-as-i-go-my-attempt-to-develop-a-home-assistant-integration-part-3\/","title":{"rendered":"Notes as I go: my attempt to develop a Home Assistant integration, part 3"},"content":{"rendered":"<p>One thing that was confusing to me from the start was the seemingly overlapping functionality in <code>__init__.py<\/code> and <code>config_flow.py<\/code>, but I think I figured it out: <code>async_step_*()<\/code> in <code>config_flow.py<\/code> is for when a component is first set up, whereas <code>async_setup_entry()<\/code> in <code>__init__.py<\/code> is for when a config entry for the component <em>has already previously been set up<\/em>, and so an object can be instantiated for that entry.<\/p>\n<p>As for &#8220;my API&#8221;, my impression (from both core and non-core integrations) is that if I had a published Python package for the device, I&#8217;d just import it (like, for instance, <a href=\"https:\/\/www.home-assistant.io\/integrations\/ruuvitag_ble\/\">RuuviTag integration<\/a> imports <a href=\"https:\/\/pypi.org\/project\/ruuvitag-ble\/\">ruuvitag-ble<\/a>), but if\/as I don&#8217;t, I should create the API in a subdirectory of my integration and <a href=\"https:\/\/realpython.com\/absolute-vs-relative-python-imports\/#relative-imports\">import it using dot notation<\/a>.<\/p>\n<p>Hence, naming the files inside the API directory is more a question of general <a href=\"https:\/\/peps.python.org\/pep-0008\/#package-and-module-names\">Python convention<\/a>, rather than something HA has opinions about.<\/p>\n<hr>\n<p>Anyway, while I understand all the complications I keep stumbling over make HA component development scalable, it also makes my tiny button project way more complicated than it should be. There appears to be no way to build a minuscule MVP with just a few lines of code, to be then extended with all the bells and whistles that would make it look and play nice.<\/p>\n<p>Instead it seems easier to just hack some existing code to work with my device (which I&#8217;ve already done, semi-successfully). But that means then having to clean up tons of someone else&#8217;s code, or, what&#8217;s more likely, just leave it all as an ugly hack, never to be published anywhere.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One thing that was confusing to me from the start was the seemingly overlapping functionality in __init__.py and config_flow.py, but I think I figured it out: async_step_*() in config_flow.py is for when a component is first set up, whereas async_setup_entry() in __init__.py is for when a config entry for the component has already previously been [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3954","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/3954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/comments?post=3954"}],"version-history":[{"count":16,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/3954\/revisions"}],"predecessor-version":[{"id":3975,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/posts\/3954\/revisions\/3975"}],"wp:attachment":[{"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/media?parent=3954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/categories?post=3954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mummila.net\/nuudelisoppa\/wp-json\/wp\/v2\/tags?post=3954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}