Skip to content

Audit fixes: correct calendar values, leaner core, tests against known answers - #4

Merged
Lexorius merged 2 commits into
mainfrom
fix/audit-findings
Nov 15, 2026
Merged

Lexorius merged 2 commits into
mainfrom
fix/audit-findings

Conversation

@Lexorius

Copy link
Copy Markdown
Owner

Summary

Fixes all 20 findings of the full repo audit, plus three small ones. This changes displayed values, removes three attributes and two options — please test in a live instance before it is tagged. No version bump yet; the notes sit under [Unreleased] in CHANGELOG.md (planned: 2.7.0).

Wrong values and crashes

Calendar What was wrong
swatch One hour (41.7 beats) too high all summer. Biel Mean Time is fixed UTC+1; the code used Europe/Zurich with daylight saving.
stardate, discworld, eve, islamic, rivendell, shire, tamriel Ignored every option (31 in total): set_options() was defined but never called.
warcraft IndexError on 52 days a year.
julian_date Always half a day too low.
mars Mars Sol Date 4.4 sols too high; season (Ls) guessed linearly; five of seven landing sols wrong.
darian Year 85 instead of 221 (ratio upside down, wrong epoch, month lengths, no leap years, weekday).
solar_system "Geocentric" longitude and visibility subtracted two heliocentric angles; Saturn at opposition was "not visible". Retrograde was hard-coded False.
islamic, suriyakati, lunar_time Weekday one day ahead; wrong zodiac animal; illumination inverted.
hindu_panchang, japanese_lunar, suriyakati, sexagesimal Made-up moon and year maths, replaced by real new/full moons and Sun/Moon longitude.
stellar_distances Swallowed its own errors.
timezone An unknown zone name raised NameError while the entity was added.
25 calendars Used the operating-system clock (UTC in a container without TZ) instead of Home Assistant's time zone.

Core

  • One calendar discovery instead of three; no sys.path changes; a plugin that fails to import is logged at ERROR.
  • One option-form builder for the wizard and the options dialog.
  • New sensors get entity_id = sensor.alternative_time_<calendar> set explicitly. Newer Home Assistant versions prefixed device and area names onto the suggested id, so the recorder glob from the README could miss them. Existing entities keep their id.
  • Wizard and sensors pick the language the same way (i18n.py). translations/zh.json is now zh-Hans.json.
  • astro.py: shared, dependency-free astronomy (Julian day, Meeus moon phases, Sun/Moon longitude, lunisolar calendar, Mars Sol Date and Ls).
  • Dead code removed; pytz and tzlocal dropped in favour of zoneinfo. Requirements are now LunarCalendar and Pillow only.
  • Removed files that still reached every HACS user: calendars/test_debug.py, template.py.example, calendars/README.md, README_FIX.md. LICENCE renamed to LICENSE.

Breaking for users

  • Displayed values change in the calendars above.
  • solar_system: attributes solar_system_map_svg, solar_system_map_png and observer_location are gone. Use local_svg_path, local_png_path or entity_picture.
  • Options darian.month_names and german_rescue_dtg.show_timezone are gone (they had no effect).
  • Options of the seven calendars take effect for the first time.

Tests

pytest tests: 175 passed (was 80), ruff clean on custom_components/ and tests/. New:

  • every calendar on every day of a leap year, no error state
  • published reference values: Julian Dates, Curiosity and Perseverance landing sols, Darian dates of eight Mars missions, Mars year starts, new/full moons, Chinese New Year 2023–2028 with leap months, Makha Bucha, Buddha Purnima, Diwali, eleven Poya days, summer/winter time of the zone clocks
  • every option reaches its sensor; setup assigns the fixed entity ids

Not verified

  • Nothing ran on a live Home Assistant: the explicit entity ids, the options dialog and the id migration are only covered by tests against a stubbed HA.
  • chinese_lunar needs a library that is not installed on the dev machine.
  • The UT1 data service could not be reached from the dev machine.

🤖 Generated with Claude Code

Thomas Kloppholz and others added 2 commits November 15, 2026 21:27
…answer tests

Fixes all 20 findings of the repo audit plus three small ones.

Wrong values / crashes
- swatch: BMT is fixed UTC+1, no daylight saving (was one hour off all summer)
- stardate, discworld, eve, islamic, rivendell, shire, tamriel: options are
  now actually loaded (set_options() was never called)
- warcraft: IndexError on 52 days a year (moon phase index)
- julian: Julian Date was half a day too low
- mars: Mars Sol Date 4.4 sols too high, Ls guessed linearly, landing sols
- darian: year 85 instead of 221 (ratio, epoch, month lengths, leap years)
- solar_system: real geocentric geometry, visibility by elongation,
  retrograde computed; map no longer stored three times in the attributes
- islamic weekday, Thai zodiac, lunar illumination (one-line slips)
- hindu_panchang, japanese_lunar, suriyakati, sexagesimal: real new/full
  moons and Sun/Moon longitude instead of made-up cycles
- stellar_distances: errors reach the base class instead of the state
- timezone: unknown zone name raised NameError while the entity was added
- 25 calendars used the OS clock; they now use Home Assistant's time zone

Core
- one calendar discovery instead of three, no sys.path changes
- one option-form builder for wizard and options dialog
- new sensors get entity_id sensor.alternative_time_<calendar> explicitly
- wizard and sensors pick the language the same way (i18n.py);
  translations/zh.json renamed to zh-Hans.json
- astro.py: shared, dependency-free astronomy (Julian day, Meeus moon
  phases, Sun/Moon longitude, lunisolar calendar, Mars Sol Date and Ls)
- dead code removed (unused constants, async_setup/CONFIG_SCHEMA, hass.data
  bookkeeping, pass-through async_update, dead options)
- pytz and tzlocal dropped; zoneinfo instead

Housekeeping
- removed calendars/test_debug.py, template.py.example, calendars/README.md,
  README_FIX.md; LICENCE renamed to LICENSE
- README: 45 calendars, two non-existent calendars removed
- CI lints tests/; tests: 80 -> 175, incl. published reference values

Removed attributes/options (see CHANGELOG): solar_system_map_svg,
solar_system_map_png, observer_location, darian.month_names,
german_rescue_dtg.show_timezone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tant ships itself

The PIL import in solar_system.py is optional and Home Assistant core already depends on Pillow, so the PNG map keeps working.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Lexorius
Lexorius merged commit 5333dd0 into main Nov 15, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant