Bump pyaussiebb in Aussie Broadband (#65754)
Co-authored-by: Shay Levy <levyshay1@gmail.com>pull/64892/head
parent
b211a1faa7
commit
6b6f50e28b
|
@ -5,14 +5,15 @@ from datetime import timedelta
|
|||
import logging
|
||||
|
||||
from aiohttp import ClientError
|
||||
from aussiebb.asyncio import AussieBB, AuthenticationException
|
||||
from aussiebb.asyncio import AussieBB
|
||||
from aussiebb.exceptions import AuthenticationException, UnrecognisedServiceType
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import CONF_SERVICES, DEFAULT_UPDATE_INTERVAL, DOMAIN, SERVICE_ID
|
||||
|
||||
|
@ -44,7 +45,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
# Create an appropriate refresh function
|
||||
def update_data_factory(service_id):
|
||||
async def async_update_data():
|
||||
return await client.get_usage(service_id)
|
||||
try:
|
||||
return await client.get_usage(service_id)
|
||||
except UnrecognisedServiceType as err:
|
||||
raise UpdateFailed(
|
||||
f"Service {service_id} of type '{services[service_id]['type']}' was unrecognised"
|
||||
) from err
|
||||
|
||||
return async_update_data
|
||||
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/aussie_broadband",
|
||||
"requirements": [
|
||||
"pyaussiebb==0.0.9"
|
||||
"pyaussiebb==0.0.11"
|
||||
],
|
||||
"codeowners": [
|
||||
"@nickw444",
|
||||
"@Bre77"
|
||||
],
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["aussiebb"]
|
||||
"loggers": [
|
||||
"aussiebb"
|
||||
]
|
||||
}
|
|
@ -143,7 +143,7 @@ class AussieBroadandSensorEntity(CoordinatorEntity, SensorEntity):
|
|||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if self.entity_description.key == "internet":
|
||||
return self.coordinator.data[self.entity_description.key]["kbytes"]
|
||||
return self.coordinator.data[self.entity_description.key].get("kbytes")
|
||||
if self.entity_description.key in ("national", "mobile", "sms"):
|
||||
return self.coordinator.data[self.entity_description.key]["calls"]
|
||||
return self.coordinator.data[self.entity_description.key].get("calls")
|
||||
return self.coordinator.data[self.entity_description.key]
|
||||
|
|
|
@ -1407,7 +1407,7 @@ pyatome==0.1.1
|
|||
pyatv==0.10.0
|
||||
|
||||
# homeassistant.components.aussie_broadband
|
||||
pyaussiebb==0.0.9
|
||||
pyaussiebb==0.0.11
|
||||
|
||||
# homeassistant.components.balboa
|
||||
pybalboa==0.13
|
||||
|
|
|
@ -887,7 +887,7 @@ pyatmo==6.2.4
|
|||
pyatv==0.10.0
|
||||
|
||||
# homeassistant.components.aussie_broadband
|
||||
pyaussiebb==0.0.9
|
||||
pyaussiebb==0.0.11
|
||||
|
||||
# homeassistant.components.balboa
|
||||
pybalboa==0.13
|
||||
|
|
|
@ -5,7 +5,7 @@ from homeassistant.components.aussie_broadband.const import (
|
|||
CONF_SERVICES,
|
||||
DOMAIN as AUSSIE_BROADBAND_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -22,6 +22,12 @@ FAKE_SERVICES = [
|
|||
"type": "PhoneMobile",
|
||||
"name": "Mobile",
|
||||
},
|
||||
{
|
||||
"service_id": "23456789",
|
||||
"description": "Fake ABB VOIP Service",
|
||||
"type": "VOIP",
|
||||
"name": "VOIP",
|
||||
},
|
||||
]
|
||||
|
||||
FAKE_DATA = {
|
||||
|
@ -30,12 +36,16 @@ FAKE_DATA = {
|
|||
}
|
||||
|
||||
|
||||
async def setup_platform(hass, platforms=[], side_effect=None, usage={}):
|
||||
async def setup_platform(
|
||||
hass, platforms=[], side_effect=None, usage={}, usage_effect=None
|
||||
):
|
||||
"""Set up the Aussie Broadband platform."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=AUSSIE_BROADBAND_DOMAIN,
|
||||
data=FAKE_DATA,
|
||||
options={CONF_SERVICES: ["12345678", "87654321"], CONF_SCAN_INTERVAL: 30},
|
||||
options={
|
||||
CONF_SERVICES: ["12345678", "87654321", "23456789", "98765432"],
|
||||
},
|
||||
)
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
|
@ -50,7 +60,9 @@ async def setup_platform(hass, platforms=[], side_effect=None, usage={}):
|
|||
return_value=FAKE_SERVICES,
|
||||
side_effect=side_effect,
|
||||
), patch(
|
||||
"aussiebb.asyncio.AussieBB.get_usage", return_value=usage
|
||||
"aussiebb.asyncio.AussieBB.get_usage",
|
||||
return_value=usage,
|
||||
side_effect=usage_effect,
|
||||
):
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
from aiohttp import ClientConnectionError
|
||||
from aussiebb.asyncio import AuthenticationException
|
||||
from aussiebb.exceptions import AuthenticationException, UnrecognisedServiceType
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
|
@ -33,3 +33,9 @@ async def test_net_failure(hass: HomeAssistant) -> None:
|
|||
"""Test init with a network failure."""
|
||||
entry = await setup_platform(hass, side_effect=ClientConnectionError())
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_service_failure(hass: HomeAssistant) -> None:
|
||||
"""Test init with a invalid service."""
|
||||
entry = await setup_platform(hass, usage_effect=UnrecognisedServiceType())
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Aussie Broadband sensor platform tests."""
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import STATE_UNKNOWN
|
||||
|
||||
from .common import setup_platform
|
||||
|
||||
|
@ -24,6 +25,19 @@ MOCK_MOBILE_USAGE = {
|
|||
"historical": [],
|
||||
}
|
||||
|
||||
MOCK_VOIP_USAGE = {
|
||||
"national": {"calls": 1, "cost": 0},
|
||||
"mobile": {"calls": 2, "cost": 0},
|
||||
"international": {"calls": 3, "cost": 0},
|
||||
"sms": {},
|
||||
"internet": {},
|
||||
"voicemail": {"calls": 6, "cost": 0},
|
||||
"other": {"calls": 7, "cost": 0},
|
||||
"daysTotal": 31,
|
||||
"daysRemaining": 30,
|
||||
"historical": [],
|
||||
}
|
||||
|
||||
|
||||
async def test_nbn_sensor_states(hass):
|
||||
"""Tests that the sensors are correct."""
|
||||
|
@ -48,3 +62,13 @@ async def test_phone_sensor_states(hass):
|
|||
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"
|
||||
|
||||
|
||||
async def test_voip_sensor_states(hass):
|
||||
"""Tests that the sensors are correct."""
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue