Skip to content

Add payment date (editable datetime) and next payment date (sensor) entities#7

Merged
CodekExplor merged 1 commit intomainfrom
copilot/add-payment-date-sensors
Apr 14, 2026
Merged

Add payment date (editable datetime) and next payment date (sensor) entities#7
CodekExplor merged 1 commit intomainfrom
copilot/add-payment-date-sensors

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Adds two new per-bill entities tracking payment history and the upcoming due date, completing the payment lifecycle tracking alongside the existing confirm-payment button.

New entities

  • data_platnosci (datetime platform) — editable DateTimeEntity storing the last completed payment timestamp. Auto-set by the "Potwierdź płatność" button; can be overridden manually from the HA UI. Persisted via HA Store.
  • data_kolejnej_platnosci (sensor, SensorDeviceClass.DATE) — read-only sensor exposing the next due date (termin_platnosci). Advances automatically on payment confirmation per the configured recurrence cycle.

Changes

  • const.py — added DATETIME_PAYMENT_DATE and SENSOR_NEXT_PAYMENT_DATE constants
  • coordinator.py — added async_set_payment_confirmed_date(dt) for manual date writes to storage
  • datetime.py (new)PaymentDateEntity implementing DateTimeEntity with async_set_value delegating to the coordinator
  • sensor.py — added NextPaymentDateSensor; returns date.fromisoformat(due_date_str) with SensorDeviceClass.DATE
  • __init__.py — registered "datetime" in PLATFORMS
  • translations/pl.json, strings.json — translations for both new entities

…or) entities

Agent-Logs-Url: https://github.com/CodekExplor/Bills-ha/sessions/f9f71eb1-9017-497a-9751-1fa57f0fce91

Co-authored-by: CodekExplor <24770587+CodekExplor@users.noreply.github.com>
@CodekExplor CodekExplor requested a review from Copilot April 14, 2026 09:52
@CodekExplor CodekExplor marked this pull request as ready for review April 14, 2026 09:53
@CodekExplor CodekExplor merged commit 9edce2d into main Apr 14, 2026
2 of 3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds two new per-bill entities to the oplats Home Assistant integration to track the last payment timestamp (editable datetime) and expose the next payment due date (sensor), extending the existing “confirm payment” flow.

Changes:

  • Adds an editable datetime entity (data_platnosci) backed by HA Store via the coordinator.
  • Adds a read-only date sensor (data_kolejnej_platnosci) exposing the current configured due date as SensorDeviceClass.DATE.
  • Wires up new entity IDs, platform registration, and UI translations.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
custom_components/oplats/translations/pl.json Adds Polish entity-name translations for the new datetime and sensor entities.
custom_components/oplats/strings.json Adds base (English) entity-name strings for the new datetime and sensor entities.
custom_components/oplats/sensor.py Registers and implements NextPaymentDateSensor (DATE device class).
custom_components/oplats/datetime.py Adds PaymentDateEntity (DateTimeEntity) with manual write-through to coordinator.
custom_components/oplats/coordinator.py Adds async_set_payment_confirmed_date() to persist manual payment datetime updates.
custom_components/oplats/const.py Introduces constants for the new entity IDs.
custom_components/oplats/init.py Registers the datetime platform for config entry forwarding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +16
import logging
from datetime import datetime

from homeassistant.components.datetime import DateTimeEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DATETIME_PAYMENT_DATE, DOMAIN
from .coordinator import BillCoordinator

_LOGGER = logging.getLogger(__name__)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

logging / _LOGGER are defined but never used in this new module. Please remove the unused import/logger or add logging where it provides value, to avoid lint noise and keep the file minimal.

Copilot uses AI. Check for mistakes.
Comment on lines +139 to +148
async def async_set_payment_confirmed_date(self, dt: datetime) -> None:
"""Ręcznie ustaw datę wykonanej płatności."""
self._payment_confirmed_date = dt.isoformat()
await self.async_save()
self._notify_listeners()
_LOGGER.info(
"Ręcznie ustawiono datę płatności dla '%s' na %s.",
self.bill_name,
dt.isoformat(),
)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

dt.isoformat() will preserve whatever timezone awareness the UI passes in (often tz-aware), but this integration currently also writes naive datetimes elsewhere (e.g. datetime.now().isoformat() in async_confirm_payment). Mixing naive and tz-aware ISO strings can lead to Home Assistant warnings and inconsistent display/parsing. Consider normalizing dt using Home Assistant time helpers (e.g. convert to local/UTC consistently) before storing, and align async_confirm_payment to the same approach so the stored format is uniform.

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +54
def native_value(self) -> datetime | None:
"""Zwróć datę wykonanej płatności."""
raw = self._coordinator.payment_confirmed_date
if not raw:
return None
try:
return datetime.fromisoformat(raw)
except (ValueError, TypeError):
return None
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

Using datetime.fromisoformat() here can return a naive datetime (because existing stored values are written with datetime.now().isoformat()), and it will also fail to parse some valid ISO-8601 forms (e.g. strings ending with Z). For Home Assistant DateTimeEntity, prefer using HA datetime utilities (e.g. homeassistant.util.dt.parse_datetime) and ensure the returned native_value is timezone-aware and in the expected timezone.

Copilot uses AI. Check for mistakes.
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.

3 participants