mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Built-in components no longer use deprecated methods
This commit is contained in:
parent
7870e9a5e2
commit
382c1de981
@ -5,6 +5,7 @@ homeassistant.components.automation.time
|
|||||||
Offers time listening automation rules.
|
Offers time listening automation rules.
|
||||||
"""
|
"""
|
||||||
from homeassistant.util import convert
|
from homeassistant.util import convert
|
||||||
|
from homeassistant.helpers.event import track_time_change
|
||||||
|
|
||||||
CONF_HOURS = "time_hours"
|
CONF_HOURS = "time_hours"
|
||||||
CONF_MINUTES = "time_minutes"
|
CONF_MINUTES = "time_minutes"
|
||||||
@ -21,8 +22,7 @@ def register(hass, config, action):
|
|||||||
""" Listens for time changes and calls action. """
|
""" Listens for time changes and calls action. """
|
||||||
action()
|
action()
|
||||||
|
|
||||||
hass.track_time_change(
|
track_time_change(hass, time_automation_listener,
|
||||||
time_automation_listener,
|
hour=hours, minute=minutes, second=seconds)
|
||||||
hour=hours, minute=minutes, second=seconds)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -8,6 +8,7 @@ the state of the sun and devices.
|
|||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from homeassistant.helpers.event import track_point_in_time
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME
|
from homeassistant.const import STATE_HOME, STATE_NOT_HOME
|
||||||
from . import light, sun, device_tracker, group
|
from . import light, sun, device_tracker, group
|
||||||
@ -91,9 +92,9 @@ def setup(hass, config):
|
|||||||
|
|
||||||
if start_point:
|
if start_point:
|
||||||
for index, light_id in enumerate(light_ids):
|
for index, light_id in enumerate(light_ids):
|
||||||
hass.track_point_in_time(turn_on(light_id),
|
track_point_in_time(
|
||||||
(start_point +
|
hass, turn_on(light_id),
|
||||||
index * LIGHT_TRANSITION_TIME))
|
(start_point + index * LIGHT_TRANSITION_TIME))
|
||||||
|
|
||||||
# Track every time sun rises so we can schedule a time-based
|
# Track every time sun rises so we can schedule a time-based
|
||||||
# pre-sun set event
|
# pre-sun set event
|
||||||
|
@ -15,6 +15,7 @@ from homeassistant.helpers import validate_config
|
|||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
|
from homeassistant.helpers.event import track_utc_time_change
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_HOME, STATE_NOT_HOME, ATTR_ENTITY_PICTURE, ATTR_FRIENDLY_NAME,
|
STATE_HOME, STATE_NOT_HOME, ATTR_ENTITY_PICTURE, ATTR_FRIENDLY_NAME,
|
||||||
CONF_PLATFORM, DEVICE_DEFAULT_NAME)
|
CONF_PLATFORM, DEVICE_DEFAULT_NAME)
|
||||||
@ -134,7 +135,7 @@ class DeviceTracker(object):
|
|||||||
seconds = range(0, 60, seconds)
|
seconds = range(0, 60, seconds)
|
||||||
|
|
||||||
_LOGGER.info("Device tracker interval second=%s", seconds)
|
_LOGGER.info("Device tracker interval second=%s", seconds)
|
||||||
hass.track_utc_time_change(update_device_state, second=seconds)
|
track_utc_time_change(hass, update_device_state, second=seconds)
|
||||||
|
|
||||||
hass.services.register(DOMAIN,
|
hass.services.register(DOMAIN,
|
||||||
SERVICE_DEVICE_TRACKER_RELOAD,
|
SERVICE_DEVICE_TRACKER_RELOAD,
|
||||||
|
@ -17,6 +17,7 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
from homeassistant.helpers.event import track_point_in_time
|
||||||
from homeassistant.components.scheduler import ServiceEventListener
|
from homeassistant.components.scheduler import ServiceEventListener
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -62,7 +63,7 @@ class TimeEventListener(ServiceEventListener):
|
|||||||
""" Call the execute method """
|
""" Call the execute method """
|
||||||
self.execute(hass)
|
self.execute(hass)
|
||||||
|
|
||||||
hass.track_point_in_time(execute, next_time)
|
track_point_in_time(hass, execute, next_time)
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
'TimeEventListener scheduled for %s, will call service %s.%s',
|
'TimeEventListener scheduled for %s, will call service %s.%s',
|
||||||
|
@ -10,6 +10,7 @@ from datetime import timedelta
|
|||||||
import homeassistant.util.dt as date_util
|
import homeassistant.util.dt as date_util
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
from homeassistant.helpers.event import track_point_in_time
|
||||||
from homeassistant.util import split_entity_id
|
from homeassistant.util import split_entity_id
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF, EVENT_TIME_CHANGED)
|
STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF, EVENT_TIME_CHANGED)
|
||||||
@ -111,8 +112,8 @@ class Script(object):
|
|||||||
elif CONF_DELAY in action:
|
elif CONF_DELAY in action:
|
||||||
delay = timedelta(**action[CONF_DELAY])
|
delay = timedelta(**action[CONF_DELAY])
|
||||||
point_in_time = date_util.now() + delay
|
point_in_time = date_util.now() + delay
|
||||||
self.listener = self.hass.track_point_in_time(
|
self.listener = track_point_in_time(
|
||||||
self, point_in_time)
|
self.hass, self, point_in_time)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ import urllib
|
|||||||
|
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
from homeassistant.helpers.event import (
|
||||||
|
track_point_in_utc_time, track_point_in_time)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.components.scheduler import ServiceEventListener
|
from homeassistant.components.scheduler import ServiceEventListener
|
||||||
|
|
||||||
@ -209,8 +211,8 @@ class Sun(Entity):
|
|||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
# Schedule next update at next_change+1 second so sun state has changed
|
# Schedule next update at next_change+1 second so sun state has changed
|
||||||
self.hass.track_point_in_utc_time(
|
track_point_in_utc_time(
|
||||||
self.point_in_time_listener,
|
self.hass, self.point_in_time_listener,
|
||||||
self.next_change + timedelta(seconds=1))
|
self.next_change + timedelta(seconds=1))
|
||||||
|
|
||||||
|
|
||||||
@ -272,7 +274,7 @@ class SunEventListener(ServiceEventListener):
|
|||||||
""" Call the execute method. """
|
""" Call the execute method. """
|
||||||
self.execute(hass)
|
self.execute(hass)
|
||||||
|
|
||||||
hass.track_point_in_time(execute, next_time)
|
track_point_in_time(hass, execute, next_time)
|
||||||
|
|
||||||
return next_time
|
return next_time
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ Provides helpers for components that manage entities.
|
|||||||
from homeassistant.bootstrap import prepare_setup_platform
|
from homeassistant.bootstrap import prepare_setup_platform
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
generate_entity_id, config_per_platform, extract_entity_ids)
|
generate_entity_id, config_per_platform, extract_entity_ids)
|
||||||
|
from homeassistant.helpers.event import track_utc_time_change
|
||||||
from homeassistant.components import group, discovery
|
from homeassistant.components import group, discovery
|
||||||
from homeassistant.const import ATTR_ENTITY_ID
|
from homeassistant.const import ATTR_ENTITY_ID
|
||||||
|
|
||||||
@ -115,8 +116,8 @@ class EntityComponent(object):
|
|||||||
|
|
||||||
self.is_polling = True
|
self.is_polling = True
|
||||||
|
|
||||||
self.hass.track_time_change(
|
track_utc_time_change(
|
||||||
self._update_entity_states,
|
self.hass, self._update_entity_states,
|
||||||
second=range(0, 60, self.scan_interval))
|
second=range(0, 60, self.scan_interval))
|
||||||
|
|
||||||
def _setup_platform(self, platform_type, platform_config,
|
def _setup_platform(self, platform_type, platform_config,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user