Skip to content

Commit e3179ba

Browse files
Enhance weather dark mode and exclude channel 0x270f to avoid weekly popups
1 parent b24e5f1 commit e3179ba

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ pillow==11.3.0
1919
pngquant==3.0.3
2020
python-dateutil~=2.9.0
2121
pycryptodome~=3.23.0
22-
pytz==2025.2
22+
pytz==2025.2
23+
suntime~=1.3.2

tculink/carwings_proto/autodj/handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def handle_directory_response(xml_data, returning_xml):
4949
]
5050

5151
def handle_channel_response(xml_data, channel_id, returning_xml, flag):
52+
# Channel 0x270f is intended for channel directory refreshes (?), just provide directory and avoid the popup-
53+
# This channel is accessed once per week.
54+
if channel_id == 0x270f:
55+
return handle_directory_response(xml_data, returning_xml)
56+
5257
car = get_cws_authenticated_car(xml_data)
5358
channels, folders = get_info_channel_data(car, True)
5459

tculink/carwings_proto/autodj/weather.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import logging
2-
import math
2+
from suntime import Sun
33
import os
44
from datetime import timedelta, datetime
55
from io import BytesIO
6-
76
import geopy.geocoders
87
import pngquant
98
import requests
@@ -86,26 +85,16 @@
8685

8786
def is_daylight(lat, lon):
8887
try:
88+
sun = Sun(lat, lon)
8989
utc_time = timezone.now()
90-
lat_rad = math.radians(lat)
91-
day_of_year = utc_time.timetuple().tm_yday
92-
solar_noon = 12.0 - (lon / 15.0)
93-
mean_anomaly = math.radians(357.5291 + 0.98560028 * day_of_year)
94-
ecliptic_long = mean_anomaly + 1.9148 * math.sin(mean_anomaly) + 0.0200 * math.sin(2 * mean_anomaly) + 282.634
95-
declination = math.asin(math.sin(math.radians(23.44)) * math.sin(math.radians(ecliptic_long)))
96-
cos_hour_angle = -math.tan(lat_rad) * math.tan(declination)
97-
if abs(cos_hour_angle) > 1:
98-
return cos_hour_angle < 0
99-
hour_angle = math.degrees(math.acos(cos_hour_angle))
100-
sunrise = solar_noon - (hour_angle / 15.0)
101-
sunset = solar_noon + (hour_angle / 15.0)+3
102-
current_hour = utc_time.hour + utc_time.minute / 60.0 + utc_time.second / 3600.0
103-
return sunrise <= current_hour <= sunset
90+
sunrise = sun.get_sunrise_time()
91+
sunset = sun.get_sunset_time()
92+
93+
return sunrise <= utc_time <= sunset
10494
except Exception as e:
10595
print(f"Error calculating sunlight: {e}")
10696
return False
10797

108-
10998
def get_city(lat, lon):
11099
geolocator = geopy.geocoders.nominatim.Nominatim(user_agent="OpenCARWINGS", timeout=3)
111100
try:

0 commit comments

Comments
 (0)