Skip to content

Commit

Permalink
Fix remaining blueprint occurence (#53)
Browse files Browse the repository at this point in the history
* Add missing import for slugify helper

* Add VSC setting in .gitignore

* Add a cookiecutter setting for class name prefix

By default propose CapWords of domain name.

* Remove all remaining blueprint occurences

In docstrings, in documentation and in Class names.

* Update documentation by adding class_name_prefix
  • Loading branch information
oncleben31 authored Nov 12, 2020
1 parent b6cd8ad commit 9e8becc
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/docs/_build/
__pycache__/
/.python-version
/.vscode/
17 changes: 9 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ Generate a Home Assistant custom component project by using the following comman
Follow the instructions to customize the generated project

================= ============================================
===================== ============================================
Setting Definition
================= ============================================
``friendly_name`` Integration name used in configuration UI.
``project_name`` Project name on GitHub.
``domain_name`` Integration domain name
``github_user`` GitHub user hosting the repository
``version`` Initial version of the component
================= ============================================
===================== ============================================
``friendly_name`` Integration name used in configuration UI.
``project_name`` Project name on GitHub.
``domain_name`` Integration domain name
``class_name_prefix`` Prefix to be use in classes name
``github_user`` GitHub user hosting the repository
``version`` Initial version of the component
===================== ============================================

Change to the root directory of your new project,
and create a Git repository:
Expand Down
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"friendly_name": "Awesome custom component",
"project_name": "{{ cookiecutter.friendly_name | slugify }}",
"domain_name": "{{ cookiecutter.friendly_name | slugify(separator='_') }}",
"class_name_prefix": "{{ cookiecutter.domain_name | replace('_', ' ') | title | replace(' ', '') }}",
"github_user": "oncleben31",
"version": "0.0.0",
"_copy_without_render": [
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ README content if this was a published component:
Platform | Description
-- | --
`binary_sensor` | Show something `True` or `False`.
`sensor` | Show info from blueprint API.
`sensor` | Show info from {{ cookiecutter.friendly_name }} API.
`switch` | Switch something `True` or `False`.

![example][exampleimg]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Custom integration to integrate blueprint with Home Assistant.
Custom integration to integrate {{cookiecutter.friendly_name}} with Home Assistant.
For more details about this integration, please refer to
https://github.com/custom-components/blueprint
https://github.com/{{cookiecutter.github_user}}/{{cookiecutter.project_name}}
"""
import asyncio
from datetime import timedelta
Expand Down Expand Up @@ -41,7 +41,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
username = entry.data.get(CONF_USERNAME)
password = entry.data.get(CONF_PASSWORD)

coordinator = BlueprintDataUpdateCoordinator(
coordinator = {{cookiecutter.class_name_prefix}}DataUpdateCoordinator(
hass, username=username, password=password
)
await coordinator.async_refresh()
Expand All @@ -62,7 +62,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
return True


class BlueprintDataUpdateCoordinator(DataUpdateCoordinator):
class {{cookiecutter.class_name_prefix}}DataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching data from the API."""

def __init__(self, hass, username, password):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Binary sensor platform for blueprint."""
"""Binary sensor platform for {{cookiecutter.friendly_name}}."""
from homeassistant.components.binary_sensor import BinarySensorDevice

from .const import (
Expand All @@ -7,17 +7,17 @@
DEFAULT_NAME,
DOMAIN,
)
from .entity import BlueprintEntity
from .entity import {{cookiecutter.class_name_prefix}}Entity


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup binary_sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([BlueprintBinarySensor(coordinator, entry)])
async_add_devices([{{cookiecutter.class_name_prefix}}BinarySensor(coordinator, entry)])


class BlueprintBinarySensor(BlueprintEntity, BinarySensorDevice):
"""blueprint binary_sensor class."""
class {{cookiecutter.class_name_prefix}}BinarySensor({{cookiecutter.class_name_prefix}}Entity, BinarySensorDevice):
"""{{cookiecutter.domain_name}} binary_sensor class."""

@property
def name(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Adds config flow for Blueprint."""
"""Adds config flow for {{cookiecutter.friendly_name}}."""
from homeassistant import config_entries
from homeassistant.core import callback
from sampleclient.client import Client
Expand All @@ -12,8 +12,8 @@
)


class BlueprintFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Config flow for Blueprint."""
class {{cookiecutter.class_name_prefix}}FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Config flow for {{cookiecutter.domain_name}}."""

VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
Expand Down Expand Up @@ -50,7 +50,7 @@ async def async_step_user(
@staticmethod
@callback
def async_get_options_flow(config_entry):
return BlueprintOptionsFlowHandler(config_entry)
return {{cookiecutter.class_name_prefix}}OptionsFlowHandler(config_entry)

async def _show_config_form(self, user_input): # pylint: disable=unused-argument
"""Show the configuration form to edit location data."""
Expand All @@ -73,8 +73,8 @@ async def _test_credentials(self, username, password):
return False


class BlueprintOptionsFlowHandler(config_entries.OptionsFlow):
"""Blueprint config flow options handler."""
class {{cookiecutter.class_name_prefix}}OptionsFlowHandler(config_entries.OptionsFlow):
"""{{cookiecutter.domain_name}} config flow options handler."""

def __init__(self, config_entry):
"""Initialize HACS options flow."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Constants for blueprint."""
"""Constants for {{cookiecutter.friendly_name}}."""
# Base component constants
NAME = "{{ cookiecutter.friendly_name }}"
DOMAIN = "{{ cookiecutter.domain_name }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""BlueprintEntity class"""
"""{{cookiecutter.class_name_prefix}}Entity class"""
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DOMAIN, NAME, VERSION


class BlueprintEntity(CoordinatorEntity):
class {{cookiecutter.class_name_prefix}}Entity(CoordinatorEntity):
def __init__(self, coordinator, config_entry):
super().__init__(coordinator)
self.config_entry = config_entry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"""Sensor platform for blueprint."""
"""Sensor platform for {{cookiecutter.friendly_name}}."""
from .const import DEFAULT_NAME, DOMAIN, ICON, SENSOR
from .entity import BlueprintEntity
from .entity import {{cookiecutter.class_name_prefix}}Entity

from homeassistant.util import slugify

from homeassistant.util import slugify


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([BlueprintSensor(coordinator, entry)])
async_add_devices([{{cookiecutter.class_name_prefix}}Sensor(coordinator, entry)])


class BlueprintSensor(BlueprintEntity):
"""blueprint Sensor class."""
class {{cookiecutter.class_name_prefix}}Sensor({{cookiecutter.class_name_prefix}}Entity):
"""{{cookiecutter.domain_name}} Sensor class."""

@property
def name(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""Switch platform for blueprint."""
"""Switch platform for {{cookiecutter.friendly_name}}."""
from homeassistant.components.switch import SwitchDevice

from .const import DEFAULT_NAME, DOMAIN, ICON, SWITCH
from .entity import BlueprintEntity
from .entity import {{cookiecutter.class_name_prefix}}Entity


async def async_setup_entry(hass, entry, async_add_devices):
"""Setup sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([BlueprintBinarySwitch(coordinator, entry)])
async_add_devices([{{cookiecutter.class_name_prefix}}BinarySwitch(coordinator, entry)])


class BlueprintBinarySwitch(BlueprintEntity, SwitchDevice):
"""blueprint switch class."""
class {{cookiecutter.class_name_prefix}}BinarySwitch({{cookiecutter.class_name_prefix}}Entity, SwitchDevice):
"""{{cookiecutter.domain_name}} switch class."""

async def async_turn_on(self, **kwargs): # pylint: disable=unused-argument
"""Turn on the switch."""
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_name}}/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Platform | Description
-- | --
`binary_sensor` | Show something `True` or `False`.
`sensor` | Show info from blueprint API.
`sensor` | Show info from {{ cookiecutter.friendly_name }} API.
`switch` | Switch something `True` or `False`.

![example][exampleimg]
Expand All @@ -23,7 +23,7 @@ Platform | Description
## Installation

1. Click install.
1. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Blueprint".
1. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "{{ cookiecutter.friendly_name }}".

{{ "{% endif %}" }}

Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ not_skip = __init__.py
force_sort_within_sections = true
sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section = THIRDPARTY
known_first_party = custom_components.blueprint
known_first_party = custom_components.{{ cookiecutter.domain_name }}
combine_as_imports = true

0 comments on commit 9e8becc

Please sign in to comment.