Skip to content

Commit 6ff8641

Browse files
authored
同步原作者bug fix
1 parent 9245062 commit 6ff8641

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

custom_components/chineseholiday/sensor.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,18 @@ def anniversary_handle(l,age):
349349
day = int(key[2:])
350350
age = -1
351351

352-
solar_date = lunar.CalendarToday.lunar_to_solar(self._lunar.solar()[0],month,day)#下标和位置
352+
#solar_date = lunar.CalendarToday.lunar_to_solar(self._lunar.solar()[0],month,day)#下标和位置
353+
y = self._lunar.lunar()[0]
354+
if month < self._lunar.lunar()[1]:
355+
y += 1
356+
elif month == self._lunar.lunar()[1]:
357+
if day < self._lunar.lunar()[2]:
358+
y += 1
359+
360+
solar_date = lunar.CalendarToday.lunar_to_solar(y,month,day)#下标和位置
361+
353362
date_str = solar_date.strftime('%Y%m%d')
363+
self._lunar = lunar.CalendarToday()
354364
try:
355365
l = anniversaries[date_str]
356366
except Exception as e:
@@ -507,6 +517,8 @@ def _update(self):
507517
self.localizedAttributes['星期'] = self._lunar.week_description()
508518
self.attributes['lunar'] = self._lunar.lunar_date_description()
509519
self.localizedAttributes['农历'] = self._lunar.lunar_date_description()
520+
self.attributes['week_number'] = self._lunar.solar_week_number()
521+
self.localizedAttributes['周数'] = self._lunar.solar_week_number_description()
510522
term = self._lunar.solar_Term()
511523
if term:
512524
self.attributes['term'] = term
@@ -522,7 +534,7 @@ def _update(self):
522534
self.localizedAttributes['纪念日'] = custom
523535

524536
#这里传的数字 控制 显示几个 自定义的纪念日
525-
results = self.calculate_anniversary(4)
537+
results = self.calculate_anniversary(5)
526538
_LOGGER.info(f'anniversaries: ${results}')
527539

528540
self.attributes['next_anniversaries'] = []

0 commit comments

Comments
 (0)