Add Fast.com Device Info (#105528)
Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
parent
6908497c3d
commit
9d44dc4437
3 changed files with 18 additions and 4 deletions
|
@ -9,6 +9,7 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import UnitOfDataRate
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
|
@ -31,12 +32,13 @@ class SpeedtestSensor(
|
|||
):
|
||||
"""Implementation of a Fast.com sensor."""
|
||||
|
||||
_attr_name = "Fast.com Download"
|
||||
_attr_translation_key = "download"
|
||||
_attr_device_class = SensorDeviceClass.DATA_RATE
|
||||
_attr_native_unit_of_measurement = UnitOfDataRate.MEGABITS_PER_SECOND
|
||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||
_attr_icon = "mdi:speedometer"
|
||||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self, entry_id: str, coordinator: FastdotcomDataUpdateCoordindator
|
||||
|
@ -44,6 +46,11 @@ class SpeedtestSensor(
|
|||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_unique_id = entry_id
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, entry_id)},
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
configuration_url="https://www.fast.com",
|
||||
)
|
||||
|
||||
@property
|
||||
def native_value(
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"download": {
|
||||
"name": "Download"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"speedtest": {
|
||||
"name": "Speed test",
|
||||
|
|
|
@ -28,7 +28,7 @@ async def test_fastdotcom_data_update_coordinator(
|
|||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.fast_com_download")
|
||||
state = hass.states.get("sensor.mock_title_download")
|
||||
assert state is not None
|
||||
assert state.state == "5.0"
|
||||
|
||||
|
@ -39,7 +39,7 @@ async def test_fastdotcom_data_update_coordinator(
|
|||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.fast_com_download")
|
||||
state = hass.states.get("sensor.mock_title_download")
|
||||
assert state.state == "10.0"
|
||||
|
||||
with patch(
|
||||
|
@ -50,5 +50,5 @@ async def test_fastdotcom_data_update_coordinator(
|
|||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.fast_com_download")
|
||||
state = hass.states.get("sensor.mock_title_download")
|
||||
assert state.state is STATE_UNAVAILABLE
|
||||
|
|
Loading…
Add table
Reference in a new issue