Skip to content

Make iot time timezone aware #1147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 8, 2024
Merged

Make iot time timezone aware #1147

merged 8 commits into from
Oct 8, 2024

Conversation

sdb9696
Copy link
Collaborator

@sdb9696 sdb9696 commented Oct 1, 2024

  • Make iot time timezone aware
  • Make on_since for iot devices use device time

Closes #980

Breaking:

This changes the return value for device.timezone to be tzinfo so marking as a breaking change. Previous return values of {"timezone": ti.tzname()} for smart and {"index": 39, "error_code": 0} for iot were not particularly helpful so I don't think we need to be backwards compatible.

Requires the tzdata to be installed on windows as there is no system installation.

N.B. The get_timezone_index should allow setting the iot device timezone from any IANA timezone key.

The mapping for the iot firmware index / internal name to IANA timezone is below (n.b. Magadan index 100 is duplicated with no side-effects):

Index Name IANA Timezone
0 International Date Line West Etc/GMT+12
1 Coordinated Universal Time-11 Pacific/Samoa
2 Hawaii US/Hawaii
3 Alaska US/Alaska
4 Baja California Mexico/BajaNorte
5 Pacific Standard Time (US & Canada) Etc/GMT+8
6 Pacific Daylight Time (US & Canada) PST8PDT
7 Arizona US/Arizona
8 La paz, Mazatlan, Chihuahua America/Mazatlan
9 Mountain Standard Time (US & Canada) MST
10 Mountain Daylight Time (US & Canada) MST7MDT
11 Central America Mexico/General
12 Central Standard Time (US & Canada) Etc/GMT+6
13 Central Daylight Time (US & Canada) CST6CDT
14 Guadalajara, Mexico City, Monterrey America/Monterrey
15 Saskatchewan Canada/Saskatchewan
16 Bogota, Lima, Quito, Rio Branco America/Bogota
17 Eastern Standard Time (US & Canada) Etc/GMT+5
18 Eastern Daylight Time (US & Canada) EST
19 Indiana (East) America/Indiana/Indianapolis
20 Caracas America/Caracas
21 Asuncion America/Asuncion
22 Atlantic Standard Time (Canada) Etc/GMT+4
23 Atlantic Daylight Time (Canada) Canada/Atlantic
24 Cuiaba America/Cuiaba
25 Georgetown Brazil/West
26 Santiago America/Santiago
27 Newfoundland Canada/Newfoundland
28 Brasilia America/Sao_Paulo
29 Buenos Aires America/Argentina/Buenos_Aires
30 Cayenne, Fortaleza America/Cayenne
31 Greenland America/Miquelon
32 Montevideo America/Montevideo
33 Salvador Chile/Continental
34 Coordinated Universal Time-02 Etc/GMT+2
35 Azores Atlantic/Azores
36 Cabo Verde Is. Atlantic/Cape_Verde
37 Casablanca Africa/Casablanca
38 Coordinated Universal Time UCT
39 Dublin, Edinburgh, Lisbon, London GB
40 Monrovia, Reykjavik Africa/Monrovia
41 Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna Europe/Amsterdam
42 Belgrade, Bratislava, Budapest, Ljubljana, Prague Europe/Belgrade
43 Brussels, Copenhagen, Madrid, Paris Europe/Brussels
44 Sarajevo, Skopje, Warsaw, Zagreb Europe/Sarajevo
45 West Central Africa Africa/Lagos
46 Windhoek Africa/Windhoek
47 Amman Asia/Amman
48 Athens, Bucharest Europe/Athens
49 Beirut Asia/Beirut
50 Cairo Africa/Cairo
51 Damascus Asia/Damascus
52 E. Europe EET
53 Harare, Pretoria Africa/Harare
54 Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius Europe/Helsinki
55 Istanbul Asia/Istanbul
56 Jerusalem Asia/Jerusalem
57 Kaliningrad (RTZ 1) Europe/Kaliningrad
58 Tripoli Africa/Tripoli
59 Baghdad Asia/Baghdad
60 Kuwait, Riyadh Asia/Kuwait
61 Minsk Europe/Minsk
62 Moscow, St. Petersburg, Volgograd (RTZ 2) Europe/Moscow
63 Nairobi Africa/Nairobi
64 Tehran Asia/Tehran
65 Abu Dhabi, Muscat Asia/Muscat
66 Baku Asia/Baku
67 Izhevsk, Samara (RTZ 3) Europe/Samara
68 Port Louis Indian/Mauritius
69 Tbilisi Asia/Tbilisi
70 Yerevan Asia/Yerevan
71 Kabul Asia/Kabul
72 Ashgabat, Tashkent Asia/Ashgabat
73 Ekaterinburg (RTZ 4) Asia/Yekaterinburg
74 Islamabad, Karachi Asia/Karachi
75 Chennai, Kolkata, Mumbai, New Delhi Asia/Kolkata
76 Sri Jayawardenepura Asia/Colombo
77 Kathmandu Asia/Kathmandu
78 Astana Asia/Almaty
79 Dhaka Asia/Dhaka
80 Novosibirsk (RTZ 5) Asia/Novosibirsk
81 Yangon (Rangoon) Asia/Rangoon
82 Bangkok, Hanoi, Jakarta Asia/Bangkok
83 Krasnoyarsk (RTZ 6) Asia/Krasnoyarsk
84 Beijing, Chongqing, Hong Kong, Urumqi Asia/Chongqing
85 Irkutsk (RTZ 7) Asia/Irkutsk
86 Kuala Lumpur, Singapore Asia/Singapore
87 Perth Australia/Perth
88 Taipei Asia/Taipei
89 Ulaanbaatar Asia/Ulaanbaatar
90 Osaka, Sapporo, Tokyo Asia/Tokyo
91 Seoul Asia/Seoul
92 Yakutsk (RTZ 8) Asia/Yakutsk
93 Adelaide Australia/Adelaide
94 Darwin Australia/Darwin
95 Brisbane Australia/Brisbane
96 Canberra, Melbourne, Sydney Australia/Canberra
97 Guam, Port Moresby Pacific/Guam
98 Hobart Australia/Hobart
99 DumontDUrville Antarctica/DumontDUrville
100 Magadan Asia/Magadan
100 Vladivostok, Magadan (RTZ 9) Asia/Magadan
101 Chokurdakh (RTZ 10) Asia/Srednekolymsk
102 Solomon Is., New Caledonia Etc/GMT-11
103 Anadyr, Petropavlovsk-Kamchatsky (RTZ 11) Asia/Anadyr
104 Auckland, Wellington Pacific/Auckland
105 Coordinated Universal Time+12 Etc/GMT-12
106 Fiji Pacific/Fiji
107 Nuku'alofa Etc/GMT-13
108 Samoa Pacific/Apia
109 Kiritimati Island Etc/GMT-14

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 94.38202% with 5 lines in your changes missing coverage. Please review.

Project coverage is 92.57%. Comparing base (8bb2cca) to head (4df2002).
Report is 200 commits behind head on master.

Files with missing lines Patch % Lines
kasa/iot/iottimezone.py 94.73% 1 Missing and 1 partial ⚠️
kasa/smart/modules/time.py 81.81% 2 Missing ⚠️
kasa/iot/modules/time.py 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1147      +/-   ##
==========================================
- Coverage   92.59%   92.57%   -0.03%     
==========================================
  Files          96       97       +1     
  Lines        6119     6168      +49     
  Branches     1514     1523       +9     
==========================================
+ Hits         5666     5710      +44     
- Misses        354      357       +3     
- Partials       99      101       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sdb9696 sdb9696 force-pushed the feat/iot_timezone branch from ec37b45 to 7778d2b Compare October 1, 2024 17:40
@sdb9696 sdb9696 changed the base branch from master to fix/on_since October 1, 2024 17:40
@rytilahti rytilahti linked an issue Oct 1, 2024 that may be closed by this pull request
@rytilahti rytilahti added the enhancement New feature or request label Oct 1, 2024
Base automatically changed from fix/on_since to master October 2, 2024 14:04
@sdb9696 sdb9696 force-pushed the feat/iot_timezone branch from 535dce2 to 4d36a92 Compare October 2, 2024 14:11
@sdb9696 sdb9696 added the breaking change Breaking change label Oct 2, 2024
@sdb9696 sdb9696 added this to the 0.7.5 milestone Oct 2, 2024
@sdb9696 sdb9696 marked this pull request as ready for review October 2, 2024 14:46
@sdb9696 sdb9696 requested a review from rytilahti October 2, 2024 15:10
@sdb9696 sdb9696 requested a review from rytilahti October 7, 2024 17:17
Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what's the best approach for caching here, maybe @bdraco knows, but otherwise this looks good to me.

@sdb9696 sdb9696 merged commit 9641edc into master Oct 8, 2024
28 checks passed
@sdb9696 sdb9696 deleted the feat/iot_timezone branch October 8, 2024 07:16
@sdb9696 sdb9696 mentioned this pull request Oct 8, 2024
sdb9696 added a commit that referenced this pull request Oct 8, 2024
## [0.7.5](https://github.com/python-kasa/python-kasa/tree/0.7.5) (2024-10-08)

[Full Changelog](0.7.4...0.7.5)

**Release summary:**

- Fix for KP303 on Firmware 1.0.6
- Fix for `on_since` value jitter
- Various maintenance items

**Breaking changes:**

- Make iot time timezone aware [\#1147](#1147) (@sdb9696)

**Fixed bugs:**

- Use tzinfo in time constructor instead of astime for iot devices [\#1158](#1158) (@sdb9696)
- Send empty dictionary instead of null for iot queries [\#1145](#1145) (@sdb9696)
- Stabilise on\_since value for smart devices [\#1144](#1144) (@sdb9696)
- parse\_pcap\_klap: require source host [\#1137](#1137) (@rytilahti)
- parse\_pcap\_klap: use request\_uri for matching the response [\#1136](#1136) (@rytilahti)


**Project maintenance:**

- Cache zoneinfo for smart devices [\#1156](#1156) (@sdb9696)
- Correctly define SmartModule.call as an async function [\#1148](#1148) (@sdb9696)
- Remove async magic patch from tests [\#1146](#1146) (@sdb9696)
- Move feature initialization from \_\_init\_\_ to \_initialize\_features [\#1140](#1140) (@rytilahti)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Breaking change enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve timezone support
2 participants