Skip to content

Commit

Permalink
Add Room Audio Control to Control4 Integration (home-assistant#87821)
Browse files Browse the repository at this point in the history
* Add control4 room based media player (#13)

* update attribute names (#14)

* change to data class and set off to idle (#15)

Co-authored-by: nalin29 <nalin29@github.com>

---------

Co-authored-by: nalin29 <nalin29@github.com>
  • Loading branch information
nalin29 and nalin29 authored Mar 19, 2024
1 parent 4381780 commit 18ef76a
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 9 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ omit =
homeassistant/components/control4/__init__.py
homeassistant/components/control4/director_utils.py
homeassistant/components/control4/light.py
homeassistant/components/control4/media_player.py
homeassistant/components/coolmaster/coordinator.py
homeassistant/components/cppm_tracker/device_tracker.py
homeassistant/components/crownstone/__init__.py
Expand Down
12 changes: 8 additions & 4 deletions homeassistant/components/control4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import logging
from typing import Any

from aiohttp import client_exceptions
from pyControl4.account import C4Account
Expand Down Expand Up @@ -36,13 +37,14 @@
CONF_DIRECTOR_ALL_ITEMS,
CONF_DIRECTOR_MODEL,
CONF_DIRECTOR_SW_VERSION,
CONF_UI_CONFIGURATION,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
)

_LOGGER = logging.getLogger(__name__)

PLATFORMS = [Platform.LIGHT]
PLATFORMS = [Platform.LIGHT, Platform.MEDIA_PLAYER]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Expand Down Expand Up @@ -105,6 +107,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
director_all_items = json.loads(director_all_items)
entry_data[CONF_DIRECTOR_ALL_ITEMS] = director_all_items

entry_data[CONF_UI_CONFIGURATION] = json.loads(await director.getUiConfiguration())

# Load options from config entry
entry_data[CONF_SCAN_INTERVAL] = entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
Expand Down Expand Up @@ -145,14 +149,14 @@ async def get_items_of_category(hass: HomeAssistant, entry: ConfigEntry, categor
]


class Control4Entity(CoordinatorEntity):
class Control4Entity(CoordinatorEntity[Any]):
"""Base entity for Control4."""

def __init__(
self,
entry_data: dict,
coordinator: DataUpdateCoordinator,
name: str,
coordinator: DataUpdateCoordinator[Any],
name: str | None,
idx: int,
device_name: str | None,
device_manufacturer: str | None,
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/control4/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CONF_DIRECTOR_SW_VERSION = "director_sw_version"
CONF_DIRECTOR_MODEL = "director_model"
CONF_DIRECTOR_ALL_ITEMS = "director_all_items"
CONF_UI_CONFIGURATION = "ui_configuration"
CONF_CONTROLLER_UNIQUE_ID = "controller_unique_id"

CONF_CONFIG_LISTENER = "config_listener"
Expand Down
12 changes: 7 additions & 5 deletions homeassistant/components/control4/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def async_setup_entry(
scan_interval,
)

async def async_update_data_non_dimmer():
async def async_update_data_non_dimmer() -> dict[int, dict[str, Any]]:
"""Fetch data from Control4 director for non-dimmer lights."""
try:
return await update_variables_for_config_entry(
Expand All @@ -54,7 +54,7 @@ async def async_update_data_non_dimmer():
except C4Exception as err:
raise UpdateFailed(f"Error communicating with API: {err}") from err

async def async_update_data_dimmer():
async def async_update_data_dimmer() -> dict[int, dict[str, Any]]:
"""Fetch data from Control4 director for dimmer lights."""
try:
return await update_variables_for_config_entry(
Expand All @@ -63,14 +63,14 @@ async def async_update_data_dimmer():
except C4Exception as err:
raise UpdateFailed(f"Error communicating with API: {err}") from err

non_dimmer_coordinator = DataUpdateCoordinator(
non_dimmer_coordinator = DataUpdateCoordinator[dict[int, dict[str, Any]]](
hass,
_LOGGER,
name="light",
update_method=async_update_data_non_dimmer,
update_interval=timedelta(seconds=scan_interval),
)
dimmer_coordinator = DataUpdateCoordinator(
dimmer_coordinator = DataUpdateCoordinator[dict[int, dict[str, Any]]](
hass,
_LOGGER,
name="light",
Expand Down Expand Up @@ -149,10 +149,12 @@ async def async_update_data_dimmer():
class Control4Light(Control4Entity, LightEntity):
"""Control4 light entity."""

_attr_has_entity_name = True

def __init__(
self,
entry_data: dict,
coordinator: DataUpdateCoordinator,
coordinator: DataUpdateCoordinator[dict[int, dict[str, Any]]],
name: str,
idx: int,
device_name: str | None,
Expand Down
Loading

0 comments on commit 18ef76a

Please sign in to comment.