Skip to content

Commit

Permalink
Release v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdwetering committed Apr 23, 2024
2 parents 67362ba + f345801 commit 9f06701
Show file tree
Hide file tree
Showing 24 changed files with 572 additions and 262 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Checks

on:
push:
branches:
- dev
- master
pull_request:
schedule:
- cron: "0 0 * * *"
Expand All @@ -11,7 +14,7 @@ jobs:
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]
steps:
- uses: "actions/checkout@v3"
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -23,7 +26,6 @@ jobs:
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
if [ -f requirements_test.txt ]; then pip install -r requirements_test.txt; fi
- name: Test with pytest
run: |
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ Custom integration for the Philips Hue Play HDMI Sync Box.

## About

> Please set up the Philips Hue Play HDMI Syncbox with the Hue App first and make sure it works before setting up this integration.
This integration exposes the Philips Hue Play HDMI Sync Box in Home Assistant so it can be used in automations or dashboards.

The Philips Hue Play HDMI Sync Box will be discovered automatically in most cases and can be added manually through the `Settings > Devices and Services` menu in Home Assistant if that is not the case.
The Philips Hue Play HDMI Sync Box will be discovered automatically in most cases and otherwise can be added manually through the `Settings > Devices and Services` menu in Home Assistant.

The following features are available:

Expand All @@ -27,7 +29,7 @@ The following features are available:
* HDMI Input selection
* Brightness control
* Entertainment area selection
* HDMI1-4 connection status
* HDMI input connection status
* Dolby Vision compatibility on/off
* LED indicator mode
* Bridge connection status ⁺
Expand All @@ -39,11 +41,11 @@ Entities marked with ⁺ are default disabled.

### Behavior

A few notes on behavior when changing entities.
A few notes on behavior when changing entities. Note that this behavior is just how the box reacts when sending these commands, not something coded in this integration.

* Enabling light sync will also power on the box
* Setting sync mode will also power on the box and start light sync on the selected mode
* When you want to change multiple entities the order is important. For example Intensity applies to the current selected mode. So if you want to change both the `intensity` and `mode` you _first_ have to change the mode and then set the intensity. Otherwise the intensity is applied to the "old" mode. If you want to avoid ordering issues you can use the `set_sync_state` service which will take care of the ordering and is more efficient.
* When you want to change multiple entities the order is important. For example, Intensity applies to the current selected mode. So if you want to change both the `intensity` and `mode` you _first_ have to change the mode and then set the intensity. Otherwise, the intensity is applied to the "old" mode. If you want to avoid ordering issues you can use the `set_sync_state` service which will take care of the ordering and is more efficient than sending everything separately.

### Services

Expand All @@ -67,11 +69,11 @@ No functionality is lost it just moved to a different place.
## Installation

> **Note**
> The Wifi connection of the Philips Hue Play HDMI Sync Box has to be setup with the official Hue app before it can be added to Home Assistant.
> Please setup the Philips Hue Play HDMI Syncbox with the Hue App first and make sure it works before setting up this integration.
### Home Assistant Community Store (HACS)

HACS is a 3rd party downloader for Home Assistant to easily install and update custom integrations made by the community. More information and installation instructions can be found on their site https://hacs.xyz/
HACS is a 3rd party downloader for Home Assistant to easily install and update custom integrations made by the community. More information and installation instructions can be found on the [HACS website](https://hacs.xyz/).

* Install the integration from within HACS (you can use the search box to find it)
* Restart Home Assistant
Expand All @@ -80,8 +82,8 @@ HACS is a 3rd party downloader for Home Assistant to easily install and update c
### Manually

* Install the custom component
* Download the zip from the releases section on Github
* Download the zip from the releases section on GitHub
* Unzip it
* Copy it to the custom_components directory of your Home Assistnat install as usual
* Copy it to the custom_components directory of your Home Assistant install as usual
* Restart Home Assistant
* Devices will be found automatically or can be added manually from the Home Assistant integrations screen
63 changes: 26 additions & 37 deletions custom_components/huesyncbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""The Philips Hue Play HDMI Sync Box integration."""
import asyncio
import aiohuesyncbox
import async_timeout

from homeassistant.components import automation
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
Expand All @@ -11,8 +10,9 @@
entity_registry,
)
from homeassistant.helpers import issue_registry
from homeassistant.helpers.typing import ConfigType

from .services import async_register_services, async_unregister_services
from .services import async_register_services

from .const import (
DOMAIN,
Expand All @@ -29,6 +29,12 @@
]


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Philips Hue Play HDMI Sync Box integration."""
hass.data[DOMAIN] = {}
await async_register_services(hass)
return True

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Philips Hue Play HDMI Sync Box from a config entry."""

Expand Down Expand Up @@ -57,12 +63,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

coordinator = HueSyncBoxCoordinator(hass, api)

hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

await async_register_services(hass)

return True


Expand All @@ -72,18 +75,14 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
coordinator = hass.data[DOMAIN].pop(entry.entry_id)
await coordinator.api.close()

if len(hass.data[DOMAIN]) == 0:
hass.data.pop(DOMAIN)
await async_unregister_services(hass)

return unload_ok


async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
# Best effort cleanup. User might not even have the device anymore or had it factory reset.
# Note that the entry already has been unloaded, so need to create API again
try:
async with async_timeout.timeout(10):
async with asyncio.timeout(10):
async with aiohuesyncbox.HueSyncBox(
entry.data["host"],
entry.data["unique_id"],
Expand All @@ -105,6 +104,9 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):

if config_entry.version == 1:
migrate_v1_to_v2(hass, config_entry)
if config_entry.version == 2:
if config_entry.minor_version == 1:
migrate_v2_1_to_v2_2(hass, config_entry)

LOGGER.info(
"Migration of ConfigEntry from version %s to version %s successful",
Expand All @@ -123,36 +125,23 @@ def migrate_v1_to_v2(hass: HomeAssistant, config_entry: ConfigEntry):
registry, config_entry.entry_id
)

automations_with_entity = []
for entity in entities:
if entity.domain == Platform.MEDIA_PLAYER:
registry.async_remove(entity.entity_id)

automations_with_entity = automation.automations_with_entity(
hass, entity.entity_id
)

automation_info = []
for automation_with_entity in automations_with_entity:
if automation_entry := registry.async_get(automation_with_entity):
automation_info.append(
f"{automation_entry.name or automation_entry.original_name} ({automation_with_entity})\n"
)

if len(automation_info) > 0:
issue_registry.async_create_issue(
hass,
DOMAIN,
f"automations_using_deleted_mediaplayer_{config_entry.entry_id}",
is_fixable=True,
is_persistent=True,
severity=issue_registry.IssueSeverity.WARNING,
translation_key="automations_using_deleted_mediaplayer",
translation_placeholders={
"automations": ",".join(automation_info),
"media_player_entity": entity.entity_id,
},
)
# There used to be a repair created here
# Removed due to adding dependency on automation

config_entry.version = 2
hass.config_entries.async_update_entry(config_entry)


def migrate_v2_1_to_v2_2(hass: HomeAssistant, config_entry: ConfigEntry):
# Remove any pending repairs
issue_registry.async_delete_issue(
hass, DOMAIN, f"automations_using_deleted_mediaplayer_{config_entry.entry_id}"
)

config_entry.version = 2
config_entry.minor_version = 2
hass.config_entries.async_update_entry(config_entry)
Loading

0 comments on commit 9f06701

Please sign in to comment.