mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Migrate Aussie Broadband to new entity naming style (#74937)
This commit is contained in:
parent
7a729aed54
commit
d0f71d2e53
@ -33,7 +33,7 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
|
||||
# Internet Services sensors
|
||||
SensorValueEntityDescription(
|
||||
key="usedMb",
|
||||
name="Data Used",
|
||||
name="Data used",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
native_unit_of_measurement=DATA_MEGABYTES,
|
||||
icon="mdi:network",
|
||||
@ -55,35 +55,35 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
|
||||
# Mobile Phone Services sensors
|
||||
SensorValueEntityDescription(
|
||||
key="national",
|
||||
name="National Calls",
|
||||
name="National calls",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
icon="mdi:phone",
|
||||
value=lambda x: x.get("calls"),
|
||||
),
|
||||
SensorValueEntityDescription(
|
||||
key="mobile",
|
||||
name="Mobile Calls",
|
||||
name="Mobile calls",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
icon="mdi:phone",
|
||||
value=lambda x: x.get("calls"),
|
||||
),
|
||||
SensorValueEntityDescription(
|
||||
key="international",
|
||||
name="International Calls",
|
||||
name="International calls",
|
||||
entity_registry_enabled_default=False,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
icon="mdi:phone-plus",
|
||||
),
|
||||
SensorValueEntityDescription(
|
||||
key="sms",
|
||||
name="SMS Sent",
|
||||
name="SMS sent",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
icon="mdi:message-processing",
|
||||
value=lambda x: x.get("calls"),
|
||||
),
|
||||
SensorValueEntityDescription(
|
||||
key="internet",
|
||||
name="Data Used",
|
||||
name="Data used",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
native_unit_of_measurement=DATA_KILOBYTES,
|
||||
icon="mdi:network",
|
||||
@ -91,14 +91,14 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
|
||||
),
|
||||
SensorValueEntityDescription(
|
||||
key="voicemail",
|
||||
name="Voicemail Calls",
|
||||
name="Voicemail calls",
|
||||
entity_registry_enabled_default=False,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
icon="mdi:phone",
|
||||
),
|
||||
SensorValueEntityDescription(
|
||||
key="other",
|
||||
name="Other Calls",
|
||||
name="Other calls",
|
||||
entity_registry_enabled_default=False,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
icon="mdi:phone",
|
||||
@ -106,13 +106,13 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
|
||||
# Generic sensors
|
||||
SensorValueEntityDescription(
|
||||
key="daysTotal",
|
||||
name="Billing Cycle Length",
|
||||
name="Billing cycle length",
|
||||
native_unit_of_measurement=TIME_DAYS,
|
||||
icon="mdi:calendar-range",
|
||||
),
|
||||
SensorValueEntityDescription(
|
||||
key="daysRemaining",
|
||||
name="Billing Cycle Remaining",
|
||||
name="Billing cycle remaining",
|
||||
native_unit_of_measurement=TIME_DAYS,
|
||||
icon="mdi:calendar-clock",
|
||||
),
|
||||
@ -137,6 +137,7 @@ async def async_setup_entry(
|
||||
class AussieBroadandSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
"""Base class for Aussie Broadband metric sensors."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
entity_description: SensorValueEntityDescription
|
||||
|
||||
def __init__(
|
||||
@ -146,7 +147,6 @@ class AussieBroadandSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
super().__init__(service["coordinator"])
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{service[SERVICE_ID]}:{description.key}"
|
||||
self._attr_name = f"{service['name']} {description.name}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN, service[SERVICE_ID])},
|
||||
|
@ -44,11 +44,17 @@ async def test_nbn_sensor_states(hass):
|
||||
|
||||
await setup_platform(hass, [SENSOR_DOMAIN], usage=MOCK_NBN_USAGE)
|
||||
|
||||
assert hass.states.get("sensor.nbn_data_used").state == "54321"
|
||||
assert hass.states.get("sensor.nbn_downloaded").state == "50000"
|
||||
assert hass.states.get("sensor.nbn_uploaded").state == "4321"
|
||||
assert hass.states.get("sensor.nbn_billing_cycle_length").state == "28"
|
||||
assert hass.states.get("sensor.nbn_billing_cycle_remaining").state == "25"
|
||||
assert hass.states.get("sensor.fake_abb_nbn_service_data_used").state == "54321"
|
||||
assert hass.states.get("sensor.fake_abb_nbn_service_downloaded").state == "50000"
|
||||
assert hass.states.get("sensor.fake_abb_nbn_service_uploaded").state == "4321"
|
||||
assert (
|
||||
hass.states.get("sensor.fake_abb_nbn_service_billing_cycle_length").state
|
||||
== "28"
|
||||
)
|
||||
assert (
|
||||
hass.states.get("sensor.fake_abb_nbn_service_billing_cycle_remaining").state
|
||||
== "25"
|
||||
)
|
||||
|
||||
|
||||
async def test_phone_sensor_states(hass):
|
||||
@ -56,12 +62,18 @@ async def test_phone_sensor_states(hass):
|
||||
|
||||
await setup_platform(hass, [SENSOR_DOMAIN], usage=MOCK_MOBILE_USAGE)
|
||||
|
||||
assert hass.states.get("sensor.mobile_national_calls").state == "1"
|
||||
assert hass.states.get("sensor.mobile_mobile_calls").state == "2"
|
||||
assert hass.states.get("sensor.mobile_sms_sent").state == "4"
|
||||
assert hass.states.get("sensor.mobile_data_used").state == "512"
|
||||
assert hass.states.get("sensor.mobile_billing_cycle_length").state == "31"
|
||||
assert hass.states.get("sensor.mobile_billing_cycle_remaining").state == "30"
|
||||
assert hass.states.get("sensor.fake_abb_mobile_service_national_calls").state == "1"
|
||||
assert hass.states.get("sensor.fake_abb_mobile_service_mobile_calls").state == "2"
|
||||
assert hass.states.get("sensor.fake_abb_mobile_service_sms_sent").state == "4"
|
||||
assert hass.states.get("sensor.fake_abb_mobile_service_data_used").state == "512"
|
||||
assert (
|
||||
hass.states.get("sensor.fake_abb_mobile_service_billing_cycle_length").state
|
||||
== "31"
|
||||
)
|
||||
assert (
|
||||
hass.states.get("sensor.fake_abb_mobile_service_billing_cycle_remaining").state
|
||||
== "30"
|
||||
)
|
||||
|
||||
|
||||
async def test_voip_sensor_states(hass):
|
||||
@ -69,6 +81,10 @@ async def test_voip_sensor_states(hass):
|
||||
|
||||
await setup_platform(hass, [SENSOR_DOMAIN], usage=MOCK_VOIP_USAGE)
|
||||
|
||||
assert hass.states.get("sensor.mobile_national_calls").state == "1"
|
||||
assert hass.states.get("sensor.mobile_sms_sent").state == STATE_UNKNOWN
|
||||
assert hass.states.get("sensor.mobile_data_used").state == STATE_UNKNOWN
|
||||
assert hass.states.get("sensor.fake_abb_voip_service_national_calls").state == "1"
|
||||
assert (
|
||||
hass.states.get("sensor.fake_abb_voip_service_sms_sent").state == STATE_UNKNOWN
|
||||
)
|
||||
assert (
|
||||
hass.states.get("sensor.fake_abb_voip_service_data_used").state == STATE_UNKNOWN
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user