Skip to content

Commit

Permalink
fix: Let HA know the integration is , so that polling can be disabled…
Browse files Browse the repository at this point in the history
… via the integration system options
  • Loading branch information
BazaJayGee66 committed Mar 14, 2023
1 parent cba8f70 commit 47d009f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v2.0.1

## Fixes

- Let HA know the integration is `local_polling`, so that polling can be disabled via the integration system options

# v2.0.0

## New Features
Expand Down
24 changes: 14 additions & 10 deletions custom_components/cololight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.core import callback
from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_NAME, Platform

DOMAIN = "cololight"
PLATFORMS = [Platform.LIGHT]


async def async_setup(hass, config):
Expand All @@ -16,22 +17,25 @@ async def async_setup(hass, config):
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Load the saved entities."""

entry.add_update_listener(update_listener)
entry.async_on_unload(entry.add_update_listener(update_listener))

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, LIGHT_DOMAIN)
)
return True


async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.config_entries.async_forward_entry_unload(entry, LIGHT_DOMAIN)

unload_ok = await hass.config_entries.async_forward_entry_unload(
entry, LIGHT_DOMAIN
)

if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok


async def update_listener(hass, entry):
"""Handle options update."""
await hass.config_entries.async_forward_entry_unload(entry, LIGHT_DOMAIN)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, LIGHT_DOMAIN)
)
await hass.config_entries.async_reload(entry.entry_id)
3 changes: 2 additions & 1 deletion custom_components/cololight/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"config_flow": true,
"documentation": "https://github.com/BazaJayGee66/homeassistant_cololight",
"issue_tracker": "https://github.com/BazaJayGee66/homeassistant_cololight/issues",
"version": "v2.0.0",
"version": "v2.0.1",
"dependencies": [],
"iot_class": "local_polling",
"codeowners": ["@BazaJayGee66"],
"requirements": ["pycololight==2.0.0"]
}
5 changes: 0 additions & 5 deletions custom_components/tests/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ async def test_turn_off(mock_send, hass):


async def test_light_has_effects(hass):

state = hass.states.get(ENTITY_1_LIGHT)

expected_efects_list = [
Expand All @@ -251,7 +250,6 @@ async def test_light_has_effects(hass):


async def test_light_adds_custom_effect(hass):

state = hass.states.get(ENTITY_2_LIGHT)

expected_efects_list = [
Expand All @@ -265,7 +263,6 @@ async def test_light_adds_custom_effect(hass):


async def test_light_handles_incorrect_custom_effect(hass):

state = hass.states.get(ENTITY_3_LIGHT)

expected_efects_list = [
Expand All @@ -278,7 +275,6 @@ async def test_light_handles_incorrect_custom_effect(hass):


async def test_light_has_only_specified_default_effects(hass):

state = hass.states.get(ENTITY_4_LIGHT)

expected_efects_list = ["80s Club", "Custom Effect"]
Expand All @@ -287,7 +283,6 @@ async def test_light_has_only_specified_default_effects(hass):


async def test_icon(hass):

state_hexagon = hass.states.get(ENTITY_1_LIGHT)
state_strip = hass.states.get(ENTITY_6_LIGHT)

Expand Down

0 comments on commit 47d009f

Please sign in to comment.