mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Add Fast.com Device Info (#105528)
Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
parent
6908497c3d
commit
9d44dc4437
@ -9,6 +9,7 @@ from homeassistant.components.sensor import (
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import UnitOfDataRate
|
from homeassistant.const import UnitOfDataRate
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
@ -31,12 +32,13 @@ class SpeedtestSensor(
|
|||||||
):
|
):
|
||||||
"""Implementation of a Fast.com sensor."""
|
"""Implementation of a Fast.com sensor."""
|
||||||
|
|
||||||
_attr_name = "Fast.com Download"
|
_attr_translation_key = "download"
|
||||||
_attr_device_class = SensorDeviceClass.DATA_RATE
|
_attr_device_class = SensorDeviceClass.DATA_RATE
|
||||||
_attr_native_unit_of_measurement = UnitOfDataRate.MEGABITS_PER_SECOND
|
_attr_native_unit_of_measurement = UnitOfDataRate.MEGABITS_PER_SECOND
|
||||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||||
_attr_icon = "mdi:speedometer"
|
_attr_icon = "mdi:speedometer"
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, entry_id: str, coordinator: FastdotcomDataUpdateCoordindator
|
self, entry_id: str, coordinator: FastdotcomDataUpdateCoordindator
|
||||||
@ -44,6 +46,11 @@ class SpeedtestSensor(
|
|||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._attr_unique_id = entry_id
|
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
|
@property
|
||||||
def native_value(
|
def native_value(
|
||||||
|
@ -9,6 +9,13 @@
|
|||||||
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"download": {
|
||||||
|
"name": "Download"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"speedtest": {
|
"speedtest": {
|
||||||
"name": "Speed test",
|
"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.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
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 is not None
|
||||||
assert state.state == "5.0"
|
assert state.state == "5.0"
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ async def test_fastdotcom_data_update_coordinator(
|
|||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
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"
|
assert state.state == "10.0"
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -50,5 +50,5 @@ async def test_fastdotcom_data_update_coordinator(
|
|||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
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
|
assert state.state is STATE_UNAVAILABLE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user