mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +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
|
# Internet Services sensors
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="usedMb",
|
key="usedMb",
|
||||||
name="Data Used",
|
name="Data used",
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:network",
|
icon="mdi:network",
|
||||||
@ -55,35 +55,35 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
|
|||||||
# Mobile Phone Services sensors
|
# Mobile Phone Services sensors
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="national",
|
key="national",
|
||||||
name="National Calls",
|
name="National calls",
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
icon="mdi:phone",
|
icon="mdi:phone",
|
||||||
value=lambda x: x.get("calls"),
|
value=lambda x: x.get("calls"),
|
||||||
),
|
),
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="mobile",
|
key="mobile",
|
||||||
name="Mobile Calls",
|
name="Mobile calls",
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
icon="mdi:phone",
|
icon="mdi:phone",
|
||||||
value=lambda x: x.get("calls"),
|
value=lambda x: x.get("calls"),
|
||||||
),
|
),
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="international",
|
key="international",
|
||||||
name="International Calls",
|
name="International calls",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
icon="mdi:phone-plus",
|
icon="mdi:phone-plus",
|
||||||
),
|
),
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="sms",
|
key="sms",
|
||||||
name="SMS Sent",
|
name="SMS sent",
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
icon="mdi:message-processing",
|
icon="mdi:message-processing",
|
||||||
value=lambda x: x.get("calls"),
|
value=lambda x: x.get("calls"),
|
||||||
),
|
),
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="internet",
|
key="internet",
|
||||||
name="Data Used",
|
name="Data used",
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
native_unit_of_measurement=DATA_KILOBYTES,
|
native_unit_of_measurement=DATA_KILOBYTES,
|
||||||
icon="mdi:network",
|
icon="mdi:network",
|
||||||
@ -91,14 +91,14 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="voicemail",
|
key="voicemail",
|
||||||
name="Voicemail Calls",
|
name="Voicemail calls",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
icon="mdi:phone",
|
icon="mdi:phone",
|
||||||
),
|
),
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="other",
|
key="other",
|
||||||
name="Other Calls",
|
name="Other calls",
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
icon="mdi:phone",
|
icon="mdi:phone",
|
||||||
@ -106,13 +106,13 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
|
|||||||
# Generic sensors
|
# Generic sensors
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="daysTotal",
|
key="daysTotal",
|
||||||
name="Billing Cycle Length",
|
name="Billing cycle length",
|
||||||
native_unit_of_measurement=TIME_DAYS,
|
native_unit_of_measurement=TIME_DAYS,
|
||||||
icon="mdi:calendar-range",
|
icon="mdi:calendar-range",
|
||||||
),
|
),
|
||||||
SensorValueEntityDescription(
|
SensorValueEntityDescription(
|
||||||
key="daysRemaining",
|
key="daysRemaining",
|
||||||
name="Billing Cycle Remaining",
|
name="Billing cycle remaining",
|
||||||
native_unit_of_measurement=TIME_DAYS,
|
native_unit_of_measurement=TIME_DAYS,
|
||||||
icon="mdi:calendar-clock",
|
icon="mdi:calendar-clock",
|
||||||
),
|
),
|
||||||
@ -137,6 +137,7 @@ async def async_setup_entry(
|
|||||||
class AussieBroadandSensorEntity(CoordinatorEntity, SensorEntity):
|
class AussieBroadandSensorEntity(CoordinatorEntity, SensorEntity):
|
||||||
"""Base class for Aussie Broadband metric sensors."""
|
"""Base class for Aussie Broadband metric sensors."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
entity_description: SensorValueEntityDescription
|
entity_description: SensorValueEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -146,7 +147,6 @@ class AussieBroadandSensorEntity(CoordinatorEntity, SensorEntity):
|
|||||||
super().__init__(service["coordinator"])
|
super().__init__(service["coordinator"])
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{service[SERVICE_ID]}:{description.key}"
|
self._attr_unique_id = f"{service[SERVICE_ID]}:{description.key}"
|
||||||
self._attr_name = f"{service['name']} {description.name}"
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
identifiers={(DOMAIN, service[SERVICE_ID])},
|
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)
|
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.fake_abb_nbn_service_data_used").state == "54321"
|
||||||
assert hass.states.get("sensor.nbn_downloaded").state == "50000"
|
assert hass.states.get("sensor.fake_abb_nbn_service_downloaded").state == "50000"
|
||||||
assert hass.states.get("sensor.nbn_uploaded").state == "4321"
|
assert hass.states.get("sensor.fake_abb_nbn_service_uploaded").state == "4321"
|
||||||
assert hass.states.get("sensor.nbn_billing_cycle_length").state == "28"
|
assert (
|
||||||
assert hass.states.get("sensor.nbn_billing_cycle_remaining").state == "25"
|
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):
|
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)
|
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.fake_abb_mobile_service_national_calls").state == "1"
|
||||||
assert hass.states.get("sensor.mobile_mobile_calls").state == "2"
|
assert hass.states.get("sensor.fake_abb_mobile_service_mobile_calls").state == "2"
|
||||||
assert hass.states.get("sensor.mobile_sms_sent").state == "4"
|
assert hass.states.get("sensor.fake_abb_mobile_service_sms_sent").state == "4"
|
||||||
assert hass.states.get("sensor.mobile_data_used").state == "512"
|
assert hass.states.get("sensor.fake_abb_mobile_service_data_used").state == "512"
|
||||||
assert hass.states.get("sensor.mobile_billing_cycle_length").state == "31"
|
assert (
|
||||||
assert hass.states.get("sensor.mobile_billing_cycle_remaining").state == "30"
|
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):
|
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)
|
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.fake_abb_voip_service_national_calls").state == "1"
|
||||||
assert hass.states.get("sensor.mobile_sms_sent").state == STATE_UNKNOWN
|
assert (
|
||||||
assert hass.states.get("sensor.mobile_data_used").state == STATE_UNKNOWN
|
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