Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Feb 14, 2024
2 parents 62e00fc + e610731 commit aef760c
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 106 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/auto_approve_dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Auto approve Dependabot PR's

on: pull_request_target

jobs:
auto-approve:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.actor == 'dependabot[bot]'
steps:
- uses: hmarr/auto-approve-action@v4
28 changes: 28 additions & 0 deletions .github/workflows/pre-commit-updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Pre-commit auto-update
on:
schedule:
- cron: '0 0 * * *'
jobs:
auto-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit autoupdate
run: pre-commit autoupdate
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-autoupdate
title: Auto-update pre-commit hooks
commit-message: Auto-update pre-commit hooks
body: |
Update versions of tools in pre-commit
configs to latest version
labels: dependencies
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131 changes: 35 additions & 96 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,109 +1,48 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: local
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: ruff-check
name: 🐶 Ruff Linter
language: system
types: [python]
entry: scripts/run-in-env.sh ruff check --fix
require_serial: true
stages: [commit, push, manual]
- id: ruff-format
name: 🐶 Ruff Formatter
language: system
types: [python]
entry: scripts/run-in-env.sh ruff format
require_serial: true
stages: [commit, push, manual]
- id: check-ast
name: 🐍 Check Python AST
language: system
types: [python]
entry: scripts/run-in-env.sh check-ast
- id: check-case-conflict
name: 🔠 Check for case conflicts
language: system
entry: scripts/run-in-env.sh check-case-conflict
- id: check-docstring-first
name: ℹ️ Check docstring is first
language: system
types: [python]
entry: scripts/run-in-env.sh check-docstring-first
- id: check-executables-have-shebangs
name: 🧐 Check that executables have shebangs
language: system
types: [text, executable]
entry: scripts/run-in-env.sh check-executables-have-shebangs
stages: [commit, push, manual]
- id: check-json
name: { Check JSON files
language: system
types: [json]
entry: scripts/run-in-env.sh check-json
files: ^(custom_components/mass)/.+\.json$
- id: check-yaml
name: { Check YAML files
language: system
types: [yaml]
entry: scripts/run-in-env.sh check-yaml
- id: check-merge-conflict
name: 💥 Check for merge conflicts
language: system
types: [text]
entry: scripts/run-in-env.sh check-merge-conflict
- id: check-symlinks
name: 🔗 Check for broken symlinks
language: system
types: [symlink]
entry: scripts/run-in-env.sh check-symlinks
- id: check-toml
name: ✅ Check TOML files
language: system
types: [toml]
entry: scripts/run-in-env.sh check-toml
- id: codespell
name: ✅ Check code for common misspellings
language: system
types: [text]
entry: scripts/run-in-env.sh codespell
- id: detect-private-key
name: 🕵️ Detect Private Keys
language: system
types: [text]
entry: scripts/run-in-env.sh detect-private-key
- id: end-of-file-fixer
name: ⮐ Fix End of Files
language: system
types: [text]
entry: scripts/run-in-env.sh end-of-file-fixer
stages: [commit, push, manual]
- id: trailing-whitespace
- id: no-commit-to-branch
name: 🛑 Don't commit to main branch
language: system
entry: scripts/run-in-env.sh no-commit-to-branch
pass_filenames: false
always_run: true
args:
- --branch=main
- id: debug-statements
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.2.1'
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
args:
- --safe
- --quiet
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: []
exclude_types: [csv, json]
exclude: ^tests/fixtures/
additional_dependencies:
- tomli

- repo: local
hooks:
- id: pylint
name: 🌟 Starring code with pylint
language: system
name: pylint
entry: script/run-in-env.sh pylint -j 0
language: script
types: [python]
entry: scripts/run-in-env.sh pylint
- id: trailing-whitespace
name: ✄ Trim Trailing Whitespace
language: system
types: [text]
entry: scripts/run-in-env.sh trailing-whitespace-fixer
stages: [commit, push, manual]
###############################################
# TODO: enable mypy later
files: ^custom_components/mass/.+\.py$

# TODO: reinstate mypy after fixing the many issues
# - id: mypy
# name: mypy
# entry: scripts/run-in-env.sh mypy
# entry: script/run-in-env.sh mypy
# language: script
# types: [python]
# require_serial: true
# files: ^(custom_components/mass|pylint)/.+\.py$
# files: ^custom_components/mass/.+\.py$
6 changes: 3 additions & 3 deletions custom_components/mass/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ async def async_step_manual(

try:
self.server_info = await get_server_info(self.hass, user_input[CONF_URL])
self.openai_agent_id = user_input[CONF_OPENAI_AGENT_ID]
self.openai_agent_id = user_input[CONF_OPENAI_AGENT_ID] or ""
self.expose_players_assist = user_input[CONF_ASSIST_AUTO_EXPOSE_PLAYERS]
await self.async_set_unique_id(self.server_info.server_id)
except CannotConnect:
Expand Down Expand Up @@ -282,7 +282,7 @@ async def async_step_discovery_confirm(
if user_input is not None:
# Check that we can connect to the address.
try:
self.openai_agent_id = user_input[CONF_OPENAI_AGENT_ID]
self.openai_agent_id = user_input[CONF_OPENAI_AGENT_ID] or ""
self.expose_players_assist = user_input[CONF_ASSIST_AUTO_EXPOSE_PLAYERS]
await get_server_info(self.hass, self.server_info.base_url)
except CannotConnect:
Expand Down Expand Up @@ -328,7 +328,7 @@ async def async_step_finish_addon_setup(
except CannotConnect:
return self.async_abort(reason="cannot_connect")
if user_input is not None:
self.openai_agent_id = user_input[CONF_OPENAI_AGENT_ID]
self.openai_agent_id = user_input[CONF_OPENAI_AGENT_ID] or ""
self.expose_players_assist = user_input[CONF_ASSIST_AUTO_EXPOSE_PLAYERS]
return await self._async_create_entry_or_abort()

Expand Down
8 changes: 2 additions & 6 deletions custom_components/mass/intent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Intents for the client integration."""

from __future__ import annotations

import json
Expand All @@ -10,7 +11,6 @@
SERVICE_PROCESS as CONVERSATION_SERVICE,
)
from homeassistant.components.conversation.const import DOMAIN as CONVERSATION_DOMAIN
from homeassistant.components.media_player import MediaPlayerEnqueue
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers import area_registry as ar
Expand Down Expand Up @@ -107,14 +107,10 @@ async def _parse_query_and_return_appropriate_response(
)
media_id = json_payload.get(ATTR_MEDIA_ID)
media_type = json_payload.get(ATTR_MEDIA_TYPE)
if isinstance(media_id, str) and media_type == "track":
enqueue = MediaPlayerEnqueue.PLAY
else:
enqueue = MediaPlayerEnqueue.REPLACE
await actual_player.async_play_media(
media_type=media_type,
media_id=media_id,
enqueue=enqueue,
enqueue=None,
extra={ATTR_RADIO_MODE: False},
)
response.response_type = intent.IntentResponseType.ACTION_DONE
Expand Down
4 changes: 4 additions & 0 deletions custom_components/mass/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ def compact_item(item: dict[str, Any]) -> dict[str, Any]:
item[key] = compact_item(value)
elif isinstance(value, list):
for subitem in value:
if not isinstance(subitem, dict):
continue
compact_item(subitem)
# item[key] = [compact_item(x) if isinstance(x, dict) else x for x in value]
return item

dict_result: dict[str, list[dict[str, Any]]] = result.to_dict()
for media_type_key in dict_result:
for item in dict_result[media_type_key]:
if not isinstance(item, dict):
continue
compact_item(item)
return dict_result

Expand Down
20 changes: 20 additions & 0 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# pylint: disable=wrong-import-order
from homeassistant.components import zeroconf
from homeassistant.data_entry_flow import InvalidData
from homeassistant.helpers.selector import ConversationAgentSelector
from music_assistant.client.exceptions import CannotConnect, InvalidServerVersion
from pytest_homeassistant_custom_component.common import MockConfigEntry
Expand Down Expand Up @@ -232,6 +233,25 @@ async def test_flow_discovery_confirm_creates_config_entry(m_mass, hass):
assert expected == result


@patch("custom_components.mass.config_flow.MusicAssistantClient")
async def test_flow_discovery_confirm_creates_config_entry_with_none_type_conversation_agent(
m_mass, hass # noqa: ARG001
):
"""Test the config entry is successfully created."""
with pytest.raises(InvalidData):
config_flow.ConfigFlow.data = VALID_CONFIG
_result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN, context={"source": "zeroconf"}, data=ZEROCONF_DATA
)
await hass.config_entries.flow.async_configure(
_result["flow_id"],
user_input={
CONF_OPENAI_AGENT_ID: None,
CONF_ASSIST_AUTO_EXPOSE_PLAYERS: False,
},
)


async def test_options_flow_init(hass):
"""Test config flow options."""
config_entry = await setup_mass_integration(hass)
Expand Down

0 comments on commit aef760c

Please sign in to comment.