Add support for async_setup_entry to switch and climate platform

This commit is contained in:
Mattias Welponer
2018-06-20 23:21:54 +02:00
parent 782e425f64
commit 35876c4f2d
3 changed files with 25 additions and 2 deletions

View File

@@ -246,7 +246,8 @@ def set_swing_mode(hass, swing_mode, entity_id=None):
async def async_setup(hass, config):
"""Set up climate devices."""
component = EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
component = hass.data[DOMAIN] = \
EntityComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
await component.async_setup(config)
async def async_away_mode_set_service(service):
@@ -456,6 +457,16 @@ async def async_setup(hass, config):
return True
async def async_setup_entry(hass, entry):
"""Setup a config entry."""
return await hass.data[DOMAIN].async_setup_entry(entry)
async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.data[DOMAIN].async_unload_entry(entry)
class ClimateDevice(Entity):
"""Representation of a climate device."""

View File

@@ -52,8 +52,10 @@ ATTR_OPERATION_LOCK = 'operation_lock'
COMPONENTS = [
'binary_sensor',
'climate',
'light',
'sensor',
'switch',
]

View File

@@ -95,7 +95,7 @@ def toggle(hass, entity_id=None):
async def async_setup(hass, config):
"""Track states and offer events for switches."""
component = EntityComponent(
component = hass.data[DOMAIN] = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL, GROUP_NAME_ALL_SWITCHES)
await component.async_setup(config)
@@ -132,6 +132,16 @@ async def async_setup(hass, config):
return True
async def async_setup_entry(hass, entry):
"""Setup a config entry."""
return await hass.data[DOMAIN].async_setup_entry(entry)
async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.data[DOMAIN].async_unload_entry(entry)
class SwitchDevice(ToggleEntity):
"""Representation of a switch."""