mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add device_tracker.see service
This commit is contained in:
parent
804b7669b7
commit
880b5f0ad1
@ -60,8 +60,15 @@ DEFAULT_SCAN_INTERVAL = 12
|
|||||||
CONF_AWAY_HIDE = 'hide_if_away'
|
CONF_AWAY_HIDE = 'hide_if_away'
|
||||||
DEFAULT_AWAY_HIDE = False
|
DEFAULT_AWAY_HIDE = False
|
||||||
|
|
||||||
|
SERVICE_SEE = 'see'
|
||||||
|
|
||||||
ATTR_LATITUDE = 'latitude'
|
ATTR_LATITUDE = 'latitude'
|
||||||
ATTR_LONGITUDE = 'longitude'
|
ATTR_LONGITUDE = 'longitude'
|
||||||
|
ATTR_MAC = 'mac'
|
||||||
|
ATTR_DEV_ID = 'dev_id'
|
||||||
|
ATTR_HOST_NAME = 'host_name'
|
||||||
|
ATTR_LOCATION_NAME = 'location_name'
|
||||||
|
ATTR_GPS = 'gps'
|
||||||
|
|
||||||
DISCOVERY_PLATFORMS = {
|
DISCOVERY_PLATFORMS = {
|
||||||
discovery.SERVICE_NETGEAR: 'netgear',
|
discovery.SERVICE_NETGEAR: 'netgear',
|
||||||
@ -76,6 +83,16 @@ def is_on(hass, entity_id=None):
|
|||||||
return hass.states.is_state(entity, STATE_HOME)
|
return hass.states.is_state(entity, STATE_HOME)
|
||||||
|
|
||||||
|
|
||||||
|
def see(hass, mac=None, dev_id=None, host_name=None, location_name=None,
|
||||||
|
gps=None):
|
||||||
|
""" Call service to notify you see device. """
|
||||||
|
data = {key: value for key, value in (
|
||||||
|
(ATTR_MAC, mac), (ATTR_DEV_ID, dev_id),
|
||||||
|
(ATTR_HOST_NAME, host_name), (ATTR_LOCATION_NAME, location_name),
|
||||||
|
(ATTR_GPS, gps)) if value is not None}
|
||||||
|
hass.services.call(DOMAIN, SERVICE_SEE, data)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Setup device tracker """
|
""" Setup device tracker """
|
||||||
yaml_path = hass.config.path(YAML_DEVICES)
|
yaml_path = hass.config.path(YAML_DEVICES)
|
||||||
@ -133,6 +150,15 @@ def setup(hass, config):
|
|||||||
|
|
||||||
tracker.setup_group()
|
tracker.setup_group()
|
||||||
|
|
||||||
|
def see_service(call):
|
||||||
|
""" Service to see a device. """
|
||||||
|
args = {key: value for key, value in call.data.items() if key in (
|
||||||
|
ATTR_MAC, ATTR_DEV_ID, ATTR_HOST_NAME, ATTR_LOCATION_NAME,
|
||||||
|
ATTR_GPS)}
|
||||||
|
tracker.see(**args)
|
||||||
|
|
||||||
|
hass.services.register(DOMAIN, SERVICE_SEE, see_service)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,3 +213,21 @@ class TestComponentsDeviceTracker(unittest.TestCase):
|
|||||||
self.assertEqual(STATE_NOT_HOME, state.state)
|
self.assertEqual(STATE_NOT_HOME, state.state)
|
||||||
self.assertSequenceEqual((entity_id,),
|
self.assertSequenceEqual((entity_id,),
|
||||||
state.attributes.get(ATTR_ENTITY_ID))
|
state.attributes.get(ATTR_ENTITY_ID))
|
||||||
|
|
||||||
|
@patch('homeassistant.components.device_tracker.DeviceTracker.see')
|
||||||
|
def test_see_service(self, mock_see):
|
||||||
|
self.assertTrue(device_tracker.setup(self.hass, {}))
|
||||||
|
mac = 'AB:CD:EF:GH'
|
||||||
|
dev_id = 'some_device'
|
||||||
|
host_name = 'example.com'
|
||||||
|
location_name = 'Work'
|
||||||
|
gps = [.3, .8]
|
||||||
|
|
||||||
|
device_tracker.see(self.hass, mac, dev_id, host_name, location_name,
|
||||||
|
gps)
|
||||||
|
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
|
||||||
|
mock_see.assert_called_once_with(
|
||||||
|
mac=mac, dev_id=dev_id, host_name=host_name,
|
||||||
|
location_name=location_name, gps=gps)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user