Skip to content

Commit

Permalink
Adding subscription expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
MTrab committed Oct 8, 2023
1 parent 3871f12 commit 0bbf5ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions custom_components/webastoconnect/pywebasto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module for interfacing with Webasto Connect."""

from datetime import datetime
import json
import threading
from typing import Any
Expand Down Expand Up @@ -301,6 +302,12 @@ def output_name(self) -> str:
"""Get the main output name."""
return self._mainOutput["name"]

@property
def subscription_expiration(self) -> datetime:
"""Get subscription expiration."""
expiration = self._dev_data["subscription"]["expiration"]
return datetime.fromtimestamp(expiration)

def __get_value(self, group: str, key: str) -> Any:
"""Get a value from the settings dict."""
for g in self._settings["settings_tab"]:
Expand Down
12 changes: 12 additions & 0 deletions custom_components/webastoconnect/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import logging

import homeassistant.util.dt as dt_util
from homeassistant.components import sensor
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import callback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import slugify as util_slugify
Expand Down Expand Up @@ -40,6 +42,16 @@
value_fn=lambda webasto: webasto.voltage,
icon="mdi:car-battery",
),
WebastoConnectSensorEntityDescription(
key="subscription_expiration",
name="Subscription Expiration",
entity_category=EntityCategory.DIAGNOSTIC,
state_class=None,
device_class=None,
entity_registry_enabled_default=False,
value_fn=lambda webasto: webasto.subscription_expiration.strftime("%d-%m-%Y"),
icon="mdi:calendar-end",
),
]


Expand Down

0 comments on commit 0bbf5ac

Please sign in to comment.