HASS - 获取日出日落时间的常用方法失效 - 如何解决?
我有一个Python程序,已经在家居助手上每天运行超过一年了。
这个程序是通过一个脚本来调用的:
#!/bin/bash
python3 /config/solax/compute_pv_schedule.py $1 $2 $3 $4 $5 $6
昨天,这个脚本第一次返回了一个错误,日志里显示是这样的:
(...)
File "/config/solax/compute_pv_schedule.py", line 331, in <module>
v_sunrise_hour = int(v_sun.get_sunrise_time().strftime(\'%H\'))
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/suntime/suntime.py", line 34, in get_sunrise_time
time_delta = self.get_sun_timedelta(at_date, time_zone=time_zone, is_rise_time=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/suntime/suntime.py", line 131, in get_sun_timedelta
UT += time_zone.utcoffset(at_date).total_seconds() / 3600
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: utcoffset(dt) argument must be a datetime instance or None, not datetime.date
在Python程序中出问题的代码行其实很简单,正如之前所说,它们在过去一年里一直没有任何问题,一直到现在:
from suntime import Sun, SunTimeException
(...)
v_sun = Sun(k_latitude, k_longitude)
v_sunrise_hour = int(v_sun.get_sunrise_time().strftime('%H')) ## <<<< offending line
v_sunset_hour = int(v_sun.get_sunset_time().strftime('%H'))
有没有人也遇到过这种情况?
看起来像是底层的Python库出了问题,是吗?
有没有人能帮忙,给点建议怎么解决这个问题?
或者我们需要在GitHub上提交一个bug吗?这个问题是已知的bug吗?
任何反馈都非常感谢。
谢谢,
-jprates
1 个回答
1
是的,这看起来是三天前一个提交中的一个错误。短期内,你可以通过修改代码来绕过这个问题,改成:
now = datetime.now()
v_sunrise_hour = int(v_sun.get_sunrise_time(now).strftime('%H'))
v_sunset_hour = int(v_sun.get_sunset_time(now).strftime('%H'))
后续
我已经提交了一个错误报告。