mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Set entity category and device class for Netgear LTE entities (#106661)
* Set entity category and device class for Netgear * add suggested unit of measure and precision
This commit is contained in:
parent
a4f0c84457
commit
7396bc61d7
@ -7,6 +7,7 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
@ -17,15 +18,19 @@ BINARY_SENSORS: tuple[BinarySensorEntityDescription, ...] = (
|
|||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
key="roaming",
|
key="roaming",
|
||||||
translation_key="roaming",
|
translation_key="roaming",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
key="wire_connected",
|
key="wire_connected",
|
||||||
translation_key="wire_connected",
|
translation_key="wire_connected",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||||
),
|
),
|
||||||
BinarySensorEntityDescription(
|
BinarySensorEntityDescription(
|
||||||
key="mobile_connected",
|
key="mobile_connected",
|
||||||
translation_key="mobile_connected",
|
translation_key="mobile_connected",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
|
EntityCategory,
|
||||||
UnitOfInformation,
|
UnitOfInformation,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -35,12 +36,14 @@ SENSORS: tuple[NetgearLTESensorEntityDescription, ...] = (
|
|||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="sms",
|
key="sms",
|
||||||
translation_key="sms",
|
translation_key="sms",
|
||||||
|
icon="mdi:message-processing",
|
||||||
native_unit_of_measurement="unread",
|
native_unit_of_measurement="unread",
|
||||||
value_fn=lambda modem_data: sum(1 for x in modem_data.data.sms if x.unread),
|
value_fn=lambda modem_data: sum(1 for x in modem_data.data.sms if x.unread),
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="sms_total",
|
key="sms_total",
|
||||||
translation_key="sms_total",
|
translation_key="sms_total",
|
||||||
|
icon="mdi:message-processing",
|
||||||
native_unit_of_measurement="messages",
|
native_unit_of_measurement="messages",
|
||||||
value_fn=lambda modem_data: len(modem_data.data.sms),
|
value_fn=lambda modem_data: len(modem_data.data.sms),
|
||||||
),
|
),
|
||||||
@ -48,39 +51,84 @@ SENSORS: tuple[NetgearLTESensorEntityDescription, ...] = (
|
|||||||
key="usage",
|
key="usage",
|
||||||
translation_key="usage",
|
translation_key="usage",
|
||||||
device_class=SensorDeviceClass.DATA_SIZE,
|
device_class=SensorDeviceClass.DATA_SIZE,
|
||||||
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
|
entity_registry_enabled_default=False,
|
||||||
value_fn=lambda modem_data: round(modem_data.data.usage / 1024**2, 1),
|
native_unit_of_measurement=UnitOfInformation.BYTES,
|
||||||
|
suggested_unit_of_measurement=UnitOfInformation.MEBIBYTES,
|
||||||
|
suggested_display_precision=1,
|
||||||
|
value_fn=lambda modem_data: modem_data.data.usage,
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="radio_quality",
|
key="radio_quality",
|
||||||
translation_key="radio_quality",
|
translation_key="radio_quality",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="rx_level",
|
key="rx_level",
|
||||||
translation_key="rx_level",
|
translation_key="rx_level",
|
||||||
|
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="tx_level",
|
key="tx_level",
|
||||||
translation_key="tx_level",
|
translation_key="tx_level",
|
||||||
|
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(key="upstream", translation_key="upstream"),
|
|
||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="connection_text", translation_key="connection_text"
|
key="upstream",
|
||||||
|
translation_key="upstream",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:ip-network",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="connection_type", translation_key="connection_type"
|
key="connection_text",
|
||||||
|
translation_key="connection_text",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:radio-tower",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="current_ps_service_type", translation_key="service_type"
|
key="connection_type",
|
||||||
|
translation_key="connection_type",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:ip",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(
|
NetgearLTESensorEntityDescription(
|
||||||
key="register_network_display", translation_key="register_network_display"
|
key="current_ps_service_type",
|
||||||
|
translation_key="service_type",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:radio-tower",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
NetgearLTESensorEntityDescription(
|
||||||
|
key="register_network_display",
|
||||||
|
translation_key="register_network_display",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:web",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
NetgearLTESensorEntityDescription(
|
||||||
|
key="current_band",
|
||||||
|
translation_key="band",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:radio-tower",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
NetgearLTESensorEntityDescription(
|
||||||
|
key="cell_id",
|
||||||
|
translation_key="cell_id",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
icon="mdi:radio-tower",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
NetgearLTESensorEntityDescription(key="current_band", translation_key="band"),
|
|
||||||
NetgearLTESensorEntityDescription(key="cell_id", translation_key="cell_id"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_binary_sensors[binary_sensor.netgear_lm1200_mobile_connected]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'connectivity',
|
||||||
|
'friendly_name': 'Netgear LM1200 Mobile connected',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'binary_sensor.netgear_lm1200_mobile_connected',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'on',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_binary_sensors[binary_sensor.netgear_lm1200_roaming]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Roaming',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'binary_sensor.netgear_lm1200_roaming',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'off',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_binary_sensors[binary_sensor.netgear_lm1200_wire_connected]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'connectivity',
|
||||||
|
'friendly_name': 'Netgear LM1200 Wire connected',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'binary_sensor.netgear_lm1200_wire_connected',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'off',
|
||||||
|
})
|
||||||
|
# ---
|
175
tests/components/netgear_lte/snapshots/test_sensor.ambr
Normal file
175
tests/components/netgear_lte/snapshots/test_sensor.ambr
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_cell_id]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Cell ID',
|
||||||
|
'icon': 'mdi:radio-tower',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_cell_id',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '12345678',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_connection_text]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Connection text',
|
||||||
|
'icon': 'mdi:radio-tower',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_connection_text',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '4G',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_connection_type]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Connection type',
|
||||||
|
'icon': 'mdi:ip',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_connection_type',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'IPv4AndIPv6',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_current_band]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Current band',
|
||||||
|
'icon': 'mdi:radio-tower',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_current_band',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'LTE B4',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_radio_quality]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Radio quality',
|
||||||
|
'unit_of_measurement': '%',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_radio_quality',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '52',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_register_network_display]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Register network display',
|
||||||
|
'icon': 'mdi:web',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_register_network_display',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'T-Mobile',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_rx_level]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'signal_strength',
|
||||||
|
'friendly_name': 'Netgear LM1200 Rx level',
|
||||||
|
'unit_of_measurement': 'dBm',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_rx_level',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '-113',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_service_type]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Service type',
|
||||||
|
'icon': 'mdi:radio-tower',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_service_type',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'LTE',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_sms]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 SMS',
|
||||||
|
'icon': 'mdi:message-processing',
|
||||||
|
'unit_of_measurement': 'unread',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_sms',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '1',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_sms_total]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 SMS total',
|
||||||
|
'icon': 'mdi:message-processing',
|
||||||
|
'unit_of_measurement': 'messages',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_sms_total',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '1',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_tx_level]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'signal_strength',
|
||||||
|
'friendly_name': 'Netgear LM1200 Tx level',
|
||||||
|
'unit_of_measurement': 'dBm',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_tx_level',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '4',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_upstream]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Netgear LM1200 Upstream',
|
||||||
|
'icon': 'mdi:ip-network',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_upstream',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'LTE',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_sensors[sensor.netgear_lm1200_usage]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'data_size',
|
||||||
|
'friendly_name': 'Netgear LM1200 Usage',
|
||||||
|
'unit_of_measurement': <UnitOfInformation.MEBIBYTES: 'MiB'>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'sensor.netgear_lm1200_usage',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': '40.5162000656128',
|
||||||
|
})
|
||||||
|
# ---
|
@ -1,19 +1,27 @@
|
|||||||
"""The tests for Netgear LTE binary sensor platform."""
|
"""The tests for Netgear LTE binary sensor platform."""
|
||||||
import pytest
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||||
from homeassistant.const import ATTR_DEVICE_CLASS, STATE_OFF, STATE_ON
|
from homeassistant.components.netgear_lte.const import DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("setup_integration", "entity_registry_enabled_by_default")
|
async def test_binary_sensors(
|
||||||
async def test_binary_sensors(hass: HomeAssistant) -> None:
|
hass: HomeAssistant,
|
||||||
|
entity_registry_enabled_by_default: None,
|
||||||
|
setup_integration: None,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
"""Test for successfully setting up the Netgear LTE binary sensor platform."""
|
"""Test for successfully setting up the Netgear LTE binary sensor platform."""
|
||||||
state = hass.states.get("binary_sensor.netgear_lm1200_mobile_connected")
|
entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
assert state.state == STATE_ON
|
entity_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
|
||||||
assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.CONNECTIVITY
|
|
||||||
state = hass.states.get("binary_sensor.netgear_lm1200_wire_connected")
|
assert entity_entries
|
||||||
assert state.state == STATE_OFF
|
for entity_entry in entity_entries:
|
||||||
assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.CONNECTIVITY
|
if entity_entry.domain != BINARY_SENSOR_DOMAIN:
|
||||||
state = hass.states.get("binary_sensor.netgear_lm1200_roaming")
|
continue
|
||||||
assert state.state == STATE_OFF
|
assert hass.states.get(entity_entry.entity_id) == snapshot(
|
||||||
|
name=entity_entry.entity_id
|
||||||
|
)
|
||||||
|
@ -1,56 +1,27 @@
|
|||||||
"""The tests for Netgear LTE sensor platform."""
|
"""The tests for Netgear LTE sensor platform."""
|
||||||
import pytest
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass
|
from homeassistant.components.netgear_lte.const import DOMAIN
|
||||||
from homeassistant.const import (
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
ATTR_DEVICE_CLASS,
|
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
|
||||||
PERCENTAGE,
|
|
||||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
|
||||||
UnitOfInformation,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("setup_integration", "entity_registry_enabled_by_default")
|
async def test_sensors(
|
||||||
async def test_sensors(hass: HomeAssistant) -> None:
|
hass: HomeAssistant,
|
||||||
|
entity_registry_enabled_by_default: None,
|
||||||
|
setup_integration: None,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
"""Test for successfully setting up the Netgear LTE sensor platform."""
|
"""Test for successfully setting up the Netgear LTE sensor platform."""
|
||||||
state = hass.states.get("sensor.netgear_lm1200_cell_id")
|
entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
assert state.state == "12345678"
|
entity_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
|
||||||
state = hass.states.get("sensor.netgear_lm1200_connection_text")
|
|
||||||
assert state.state == "4G"
|
assert entity_entries
|
||||||
state = hass.states.get("sensor.netgear_lm1200_connection_type")
|
for entity_entry in entity_entries:
|
||||||
assert state.state == "IPv4AndIPv6"
|
if entity_entry.domain != SENSOR_DOMAIN:
|
||||||
state = hass.states.get("sensor.netgear_lm1200_current_band")
|
continue
|
||||||
assert state.state == "LTE B4"
|
assert hass.states.get(entity_entry.entity_id) == snapshot(
|
||||||
state = hass.states.get("sensor.netgear_lm1200_service_type")
|
name=entity_entry.entity_id
|
||||||
assert state.state == "LTE"
|
)
|
||||||
state = hass.states.get("sensor.netgear_lm1200_radio_quality")
|
|
||||||
assert state.state == "52"
|
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
|
||||||
state = hass.states.get("sensor.netgear_lm1200_register_network_display")
|
|
||||||
assert state.state == "T-Mobile"
|
|
||||||
state = hass.states.get("sensor.netgear_lm1200_rx_level")
|
|
||||||
assert state.state == "-113"
|
|
||||||
assert (
|
|
||||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
|
||||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
|
||||||
)
|
|
||||||
state = hass.states.get("sensor.netgear_lm1200_sms")
|
|
||||||
assert state.state == "1"
|
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "unread"
|
|
||||||
state = hass.states.get("sensor.netgear_lm1200_sms_total")
|
|
||||||
assert state.state == "1"
|
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "messages"
|
|
||||||
state = hass.states.get("sensor.netgear_lm1200_tx_level")
|
|
||||||
assert state.state == "4"
|
|
||||||
assert (
|
|
||||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
|
||||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
|
||||||
)
|
|
||||||
state = hass.states.get("sensor.netgear_lm1200_upstream")
|
|
||||||
assert state.state == "LTE"
|
|
||||||
state = hass.states.get("sensor.netgear_lm1200_usage")
|
|
||||||
assert state.state == "40.5"
|
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfInformation.MEBIBYTES
|
|
||||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.DATA_SIZE
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user