Remove useless async_add_executor_job (#44496)

pull/44514/head
Thibaut 2020-12-24 20:42:56 +01:00 committed by GitHub
parent d385a51653
commit 19b957cd84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 45 deletions

View File

@ -49,19 +49,17 @@ HVAC_MODES_MAPPING = {HvacState.COOL: HVAC_MODE_COOL, HvacState.HEAT: HVAC_MODE_
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Somfy climate platform."""
def get_thermostats():
"""Retrieve thermostats."""
domain_data = hass.data[DOMAIN]
coordinator = domain_data[COORDINATOR]
api = domain_data[API]
domain_data = hass.data[DOMAIN]
coordinator = domain_data[COORDINATOR]
api = domain_data[API]
return [
SomfyClimate(coordinator, device_id, api)
for device_id, device in coordinator.data.items()
if SUPPORTED_CATEGORIES & set(device.categories)
]
climates = [
SomfyClimate(coordinator, device_id, api)
for device_id, device in coordinator.data.items()
if SUPPORTED_CATEGORIES & set(device.categories)
]
async_add_entities(await hass.async_add_executor_job(get_thermostats))
async_add_entities(climates)
class SomfyClimate(SomfyEntity, ClimateEntity):

View File

@ -36,19 +36,17 @@ SUPPORTED_CATEGORIES = {
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Somfy cover platform."""
def get_covers():
"""Retrieve covers."""
domain_data = hass.data[DOMAIN]
coordinator = domain_data[COORDINATOR]
api = domain_data[API]
domain_data = hass.data[DOMAIN]
coordinator = domain_data[COORDINATOR]
api = domain_data[API]
return [
SomfyCover(coordinator, device_id, api, domain_data[CONF_OPTIMISTIC])
for device_id, device in coordinator.data.items()
if SUPPORTED_CATEGORIES & set(device.categories)
]
covers = [
SomfyCover(coordinator, device_id, api, domain_data[CONF_OPTIMISTIC])
for device_id, device in coordinator.data.items()
if SUPPORTED_CATEGORIES & set(device.categories)
]
async_add_entities(await hass.async_add_executor_job(get_covers))
async_add_entities(covers)
class SomfyCover(SomfyEntity, RestoreEntity, CoverEntity):

View File

@ -12,21 +12,19 @@ SUPPORTED_CATEGORIES = {Category.HVAC.value}
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Somfy climate platform."""
"""Set up the Somfy sensor platform."""
def get_thermostats():
"""Retrieve thermostats."""
domain_data = hass.data[DOMAIN]
coordinator = domain_data[COORDINATOR]
api = domain_data[API]
domain_data = hass.data[DOMAIN]
coordinator = domain_data[COORDINATOR]
api = domain_data[API]
return [
SomfyThermostatBatterySensor(coordinator, device_id, api)
for device_id, device in coordinator.data.items()
if SUPPORTED_CATEGORIES & set(device.categories)
]
sensors = [
SomfyThermostatBatterySensor(coordinator, device_id, api)
for device_id, device in coordinator.data.items()
if SUPPORTED_CATEGORIES & set(device.categories)
]
async_add_entities(await hass.async_add_executor_job(get_thermostats))
async_add_entities(sensors)
class SomfyThermostatBatterySensor(SomfyEntity):

View File

@ -11,19 +11,17 @@ from .const import API, COORDINATOR, DOMAIN
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Somfy switch platform."""
def get_shutters():
"""Retrieve switches."""
domain_data = hass.data[DOMAIN]
coordinator = domain_data[COORDINATOR]
api = domain_data[API]
domain_data = hass.data[DOMAIN]
coordinator = domain_data[COORDINATOR]
api = domain_data[API]
return [
SomfyCameraShutter(coordinator, device_id, api)
for device_id, device in coordinator.data.items()
if Category.CAMERA.value in device.categories
]
switches = [
SomfyCameraShutter(coordinator, device_id, api)
for device_id, device in coordinator.data.items()
if Category.CAMERA.value in device.categories
]
async_add_entities(await hass.async_add_executor_job(get_shutters), True)
async_add_entities(switches)
class SomfyCameraShutter(SomfyEntity, SwitchEntity):