Skip to content

Commit

Permalink
feat: allow reconfiguring via options (#2319)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrunt57 authored Jul 18, 2024
1 parent 46369ae commit 8908b38
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 169 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repos:
- id: check-yaml
exclude: ^recipes/.*
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0

# --- Commit msg checks ---
- hooks:
Expand All @@ -55,18 +55,18 @@ repos:
hooks:
- id: prettier
exclude: ^custom_components/alexa_media/translations|CHANGELOG.md
rev: v3.0.3
rev: v4.0.0-alpha.8
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.32.0
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
rev: 1.7.9
hooks:
- id: bandit
args:
Expand All @@ -75,7 +75,7 @@ repos:
- --configfile=tests/bandit.yaml
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
# - repo: local
Expand All @@ -92,7 +92,7 @@ repos:
- id: sync_with_poetry
args: []
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
Expand Down
17 changes: 11 additions & 6 deletions custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
For more details about this platform, please refer to the documentation at
https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639
"""

import asyncio
from datetime import datetime, timedelta
from json import JSONDecodeError, loads
Expand Down Expand Up @@ -480,9 +481,11 @@ async def async_update_data() -> Optional[AlexaEntityData]:
"%s: Found %s devices, %s bluetooth",
hide_email(email),
len(devices) if devices is not None else "",
len(bluetooth.get("bluetoothStates", []))
if bluetooth is not None
else "",
(
len(bluetooth.get("bluetoothStates", []))
if bluetooth is not None
else ""
),
)

await process_notifications(login_obj, raw_notifications)
Expand Down Expand Up @@ -1388,9 +1391,11 @@ async def test_login_status(hass, config_entry, login) -> bool:
CONF_DEBUG: account[CONF_DEBUG],
CONF_INCLUDE_DEVICES: account[CONF_INCLUDE_DEVICES],
CONF_EXCLUDE_DEVICES: account[CONF_EXCLUDE_DEVICES],
CONF_SCAN_INTERVAL: account[CONF_SCAN_INTERVAL].total_seconds()
if isinstance(account[CONF_SCAN_INTERVAL], timedelta)
else account[CONF_SCAN_INTERVAL],
CONF_SCAN_INTERVAL: (
account[CONF_SCAN_INTERVAL].total_seconds()
if isinstance(account[CONF_SCAN_INTERVAL], timedelta)
else account[CONF_SCAN_INTERVAL]
),
CONF_OTPSECRET: account.get(CONF_OTPSECRET, ""),
},
)
Expand Down
1 change: 1 addition & 0 deletions custom_components/alexa_media/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
For more details about this platform, please refer to the documentation at
https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639
"""

from asyncio import sleep
import logging
from typing import List, Optional
Expand Down
14 changes: 11 additions & 3 deletions custom_components/alexa_media/alexa_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
For more details about this platform, please refer to the documentation at
https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639
"""

from datetime import datetime
import json
import logging
Expand Down Expand Up @@ -75,7 +76,10 @@ def is_local(appliance: dict[str, Any]) -> bool:

# Ledvance/Sengled bulbs connected via bluetooth are hard to detect as locally connected
# There is probably a better way, but this works for now.
if appliance.get("manufacturerName") == "Ledvance" or appliance.get("manufacturerName") == "Sengled":
if (
appliance.get("manufacturerName") == "Ledvance"
or appliance.get("manufacturerName") == "Sengled"
):
return not is_skill(appliance)

# Zigbee devices are guaranteed to be local and have a particular pattern of id
Expand Down Expand Up @@ -115,8 +119,11 @@ def is_light(appliance: dict[str, Any]) -> bool:
return (
is_local(appliance)
and (
"LIGHT" in appliance.get("applianceTypes", [])
or ("SMARTPLUG" in appliance.get("applianceTypes", []) and appliance.get("customerDefinedDeviceType") == "LIGHT")
"LIGHT" in appliance.get("applianceTypes", [])
or (
"SMARTPLUG" in appliance.get("applianceTypes", [])
and appliance.get("customerDefinedDeviceType") == "LIGHT"
)
)
and has_capability(appliance, "Alexa.PowerController", "powerState")
)
Expand All @@ -130,6 +137,7 @@ def is_contact_sensor(appliance: dict[str, Any]) -> bool:
and has_capability(appliance, "Alexa.ContactSensor", "detectionState")
)


def is_switch(appliance: dict[str, Any]) -> bool:
"""Is the given appliance a switch controlled locally by an Echo, which is not redeclared as a light."""
return (
Expand Down
Loading

0 comments on commit 8908b38

Please sign in to comment.