Skip to content

Commit

Permalink
beta: Update tests (#418)
Browse files Browse the repository at this point in the history
* Remove unused config fields

* Remove unused yaml

* Update ConfigEntry to Version 3

* Remove unused functions

* Update Z-Wave JS Client

* Combine all config into pyproject.toml

* Update conftest.py

* Limit test files for now

* Change to ruff

* Linting cleanup

* Update pytest.yaml

* Update test_config_flow.py

* init and config_flow changes to pass pytest
  • Loading branch information
Snuffy2 authored Dec 9, 2024
1 parent 8e66d4f commit 431cfdb
Show file tree
Hide file tree
Showing 23 changed files with 859 additions and 2,218 deletions.
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
strategy:
matrix:
python-version:
- "3.12"
- "3.13"

steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v4
- name: 🛠️ Set up Python
uses: actions/setup-python@v5
with:
fetch-depth: 2
fetch-depth: 2
- name: 🛠️ Set up Python
uses: actions/setup-python@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/keymaster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
)
)

if unload_ok:
if unload_ok and DOMAIN in hass.data and COORDINATOR in hass.data[DOMAIN]:
coordinator: KeymasterCoordinator = hass.data[DOMAIN][COORDINATOR]
await coordinator.delete_lock_by_config_entry_id(config_entry.entry_id)

Expand Down
48 changes: 34 additions & 14 deletions custom_components/keymaster/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,15 @@ async def async_step_init(

def _available_parent_locks(hass: HomeAssistant, entry_id: str = None) -> list:
"""Find other keymaster configurations and list them as posible
parent locks if they are not a child lock already"""
parent locks if they are not a child lock already
"""

data: list[str] = ["(none)"]
if DOMAIN not in hass.data:
return data

for entry in hass.config_entries.async_entries(DOMAIN):
if CONF_PARENT not in entry.data and entry.entry_id != entry_id:
data.append(entry.title)
elif entry.data[CONF_PARENT] is None and entry.entry_id != entry_id:
if CONF_PARENT not in entry.data and entry.entry_id != entry_id or entry.data[CONF_PARENT] is None and entry.entry_id != entry_id:
data.append(entry.title)

return data
Expand Down Expand Up @@ -207,7 +206,8 @@ def _get_default(key: str, fallback_default: Any = None) -> Any:
script_default: str | None = _get_default(CONF_NOTIFY_SCRIPT_NAME)
if isinstance(script_default, str) and not script_default.startswith("script."):
script_default = f"script.{script_default}"
return vol.Schema(
_LOGGER.debug("[get_schema] script_default: %s (%s)", script_default, type(script_default))
schema = vol.Schema(
{
vol.Required(CONF_LOCK_NAME, default=_get_default(CONF_LOCK_NAME)): str,
vol.Required(
Expand Down Expand Up @@ -267,15 +267,32 @@ def _get_default(key: str, fallback_default: Any = None) -> Any:
extra_entities=[DEFAULT_ALARM_TYPE_SENSOR],
)
),
vol.Optional(
CONF_NOTIFY_SCRIPT_NAME,
default=script_default,
): vol.In(
_get_entities(
hass=hass,
domain=SCRIPT_DOMAIN,
)
),
}
)
if script_default:
schema = schema.extend({
vol.Optional(
CONF_NOTIFY_SCRIPT_NAME,
default=script_default,
): vol.In(
_get_entities(
hass=hass,
domain=SCRIPT_DOMAIN,
)
),
})
else:
schema = schema.extend({
vol.Optional(
CONF_NOTIFY_SCRIPT_NAME
): vol.In(
_get_entities(
hass=hass,
domain=SCRIPT_DOMAIN,
)
),
})
return schema.extend({
vol.Required(
CONF_HIDE_PINS, default=_get_default(CONF_HIDE_PINS, DEFAULT_HIDE_PINS)
): bool,
Expand All @@ -292,10 +309,12 @@ async def _start_config_flow(
entry_id: str = None,
):
"""Start a config flow"""
_LOGGER.debug("[start_config_flow] step_id: %s, defaults: %s", step_id, defaults)
errors = {}
description_placeholders = {}

if user_input is not None:
_LOGGER.debug("[start_config_flow] step_id: %s, initial user_input: %s, errors: %s", step_id, user_input, errors)
user_input[CONF_SLOTS] = int(user_input.get(CONF_SLOTS))
user_input[CONF_START] = int(user_input.get(CONF_START))

Expand All @@ -307,6 +326,7 @@ async def _start_config_flow(

# Update options if no errors
if not errors:
_LOGGER.debug("[start_config_flow] step_id: %s, final user_input: %s", step_id, user_input)
if step_id == "user":
return cls.async_create_entry(title=title, data=user_input)
cls.hass.config_entries.async_update_entry(
Expand Down
50 changes: 0 additions & 50 deletions pylintrc

This file was deleted.

Loading

0 comments on commit 431cfdb

Please sign in to comment.