Coder Social home page Coder Social logo

custom-components / readme Goto Github PK

View Code? Open in Web Editor NEW
32.0 5.0 13.0 188 KB

Use Jinja and data from Home Assistant to generate your README.md file

License: MIT License

Python 88.80% Jinja 9.27% Shell 1.94%
jinja readme automation home-assistant

readme's Introduction

Readme

GitHub Release GitHub Activity License

hacs Project Maintenance BuyMeCoffee

Discord Community Forum

Use Jinja and data from Home Assistant to generate your README.md file with the list of all your installed add-ons and custom components

Installation

  1. Download it with HACS
  2. Restart Home Assistant
  3. Choose:
    • Add readme: to your HA configuration.
    • In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Generate readme"

Using your HA configuration directory (folder) as a starting point you should now also have this:

custom_components/readme/.translations/en.json
custom_components/readme/__init__.py
custom_components/readme/config_flow.py
custom_components/readme/const.py
custom_components/readme/default.j2
custom_components/readme/manifest.json
custom_components/readme/services.yaml

Example configuration.yaml

readme:

Warning!

This integration will replace your files!:

  • README.md
  • ui-lovelace.yaml (if you enable convert_lovelace)

Configuration options

Key Type Required Description
convert_lovelace boolean False Generate a ui-lovelace.yaml file (only usefull if you use the UI to edit lovelace and want to share that in a yaml format.)

Usage

In the root of your configuration directory (folder) you will get a new directory (folder) called "templates" in that directory (folder) there will be a file called "README.j2" this is where you change the template that will be used for generation of the README.md file.

When you are happy with how the template look, run the service readme.generate in Home Assistant, this will generate the README.md file, and the ui-lovelace.yaml file if you enabled that.

Usable variables

In addition to all Jinja magic you can do, there is also some additional variables you can use in the templates.

Variable Description
states This is the same as with the rest of Home Assistant.
custom_components Gives you a list of information about your custom_integrations
hacs_components Gives you a list of information about HACS installed integrations, plugins, and themes
addons List of installed Home Assistant Add-ons

custom_components

The information about custom integrations are fetched from the integrations manifest.json file, the folowing keys are available:

  • domain
  • name
  • documentation
  • codeowners
  • version

Example usage of the custom_components variable:

{%- set custom_component_descriptions = {"readme": "Generates this awesome readme file."} -%}
{% for integration in custom_components %}
### [{{integration.name}}]({{integration.documentation}})
{% if integration.domain in custom_component_descriptions %}
_{{custom_component_descriptions[integration.domain]}}_
{% endif -%}
{% endfor -%}

hacs_components

The information about integrations tracked with HACS are fetched from the storage hacs files, the folowing keys are available:

  • category
  • name
  • documentation
  • authors
  • description

Example usage of the hacs_components variable:

### Integrations
{%- for component in hacs_components | selectattr('category', 'equalto', 'integration') | sort(attribute='name') %}
- [{{component.name}}]({{component.documentation}})
{%- endfor %}

### Lovelace
{%- for component in hacs_components | selectattr('category', 'equalto', 'plugin') | sort(attribute='name') %}
- [{{component.name}}]({{component.documentation}})
{%- endfor %}

### Themes
{%- for component in hacs_components | selectattr('category', 'equalto', 'theme') | sort(attribute='name') %}
- [{{component.name}}]({{component.documentation}})
{%- endfor %}

Add-ons

The following keys are available:

  • name
  • slug
  • description
  • state
  • version
  • version_latest
  • update_available
  • repository

Example usage:

## Add-ons
{%- for addon in addons | sort(attribute='name') %}
- {{addon.name}} ({{addon.version}}) - {{addon.description}}
{%- endfor %}

Others

Example usage for documenting Alexa smart home utterances

{%- set alexa_configuration =
	{
		"domains": ["light", "camera", "vacuum", "fan"],
		"entities": {
			"included": ["climate.downstairs", "input_boolean.guest_mode", "input_boolean.assistant_notifications", "input_boolean.andrea_morning", "cover.garage_door"],
			"excluded": ["light.kitchen_light_1", "light.kitchen_light_2", "light.cabinet_split", "light.cabinet_large", "light.test_sensor_led", "camera.doorbell"]
		}
	}
-%}
{%- macro sentence_case(text) -%}
	{{ text[0]|upper}}{{text[1:] }}
{%- endmacro -%}
{% set data = namespace(domains=[]) %}
{%- for state in states %}
{%- if (state.entity_id in alexa_configuration.entities.included) or (state.entity_id not in alexa_configuration.entities.included and state.domain in alexa_configuration.domains) %}
{%- if state.domain not in data.domains %}
{%- set data.domains = data.domains + [state.domain] %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- for domain in data.domains %}
###  {{ sentence_case(domain) }}
{%- if domain == 'climate' %}
Control a thermostat temperature, run mode, etc...

Climate Mode | Accepted words
-- | --
AUTO | "auto", "automatic"
COOL | "cool", "cooling"
HEAT | "heat", "heating"
ECO | "eco", "economical"
OFF | "off"

**What you say:**

_"Alexa, set thermostat to 70."_
_"Alexa, set the AC to 70."_
_"Alexa, make it warmer in here."_
_"Alexa, make it cooler in here."_
_"Alexa, set `DEVICE NAME` to `CLIMATE MODE`."_
_"Alexa, turn on the `CLIMATE MODE`."_
_"Alexa, turn off the `DEVICE NAME`."_
{% endif %}
**Device Names:**
{%- for state in states[domain] %}
{%- if (state.entity_id in alexa_configuration.entities.included) or (state.entity_id not in alexa_configuration.entities.included and state.domain in alexa_configuration.domains) %}
{%- if state.entity_id not in alexa_configuration.entities.excluded %}
- {{state.name}}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endfor %}

Contributions are welcome!

If you want to contribute to this please read the Contribution guidelines


readme's People

Contributors

edenhaus avatar l-j avatar ludeeus avatar pinkywafer avatar steve-gombos avatar wrt54g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

readme's Issues

Failed to generate 'name' error

Failed to generate 'name' error. Default config, seems to generate ui-lovelace.yaml but breaks otherwise.

Version of the custom_component

0.2.1 (installed via HACS)

Home Assistant 0.113.2

Configuration

readme:
  - convert_lovelace: true

Using the default README.j2

Debug log

'name'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 125, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1281, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1316, in _execute_service
    await handler.func(service_call)
  File "/config/custom_components/readme/__init__.py", line 168, in service_generate
    hacs_components = get_hacs_components(hass)
  File "/config/custom_components/readme/__init__.py", line 208, in get_hacs_components
    "name": get_repository_name(repository),
  File "/config/custom_components/readme/__init__.py", line 221, in get_repository_name
    name = repository["repository_manifest"]["name"]
KeyError: 'name'

Version Bump?

Version of the custom_component

0.2.1

Configuration

N/A

Describe the bug

Looks like the latest version of HACS was pushed with the data refactor, I assume a new release for this should be published.

Debug log


N/A

KeyError: 'name'

Version of the custom_component

VERSION = "0.2.1"

Configuration

readme:

Describe the bug

Key error with hacs.repositories file.

Debug log

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1295, in _execute_service
    await handler.func(service_call)
  File "/config/custom_components/readme/__init__.py", line 168, in service_generate
    hacs_components = get_hacs_components(hass)
  File "/config/custom_components/readme/__init__.py", line 208, in get_hacs_components
    "name": get_repository_name(repository),
  File "/config/custom_components/readme/__init__.py", line 221, in get_repository_name
    name = repository["repository_manifest"]["name"]
KeyError: 'name'

Hasn't worked since 0.105.0b4

Version of the custom_component

0.1.1

Configuration

I tried replacing my entire /templates/README.j2 with the following line and got the same error.

# Test

Describe the bug

This was working great within the last week or so. I can tell you that I was running Home Assistant 0.105.0b4 the last time this worked (see the version stamped at the top of my README.md.)

Executing readme.generate from the Developer Tools > Services page gives a Failed to call service readme/generate. 'documentation' error.

Let me know if I can provide more info.

Debug log


2020-02-07 20:41:41 INFO (MainThread) [homeassistant.helpers.script] Script ci_prep: Executing step call service
2020-02-07 20:41:41 ERROR (MainThread) [homeassistant.components.script] Error executing script script.ci_prep. Unknown error for call_service at pos 2:
  Traceback (most recent call last):   File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 272, in async_turn_on     await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 247, in async_run
     await self._handle_action(action, variables, context)
   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 331, in _handle_action
     await self._actions[_determine_action(action)](action, variables, context)
   File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 413, in _async_call_service
     context=context,
   File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 96, in async_call_from_config
     domain, service_name, service_data, blocking=blocking, context=context
   File "/usr/src/homeassistant/homeassistant/core.py", line 1226, in async_call
     await asyncio.shield(self._execute_service(handler, service_call))
   File "/usr/src/homeassistant/homeassistant/core.py", line 1251, in _execute_service
     await handler.func(service_call)
   File "/config/custom_components/readme/__init__.py", line 167, in service_generate
     custom_components = get_custom_components(hass)
   File "/config/custom_components/readme/__init__.py", line 200, in get_custom_components
     "documentation": content["documentation"], KeyError: 'documentation'

Allow to load / supply variables from yaml

Is your feature request related to a problem? Please describe.
I use variables declared in yaml for lovelace_gen to generate my dashboards.
I would like to access this data in the templates.

Describe the solution you'd like
Either supply the global variables the same way as lovelace_gen does:
something like

generate_readme:
  my_vars: !include my_vars.yaml   # normal home-assistant yaml include 

Describe alternatives you've considered
tried to load variables directly from jinja, but I think you can only import macros that way.

Additional context
Actual reason for this is because I want to extend the functionality of this component to parse any .j2 files (or whitelisted) in the config, and want to use the same variables I use for lovelace, this would result in fully templated home assistant readme, config and dashboards.

Warning about depreciated .translations folder

Version of the custom_component

0.1.1

Configuration

readme:

Describe the bug

from Home Assistant 0.109.0 .translations directory was depreciated

Debug log


readme: the '.translations' directory has been moved, the new name is 'translations', starting with Home Assistant 0.111 your translations will no longer load if you do not move/rename this


How can I extract my automations? I want to print them

Is your feature request related to a problem? Please describe.
I need to create a readme for all of my automations (from automations.yaml)

Describe the solution you'd like
I need to create a readme for all of my automations (from automations.yaml)

Describe alternatives you've considered
I don't have any idea

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.