New scanner device tracker and ZHA device tracker support (#24584)
* initial implementation for zha device trackers * constant * review comments * Revert "review comments" This reverts commit 2130823566820dfc114dbeda08fcdf76ed47a4e7. * rename device tracker entity * update trackers * raise when not implemented * Update homeassistant/components/device_tracker/config_entry.py Review comment Co-Authored-By: Martin Hjelmare <marhje52@kth.se> * move source type to base state attrs * review comments * review comments * review comments * fix super call * fix battery and use last seen from device * add test * cleanup and add more to test * cleanup post zha entity removal PR * add tests for base entities * rework entity tests
This commit is contained in:
1 parent
e824c553ca
commit
3c487928d4
12 files changed
+359
-27
No files matched your search
@@ -1,6 +1,8 @@
|
||||
"""Provide a mock device scanner."""
|
||||
|
||||
from homeassistant.components.device_tracker import DeviceScanner
|
||||
from homeassistant.components.device_tracker.config_entry import ScannerEntity
|
||||
from homeassistant.components.device_tracker.const import SOURCE_TYPE_ROUTER
|
||||
|
||||
|
||||
def get_scanner(hass, config):
|
||||
@@ -8,6 +10,43 @@ def get_scanner(hass, config):
|
||||
return SCANNER
|
||||
|
||||
|
||||
class MockScannerEntity(ScannerEntity):
|
||||
"""Test implementation of a ScannerEntity."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init."""
|
||||
self.connected = False
|
||||
|
||||
@property
|
||||
def source_type(self):
|
||||
"""Return the source type, eg gps or router, of the device."""
|
||||
return SOURCE_TYPE_ROUTER
|
||||
|
||||
@property
|
||||
def battery_level(self):
|
||||
"""Return the battery level of the device.
|
||||
|
||||
Percentage from 0-100.
|
||||
"""
|
||||
return 100
|
||||
|
||||
@property
|
||||
def is_connected(self):
|
||||
"""Return true if the device is connected to the network."""
|
||||
return self.connected
|
||||
|
||||
def set_connected(self):
|
||||
"""Set connected to True."""
|
||||
self.connected = True
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the config entry."""
|
||||
entity = MockScannerEntity()
|
||||
async_add_entities([entity])
|
||||
|
||||
|
||||
class MockScanner(DeviceScanner):
|
||||
"""Mock device scanner."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user