46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
|
"""Tests for the Freebox sensors."""
|
||
|
from copy import deepcopy
|
||
|
from unittest.mock import Mock
|
||
|
|
||
|
from freezegun.api import FrozenDateTimeFactory
|
||
|
|
||
|
from homeassistant.components.freebox import SCAN_INTERVAL
|
||
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||
|
from homeassistant.core import HomeAssistant
|
||
|
|
||
|
from .common import setup_platform
|
||
|
from .const import DATA_STORAGE_GET_DISKS
|
||
|
|
||
|
from tests.common import async_fire_time_changed
|
||
|
|
||
|
|
||
|
async def test_disk(
|
||
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory, router: Mock
|
||
|
) -> None:
|
||
|
"""Test disk sensor."""
|
||
|
await setup_platform(hass, SENSOR_DOMAIN)
|
||
|
|
||
|
# Initial state
|
||
|
assert (
|
||
|
router().storage.get_disks.return_value[2]["partitions"][0]["total_bytes"]
|
||
|
== 1960000000000
|
||
|
)
|
||
|
|
||
|
assert (
|
||
|
router().storage.get_disks.return_value[2]["partitions"][0]["free_bytes"]
|
||
|
== 1730000000000
|
||
|
)
|
||
|
|
||
|
assert hass.states.get("sensor.freebox_free_space").state == "88.27"
|
||
|
|
||
|
# Simulate a changed storage size
|
||
|
data_storage_get_disks_changed = deepcopy(DATA_STORAGE_GET_DISKS)
|
||
|
data_storage_get_disks_changed[2]["partitions"][0]["free_bytes"] = 880000000000
|
||
|
router().storage.get_disks.return_value = data_storage_get_disks_changed
|
||
|
# Simulate an update
|
||
|
freezer.tick(SCAN_INTERVAL)
|
||
|
async_fire_time_changed(hass)
|
||
|
# To execute the save
|
||
|
await hass.async_block_till_done()
|
||
|
assert hass.states.get("sensor.freebox_free_space").state == "44.9"
|