Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub Actions Workflow for validating HACS #1

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Test

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: Valid integration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Test HACS Action
uses: hacs/action@main
with:
category: integration
- name: Test Home Assistant hassfest
uses: home-assistant/actions/hassfest@master
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: pre-commit/[email protected]
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
__pycache__/

# local dev env

/config
/run.sh
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
default_install_hook_types:
- pre-commit
- commit-msg
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-docstring-first
- id: check-json
- id: pretty-format-json
exclude: .+/translations/.+.json$
args: [--autofix, --no-sort-keys]
- id: check-added-large-files
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- repo: https://github.com/myint/docformatter
rev: v1.5.1
hooks:
- id: docformatter
args: [--in-place]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0
hooks:
- id: reorder-python-imports
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-use-type-annotations
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.2
hooks:
- id: yamlfmt
args: [--mapping, '2', --sequence, '2', --offset, '0']
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cover Time-based Component

Forked from [@davidramosweb](https://github.com/davidramosweb/home-assistant-custom-components-cover-time-based) @ 2021,
Forked from [@davidramosweb](https://github.com/davidramosweb/home-assistant-custom-components-cover-time-based) @ 2021,
this custom component now integrates easily in Home Assistant.

Convert your (dummy) `switch` into a `cover`, and allow to control its position.
Expand Down
30 changes: 14 additions & 16 deletions custom_components/cover_time_based/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
"""Component to wrap switch entities in entities of other domains."""

from __future__ import annotations

import logging

import voluptuous as vol

from homeassistant.components.cover import DOMAIN as COVER_DOMAIN
from homeassistant.components.homeassistant import exposed_entities
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ENTITY_ID
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.core import callback
from homeassistant.core import Event
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.event import async_track_entity_registry_updated_event

from homeassistant.components.cover import (
DOMAIN as COVER_DOMAIN
)

from .const import CONF_INVERT, CONF_TARGET_DEVICE_CLASS, CONF_ENTITY_UP, CONF_ENTITY_DOWN
from .const import CONF_ENTITY_DOWN
from .const import CONF_ENTITY_UP
from .const import CONF_INVERT
from .const import CONF_TARGET_DEVICE_CLASS

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -97,9 +98,7 @@ async def async_registry_updated(

device_id = async_add_to_device(hass, entry, entity_id)

await hass.config_entries.async_forward_entry_setups(
entry, (COVER_DOMAIN,)
)
await hass.config_entries.async_forward_entry_setups(entry, (COVER_DOMAIN,))
return True


Expand All @@ -110,15 +109,14 @@ async def config_entry_update_listener(hass: HomeAssistant, entry: ConfigEntry)

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(
entry, (COVER_DOMAIN,)
)
return await hass.config_entries.async_unload_platforms(entry, (COVER_DOMAIN,))


async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Unload a config entry.

This will unhide the wrapped entity and restore assistant expose settings.
This will unhide the wrapped entity and restore assistant expose
settings.
"""
registry = er.async_get(hass)
try:
Expand Down
78 changes: 47 additions & 31 deletions custom_components/cover_time_based/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,60 @@
"""Config flow for Cover Time-based integration."""

from __future__ import annotations

from collections.abc import Mapping
from typing import Any

import voluptuous as vol

from homeassistant.const import CONF_ENTITY_ID, CONF_NAME, Platform
from homeassistant.components.cover import CoverDeviceClass
from homeassistant.helpers import entity_registry as er, selector
from homeassistant.const import CONF_ENTITY_ID
from homeassistant.const import CONF_NAME
from homeassistant.const import Platform
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import selector
from homeassistant.helpers.schema_config_entry_flow import SchemaConfigFlowHandler
from homeassistant.helpers.schema_config_entry_flow import SchemaFlowFormStep
from homeassistant.helpers.schema_config_entry_flow import (
SchemaConfigFlowHandler,
SchemaFlowFormStep,
wrapped_entity_config_entry_title,
)

from .const import CONF_ENTITY_UP, CONF_ENTITY_DOWN, CONF_INVERT, CONF_TARGET_DEVICE_CLASS, CONF_TIME_OPEN, CONF_TIME_CLOSE, DOMAIN
from .const import CONF_ENTITY_DOWN
from .const import CONF_ENTITY_UP
from .const import CONF_INVERT
from .const import CONF_TARGET_DEVICE_CLASS
from .const import CONF_TIME_CLOSE
from .const import CONF_TIME_OPEN
from .const import DOMAIN

CONFIG_FLOW = {
"user": SchemaFlowFormStep(
vol.Schema(
{
vol.Required(CONF_NAME): selector.TextSelector(),
vol.Required(CONF_ENTITY_UP): selector.EntitySelector(
selector.EntitySelectorConfig(domain=[Platform.SWITCH, Platform.LIGHT])
selector.EntitySelectorConfig(
domain=[Platform.SWITCH, Platform.LIGHT]
)
),
vol.Required(CONF_ENTITY_DOWN): selector.EntitySelector(
selector.EntitySelectorConfig(domain=[Platform.SWITCH, Platform.LIGHT])
selector.EntitySelectorConfig(
domain=[Platform.SWITCH, Platform.LIGHT]
)
),
vol.Required(CONF_TIME_OPEN, default=25): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX, min=2,
mode=selector.NumberSelectorMode.BOX,
min=2,
max=120,
step="any",
unit_of_measurement="sec"
unit_of_measurement="sec",
)
),
vol.Optional(CONF_TIME_CLOSE): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
max=120,
step="any",
unit_of_measurement="sec"
unit_of_measurement="sec",
)
),
}
Expand All @@ -52,24 +64,27 @@

OPTIONS_FLOW = {
"init": SchemaFlowFormStep(
vol.Schema({
vol.Required(CONF_TIME_OPEN): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX, min=2,
max=120,
step="any",
unit_of_measurement="sec"
)
),
vol.Optional(CONF_TIME_CLOSE): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
max=120,
step="any",
unit_of_measurement="sec"
)
),
})
vol.Schema(
{
vol.Required(CONF_TIME_OPEN): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=2,
max=120,
step="any",
unit_of_measurement="sec",
)
),
vol.Optional(CONF_TIME_CLOSE): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
max=120,
step="any",
unit_of_measurement="sec",
)
),
}
)
),
}

Expand All @@ -84,7 +99,8 @@ class CoverTimeBasedConfigFlowHandler(SchemaConfigFlowHandler, domain=DOMAIN):
MINOR_VERSION = 2

def async_config_entry_title(self, options: Mapping[str, Any]) -> str:
"""Return config entry title and hide the wrapped entity if registered."""
"""Return config entry title and hide the wrapped entity if
registered."""
# Hide the wrapped entry if registered
registry = er.async_get(self.hass)

Expand Down
1 change: 0 additions & 1 deletion custom_components/cover_time_based/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Constants for the Cover Time-based integration."""

from typing import Final

DOMAIN: Final = "cover_time_based"
Expand Down
Loading