mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Don't run unnecessary methods in executor pool (#14853)
* Don't run unnecessary methods in executor pool * Lint * Lint 2
This commit is contained in:
parent
50321a29b5
commit
90a51160c4
@ -272,8 +272,7 @@ class AxisDeviceEvent(Entity):
|
|||||||
|
|
||||||
def _update_callback(self):
|
def _update_callback(self):
|
||||||
"""Update the sensor's state, if needed."""
|
"""Update the sensor's state, if needed."""
|
||||||
self.update()
|
self.schedule_update_ha_state(True)
|
||||||
self.schedule_update_ha_state()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -19,8 +19,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Perform the setup for Vera controller devices."""
|
"""Perform the setup for Vera controller devices."""
|
||||||
add_devices(
|
add_devices(
|
||||||
VeraBinarySensor(device, hass.data[VERA_CONTROLLER])
|
[VeraBinarySensor(device, hass.data[VERA_CONTROLLER])
|
||||||
for device in hass.data[VERA_DEVICES]['binary_sensor'])
|
for device in hass.data[VERA_DEVICES]['binary_sensor']], True)
|
||||||
|
|
||||||
|
|
||||||
class VeraBinarySensor(VeraDevice, BinarySensorDevice):
|
class VeraBinarySensor(VeraDevice, BinarySensorDevice):
|
||||||
|
@ -54,6 +54,7 @@ class VerisureDoorWindowSensor(BinarySensorDevice):
|
|||||||
"$.doorWindow.doorWindowDevice[?(@.deviceLabel=='%s')]",
|
"$.doorWindow.doorWindowDevice[?(@.deviceLabel=='%s')]",
|
||||||
self._device_label) is not None
|
self._device_label) is not None
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the state of the sensor."""
|
"""Update the state of the sensor."""
|
||||||
hub.update_overview()
|
hub.update_overview()
|
||||||
|
@ -32,8 +32,8 @@ SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE |
|
|||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
"""Set up of Vera thermostats."""
|
"""Set up of Vera thermostats."""
|
||||||
add_devices_callback(
|
add_devices_callback(
|
||||||
VeraThermostat(device, hass.data[VERA_CONTROLLER]) for
|
[VeraThermostat(device, hass.data[VERA_CONTROLLER]) for
|
||||||
device in hass.data[VERA_DEVICES]['climate'])
|
device in hass.data[VERA_DEVICES]['climate']], True)
|
||||||
|
|
||||||
|
|
||||||
class VeraThermostat(VeraDevice, ClimateDevice):
|
class VeraThermostat(VeraDevice, ClimateDevice):
|
||||||
@ -101,10 +101,6 @@ class VeraThermostat(VeraDevice, ClimateDevice):
|
|||||||
if power:
|
if power:
|
||||||
return convert(power, float, 0.0)
|
return convert(power, float, 0.0)
|
||||||
|
|
||||||
def update(self):
|
|
||||||
"""Handle state updates."""
|
|
||||||
self._state = self.vera_device.get_hvac_mode()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self):
|
def temperature_unit(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
|
@ -19,8 +19,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Vera covers."""
|
"""Set up the Vera covers."""
|
||||||
add_devices(
|
add_devices(
|
||||||
VeraCover(device, hass.data[VERA_CONTROLLER]) for
|
[VeraCover(device, hass.data[VERA_CONTROLLER]) for
|
||||||
device in hass.data[VERA_DEVICES]['cover'])
|
device in hass.data[VERA_DEVICES]['cover']], True)
|
||||||
|
|
||||||
|
|
||||||
class VeraCover(VeraDevice, CoverDevice):
|
class VeraCover(VeraDevice, CoverDevice):
|
||||||
|
@ -22,8 +22,8 @@ DEPENDENCIES = ['vera']
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Vera lights."""
|
"""Set up the Vera lights."""
|
||||||
add_devices(
|
add_devices(
|
||||||
VeraLight(device, hass.data[VERA_CONTROLLER]) for
|
[VeraLight(device, hass.data[VERA_CONTROLLER]) for
|
||||||
device in hass.data[VERA_DEVICES]['light'])
|
device in hass.data[VERA_DEVICES]['light']], True)
|
||||||
|
|
||||||
|
|
||||||
class VeraLight(VeraDevice, Light):
|
class VeraLight(VeraDevice, Light):
|
||||||
|
@ -19,8 +19,8 @@ DEPENDENCIES = ['vera']
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Find and return Vera locks."""
|
"""Find and return Vera locks."""
|
||||||
add_devices(
|
add_devices(
|
||||||
VeraLock(device, hass.data[VERA_CONTROLLER]) for
|
[VeraLock(device, hass.data[VERA_CONTROLLER]) for
|
||||||
device in hass.data[VERA_DEVICES]['lock'])
|
device in hass.data[VERA_DEVICES]['lock']], True)
|
||||||
|
|
||||||
|
|
||||||
class VeraLock(VeraDevice, LockDevice):
|
class VeraLock(VeraDevice, LockDevice):
|
||||||
|
@ -25,8 +25,8 @@ SCAN_INTERVAL = timedelta(seconds=5)
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Vera controller devices."""
|
"""Set up the Vera controller devices."""
|
||||||
add_devices(
|
add_devices(
|
||||||
VeraSensor(device, hass.data[VERA_CONTROLLER])
|
[VeraSensor(device, hass.data[VERA_CONTROLLER])
|
||||||
for device in hass.data[VERA_DEVICES]['sensor'])
|
for device in hass.data[VERA_DEVICES]['sensor']], True)
|
||||||
|
|
||||||
|
|
||||||
class VeraSensor(VeraDevice, Entity):
|
class VeraSensor(VeraDevice, Entity):
|
||||||
|
@ -74,6 +74,7 @@ class VerisureThermometer(Entity):
|
|||||||
"""Return the unit of measurement of this entity."""
|
"""Return the unit of measurement of this entity."""
|
||||||
return TEMP_CELSIUS
|
return TEMP_CELSIUS
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
hub.update_overview()
|
hub.update_overview()
|
||||||
@ -112,6 +113,7 @@ class VerisureHygrometer(Entity):
|
|||||||
"""Return the unit of measurement of this entity."""
|
"""Return the unit of measurement of this entity."""
|
||||||
return '%'
|
return '%'
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
hub.update_overview()
|
hub.update_overview()
|
||||||
@ -150,6 +152,7 @@ class VerisureMouseDetection(Entity):
|
|||||||
"""Return the unit of measurement of this entity."""
|
"""Return the unit of measurement of this entity."""
|
||||||
return 'Mice'
|
return 'Mice'
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
hub.update_overview()
|
hub.update_overview()
|
||||||
|
@ -19,8 +19,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Vera switches."""
|
"""Set up the Vera switches."""
|
||||||
add_devices(
|
add_devices(
|
||||||
VeraSwitch(device, hass.data[VERA_CONTROLLER]) for
|
[VeraSwitch(device, hass.data[VERA_CONTROLLER]) for
|
||||||
device in hass.data[VERA_DEVICES]['switch'])
|
device in hass.data[VERA_DEVICES]['switch']], True)
|
||||||
|
|
||||||
|
|
||||||
class VeraSwitch(VeraDevice, SwitchDevice):
|
class VeraSwitch(VeraDevice, SwitchDevice):
|
||||||
|
@ -72,6 +72,7 @@ class VerisureSmartplug(SwitchDevice):
|
|||||||
self._state = False
|
self._state = False
|
||||||
self._change_timestamp = time()
|
self._change_timestamp = time()
|
||||||
|
|
||||||
|
# pylint: disable=no-self-use
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest date of the smartplug."""
|
"""Get the latest date of the smartplug."""
|
||||||
hub.update_overview()
|
hub.update_overview()
|
||||||
|
@ -148,12 +148,10 @@ class VeraDevice(Entity):
|
|||||||
slugify(vera_device.name), vera_device.device_id)
|
slugify(vera_device.name), vera_device.device_id)
|
||||||
|
|
||||||
self.controller.register(vera_device, self._update_callback)
|
self.controller.register(vera_device, self._update_callback)
|
||||||
self.update()
|
|
||||||
|
|
||||||
def _update_callback(self, _device):
|
def _update_callback(self, _device):
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
self.update()
|
self.schedule_update_ha_state(True)
|
||||||
self.schedule_update_ha_state()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -171,13 +171,6 @@ class Entity(object):
|
|||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def update(self):
|
|
||||||
"""Retrieve latest state.
|
|
||||||
|
|
||||||
For asyncio use coroutine async_update.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
# DO NOT OVERWRITE
|
# DO NOT OVERWRITE
|
||||||
# These properties and methods are either managed by Home Assistant or they
|
# These properties and methods are either managed by Home Assistant or they
|
||||||
# are used to perform a very specific function. Overwriting these may
|
# are used to perform a very specific function. Overwriting these may
|
||||||
@ -320,10 +313,10 @@ class Entity(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# pylint: disable=no-member
|
||||||
if hasattr(self, 'async_update'):
|
if hasattr(self, 'async_update'):
|
||||||
# pylint: disable=no-member
|
|
||||||
yield from self.async_update()
|
yield from self.async_update()
|
||||||
else:
|
elif hasattr(self, 'update'):
|
||||||
yield from self.hass.async_add_job(self.update)
|
yield from self.hass.async_add_job(self.update)
|
||||||
finally:
|
finally:
|
||||||
self._update_staged = False
|
self._update_staged = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user