Skip to content

Commit

Permalink
Add blueprint usage instructions to README
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Apr 8, 2021
1 parent b16181e commit 552be42
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
42 changes: 39 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,46 @@ File | Purpose

## How?

* …or create a new repository on the command line:
```bash
# Initialize your new origin repository
git init
git remote add origin https://github.com/YOUR_NEW_REPOSITORY

# Apply blueprint repository
git remote add blueprint https://github.com/Limych/ha-blueprint.git
git fetch blueprint dev
git reset --hard blueprint/dev
git branch -M dev

# Push changes to origin repository
git push -u origin main
```

* …or apply blueprint to an existing repository from the command line:
```bash
# Apply blueprint repository
git remote add blueprint https://github.com/Limych/ha-blueprint.git
git fetch blueprint dev
git merge blueprint/dev --allow-unrelated-histories
# Push changes to origin repository
git push -u origin main
```

After these steps, your repository will developing on a own branch. But in parallel there will be this blueprint repository, new changes in which you can always apply with a couple of simple commands:
```bash
./bin/update
git merge blueprint/dev
```

**Note:** Please, before starting to develop your own code, initialize the development environment with the command
```bash
./bin/setup
```

If you want to use all the potential and features of this blueprint template you
should use Visual Studio Code to develop in a container. In this container you
will have all the tools to ease your python development and a dedicated Home
Assistant core instance to run your integration. See `.devcontainer/README.md` for more information.
should use devcontainer. See [.devcontainer/README.md](./.devcontainer/README.md) for more information.

If you need to work on the python library in parallel of this integration
(`sampleclient` in this example) there are different options. The following one seems
Expand Down
2 changes: 1 addition & 1 deletion bin/update
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ROOT="$( cd "$( dirname "$(readlink -f "$0")" )/.." >/dev/null 2>&1 && pwd )"
cd "${ROOT}"

if git branch -r | grep -q "blueprint/" ; then
git fetch blueprint
git fetch blueprint dev
fi

git fetch
Expand Down
24 changes: 15 additions & 9 deletions custom_components/integration_blueprint/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""Adds config flow for Blueprint."""
from typing import Optional

import voluptuous as vol
from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
from homeassistant.helpers import ConfigType
from homeassistant.helpers.aiohttp_client import async_create_clientsession

from .api import IntegrationBlueprintApiClient
Expand All @@ -23,7 +27,7 @@ def __init__(self):
"""Initialize."""
self._errors = {}

async def async_step_user(self, user_input=None):
async def async_step_user(self, user_input: Optional[ConfigType] = None):
"""Handle a flow initialized by the user."""
self._errors = {}

Expand All @@ -46,11 +50,12 @@ async def async_step_user(self, user_input=None):

@staticmethod
@callback
def async_get_options_flow(config_entry):
def async_get_options_flow(config_entry: ConfigEntry):
"""Get component options flow."""
return BlueprintOptionsFlowHandler(config_entry)

async def _show_config_form(self, user_input): # pylint: disable=unused-argument
# pylint: disable=unused-argument
async def _show_config_form(self, user_input: Optional[ConfigType]):
"""Show the configuration form to edit location data."""
return self.async_show_form(
step_id="user",
Expand All @@ -60,31 +65,32 @@ async def _show_config_form(self, user_input): # pylint: disable=unused-argumen
errors=self._errors,
)

async def _test_credentials(self, username, password):
async def _test_credentials(self, username: str, password: str) -> bool:
"""Return true if credentials is valid."""
try:
session = async_create_clientsession(self.hass)
client = IntegrationBlueprintApiClient(username, password, session)
await client.async_get_data()
return True

except Exception: # pylint: disable=broad-except
pass
return False
return False


class BlueprintOptionsFlowHandler(config_entries.OptionsFlow):
"""Blueprint config flow options handler."""

def __init__(self, config_entry):
def __init__(self, config_entry: ConfigEntry):
"""Initialize HACS options flow."""
self.config_entry = config_entry
self.options = dict(config_entry.options)

async def async_step_init(self, user_input=None): # pylint: disable=unused-argument
# pylint: disable=unused-argument
async def async_step_init(self, user_input: Optional[ConfigType] = None):
"""Manage the options."""
return await self.async_step_user()

async def async_step_user(self, user_input=None):
async def async_step_user(self, user_input: Optional[ConfigType] = None):
"""Handle a flow initialized by the user."""
if user_input is not None:
self.options.update(user_input)
Expand Down

0 comments on commit 552be42

Please sign in to comment.