mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Make iot time timezone aware (#1147)
Also makes on_since for iot devices use device time. Changes the return value for device.timezone to be tzinfo instead of a dict.
This commit is contained in:
@@ -10,10 +10,16 @@ from contextlib import AbstractContextManager
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
import zoneinfo
|
||||
|
||||
import kasa
|
||||
from kasa import Credentials, Device, DeviceConfig, DeviceType, KasaException, Module
|
||||
from kasa.iot import IotDevice
|
||||
from kasa.iot.iottimezone import (
|
||||
TIMEZONE_INDEX,
|
||||
get_timezone,
|
||||
get_timezone_index,
|
||||
)
|
||||
from kasa.iot.modules import IotLightPreset
|
||||
from kasa.smart import SmartChildDevice, SmartDevice
|
||||
|
||||
@@ -299,3 +305,29 @@ async def test_device_type_aliases():
|
||||
)
|
||||
assert isinstance(dev.config, DeviceConfig)
|
||||
assert DeviceType.Dimmer == Device.Type.Dimmer
|
||||
|
||||
|
||||
async def test_device_timezones():
|
||||
"""Test the timezone data is good."""
|
||||
# Check all indexes return a zoneinfo
|
||||
for i in range(110):
|
||||
tz = await get_timezone(i)
|
||||
assert tz
|
||||
assert tz != zoneinfo.ZoneInfo("Etc/UTC"), f"{i} is default Etc/UTC"
|
||||
|
||||
# Check an unexpected index returns a UTC default.
|
||||
tz = await get_timezone(110)
|
||||
assert tz == zoneinfo.ZoneInfo("Etc/UTC")
|
||||
|
||||
# Get an index from a timezone
|
||||
for index, zone in TIMEZONE_INDEX.items():
|
||||
found_index = await get_timezone_index(zone)
|
||||
assert found_index == index
|
||||
|
||||
# Try a timezone not hardcoded finds another match
|
||||
index = await get_timezone_index("Asia/Katmandu")
|
||||
assert index == 77
|
||||
|
||||
# Try a timezone not hardcoded no match
|
||||
with pytest.raises(zoneinfo.ZoneInfoNotFoundError):
|
||||
await get_timezone_index("Foo/bar")
|
||||
|
Reference in New Issue
Block a user