hass-core/tests/components/device_tracker/test_entities.py
David F. Mulcahey 3c487928d4 New scanner device tracker and ZHA device tracker support ()
* 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
2019-07-04 12:44:39 +02:00

62 lines
1.9 KiB
Python

"""Tests for device tracker entities."""
import pytest
from homeassistant.components.device_tracker.config_entry import (
BaseTrackerEntity, ScannerEntity
)
from homeassistant.components.device_tracker.const import (
SOURCE_TYPE_ROUTER, ATTR_SOURCE_TYPE, DOMAIN
)
from homeassistant.const import (
STATE_HOME,
STATE_NOT_HOME,
ATTR_BATTERY_LEVEL
)
from tests.common import MockConfigEntry
async def test_scanner_entity_device_tracker(hass):
"""Test ScannerEntity based device tracker."""
config_entry = MockConfigEntry(domain='test')
config_entry.add_to_hass(hass)
await hass.config_entries.async_forward_entry_setup(
config_entry, DOMAIN)
await hass.async_block_till_done()
entity_id = 'device_tracker.unnamed_device'
entity_state = hass.states.get(entity_id)
assert entity_state.attributes == {
ATTR_SOURCE_TYPE: SOURCE_TYPE_ROUTER,
ATTR_BATTERY_LEVEL: 100
}
assert entity_state.state == STATE_NOT_HOME
entity = hass.data[DOMAIN].get_entity(entity_id)
entity.set_connected()
await hass.async_block_till_done()
entity_state = hass.states.get(entity_id)
assert entity_state.state == STATE_HOME
def test_scanner_entity():
"""Test coverage for base ScannerEntity entity class."""
entity = ScannerEntity()
with pytest.raises(NotImplementedError):
assert entity.source_type is None
with pytest.raises(NotImplementedError):
assert entity.is_connected is None
with pytest.raises(NotImplementedError):
assert entity.state == STATE_NOT_HOME
assert entity.battery_level is None
def test_base_tracker_entity():
"""Test coverage for base BaseTrackerEntity entity class."""
entity = BaseTrackerEntity()
with pytest.raises(NotImplementedError):
assert entity.source_type is None
assert entity.battery_level is None
with pytest.raises(NotImplementedError):
assert entity.state_attributes is None