Remove deprecated hide_if_away from device trackers (#32705)
parent
943c7ee11a
commit
bfacd9a1c3
|
@ -25,12 +25,10 @@ from .const import (
|
|||
ATTR_LOCATION_NAME,
|
||||
ATTR_MAC,
|
||||
ATTR_SOURCE_TYPE,
|
||||
CONF_AWAY_HIDE,
|
||||
CONF_CONSIDER_HOME,
|
||||
CONF_NEW_DEVICE_DEFAULTS,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_TRACK_NEW,
|
||||
DEFAULT_AWAY_HIDE,
|
||||
DEFAULT_CONSIDER_HOME,
|
||||
DEFAULT_TRACK_NEW,
|
||||
DOMAIN,
|
||||
|
@ -53,15 +51,7 @@ SOURCE_TYPES = (
|
|||
|
||||
NEW_DEVICE_DEFAULTS_SCHEMA = vol.Any(
|
||||
None,
|
||||
vol.All(
|
||||
cv.deprecated(CONF_AWAY_HIDE, invalidation_version="0.107.0"),
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_TRACK_NEW, default=DEFAULT_TRACK_NEW): cv.boolean,
|
||||
vol.Optional(CONF_AWAY_HIDE, default=DEFAULT_AWAY_HIDE): cv.boolean,
|
||||
}
|
||||
),
|
||||
),
|
||||
vol.Schema({vol.Optional(CONF_TRACK_NEW, default=DEFAULT_TRACK_NEW): cv.boolean}),
|
||||
)
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
|
|
|
@ -20,9 +20,6 @@ SCAN_INTERVAL = timedelta(seconds=12)
|
|||
CONF_TRACK_NEW = "track_new_devices"
|
||||
DEFAULT_TRACK_NEW = True
|
||||
|
||||
CONF_AWAY_HIDE = "hide_if_away"
|
||||
DEFAULT_AWAY_HIDE = False
|
||||
|
||||
CONF_CONSIDER_HOME = "consider_home"
|
||||
DEFAULT_CONSIDER_HOME = timedelta(seconds=180)
|
||||
|
||||
|
|
|
@ -37,11 +37,9 @@ from .const import (
|
|||
ATTR_HOST_NAME,
|
||||
ATTR_MAC,
|
||||
ATTR_SOURCE_TYPE,
|
||||
CONF_AWAY_HIDE,
|
||||
CONF_CONSIDER_HOME,
|
||||
CONF_NEW_DEVICE_DEFAULTS,
|
||||
CONF_TRACK_NEW,
|
||||
DEFAULT_AWAY_HIDE,
|
||||
DEFAULT_CONSIDER_HOME,
|
||||
DEFAULT_TRACK_NEW,
|
||||
DOMAIN,
|
||||
|
@ -198,7 +196,6 @@ class DeviceTracker:
|
|||
mac,
|
||||
picture=picture,
|
||||
icon=icon,
|
||||
hide_if_away=self.defaults.get(CONF_AWAY_HIDE, DEFAULT_AWAY_HIDE),
|
||||
)
|
||||
self.devices[dev_id] = device
|
||||
if mac is not None:
|
||||
|
@ -303,7 +300,6 @@ class Device(RestoreEntity):
|
|||
picture: str = None,
|
||||
gravatar: str = None,
|
||||
icon: str = None,
|
||||
hide_if_away: bool = False,
|
||||
) -> None:
|
||||
"""Initialize a device."""
|
||||
self.hass = hass
|
||||
|
@ -331,8 +327,6 @@ class Device(RestoreEntity):
|
|||
|
||||
self.icon = icon
|
||||
|
||||
self.away_hide = hide_if_away
|
||||
|
||||
self.source_type = None
|
||||
|
||||
self._attributes = {}
|
||||
|
@ -372,11 +366,6 @@ class Device(RestoreEntity):
|
|||
"""Return device state attributes."""
|
||||
return self._attributes
|
||||
|
||||
@property
|
||||
def hidden(self):
|
||||
"""If device should be hidden."""
|
||||
return self.away_hide and self.state != STATE_HOME
|
||||
|
||||
async def async_seen(
|
||||
self,
|
||||
host_name: str = None,
|
||||
|
@ -524,7 +513,6 @@ async def async_load_config(
|
|||
vol.Optional(CONF_MAC, default=None): vol.Any(
|
||||
None, vol.All(cv.string, vol.Upper)
|
||||
),
|
||||
vol.Optional(CONF_AWAY_HIDE, default=DEFAULT_AWAY_HIDE): cv.boolean,
|
||||
vol.Optional("gravatar", default=None): vol.Any(None, cv.string),
|
||||
vol.Optional("picture", default=None): vol.Any(None, cv.string),
|
||||
vol.Optional(CONF_CONSIDER_HOME, default=consider_home): vol.All(
|
||||
|
@ -544,6 +532,7 @@ async def async_load_config(
|
|||
for dev_id, device in devices.items():
|
||||
# Deprecated option. We just ignore it to avoid breaking change
|
||||
device.pop("vendor", None)
|
||||
device.pop("hide_if_away", None)
|
||||
try:
|
||||
device = dev_schema(device)
|
||||
device["dev_id"] = cv.slugify(dev_id)
|
||||
|
@ -564,7 +553,6 @@ def update_config(path: str, dev_id: str, device: Device):
|
|||
ATTR_ICON: device.icon,
|
||||
"picture": device.config_picture,
|
||||
"track": device.track,
|
||||
CONF_AWAY_HIDE: device.away_hide,
|
||||
}
|
||||
}
|
||||
out.write("\n")
|
||||
|
|
|
@ -34,7 +34,6 @@ def scanner(hass):
|
|||
"homeassistant.components.device_tracker.legacy.load_yaml_config_file",
|
||||
return_value={
|
||||
"device_1": {
|
||||
"hide_if_away": False,
|
||||
"mac": "DEV1",
|
||||
"name": "Unnamed Device",
|
||||
"picture": "http://example.com/dev1.jpg",
|
||||
|
@ -42,7 +41,6 @@ def scanner(hass):
|
|||
"vendor": None,
|
||||
},
|
||||
"device_2": {
|
||||
"hide_if_away": False,
|
||||
"mac": "DEV2",
|
||||
"name": "Unnamed Device",
|
||||
"picture": "http://example.com/dev2.jpg",
|
||||
|
|
|
@ -15,7 +15,6 @@ from homeassistant.const import (
|
|||
ATTR_ENTITY_PICTURE,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_GPS_ACCURACY,
|
||||
ATTR_HIDDEN,
|
||||
ATTR_ICON,
|
||||
ATTR_LATITUDE,
|
||||
ATTR_LONGITUDE,
|
||||
|
@ -107,7 +106,6 @@ async def test_reading_yaml_config(hass, yaml_devices):
|
|||
"AB:CD:EF:GH:IJ",
|
||||
"Test name",
|
||||
picture="http://test.picture",
|
||||
hide_if_away=True,
|
||||
icon="mdi:kettle",
|
||||
)
|
||||
await hass.async_add_executor_job(
|
||||
|
@ -121,7 +119,6 @@ async def test_reading_yaml_config(hass, yaml_devices):
|
|||
assert device.track == config.track
|
||||
assert device.mac == config.mac
|
||||
assert device.config_picture == config.config_picture
|
||||
assert device.away_hide == config.away_hide
|
||||
assert device.consider_home == config.consider_home
|
||||
assert device.icon == config.icon
|
||||
|
||||
|
@ -284,7 +281,6 @@ async def test_entity_attributes(hass, mock_device_tracker_conf):
|
|||
None,
|
||||
friendly_name,
|
||||
picture,
|
||||
hide_if_away=True,
|
||||
icon=icon,
|
||||
)
|
||||
devices.append(device)
|
||||
|
@ -299,25 +295,6 @@ async def test_entity_attributes(hass, mock_device_tracker_conf):
|
|||
assert picture == attrs.get(ATTR_ENTITY_PICTURE)
|
||||
|
||||
|
||||
async def test_device_hidden(hass, mock_device_tracker_conf):
|
||||
"""Test hidden devices."""
|
||||
devices = mock_device_tracker_conf
|
||||
dev_id = "test_entity"
|
||||
entity_id = f"{const.DOMAIN}.{dev_id}"
|
||||
device = legacy.Device(
|
||||
hass, timedelta(seconds=180), True, dev_id, None, hide_if_away=True
|
||||
)
|
||||
devices.append(device)
|
||||
|
||||
scanner = getattr(hass.components, "test.device_tracker").SCANNER
|
||||
scanner.reset()
|
||||
|
||||
with assert_setup_component(1, device_tracker.DOMAIN):
|
||||
assert await async_setup_component(hass, device_tracker.DOMAIN, TEST_PLATFORM)
|
||||
|
||||
assert hass.states.get(entity_id).attributes.get(ATTR_HIDDEN)
|
||||
|
||||
|
||||
@patch("homeassistant.components.device_tracker.legacy." "DeviceTracker.async_see")
|
||||
async def test_see_service(mock_see, hass):
|
||||
"""Test the see service with a unicode dev_id and NO MAC."""
|
||||
|
@ -609,17 +586,6 @@ async def test_picture_and_icon_on_see_discovery(mock_device_tracker_conf, hass)
|
|||
assert mock_device_tracker_conf[0].entity_picture == "pic_url"
|
||||
|
||||
|
||||
async def test_default_hide_if_away_is_used(mock_device_tracker_conf, hass):
|
||||
"""Test that default track_new is used."""
|
||||
tracker = legacy.DeviceTracker(
|
||||
hass, timedelta(seconds=60), False, {device_tracker.CONF_AWAY_HIDE: True}, []
|
||||
)
|
||||
await tracker.async_see(dev_id=12)
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_device_tracker_conf) == 1
|
||||
assert mock_device_tracker_conf[0].away_hide
|
||||
|
||||
|
||||
async def test_backward_compatibility_for_track_new(mock_device_tracker_conf, hass):
|
||||
"""Test backward compatibility for track new."""
|
||||
tracker = legacy.DeviceTracker(
|
||||
|
|
|
@ -7,7 +7,6 @@ import pytest
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.device_tracker import (
|
||||
CONF_AWAY_HIDE,
|
||||
CONF_CONSIDER_HOME,
|
||||
CONF_NEW_DEVICE_DEFAULTS,
|
||||
CONF_TRACK_NEW,
|
||||
|
@ -49,7 +48,7 @@ async def test_get_scanner(unifi_mock, hass):
|
|||
CONF_PASSWORD: "fake_pass",
|
||||
CONF_TRACK_NEW: True,
|
||||
CONF_CONSIDER_HOME: timedelta(seconds=180),
|
||||
CONF_NEW_DEVICE_DEFAULTS: {CONF_TRACK_NEW: True, CONF_AWAY_HIDE: False},
|
||||
CONF_NEW_DEVICE_DEFAULTS: {CONF_TRACK_NEW: True},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue