Skip to content

Commit

Permalink
Intellifire Diagnostic Sensors (home-assistant#66597)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeftor authored Feb 18, 2022
1 parent 30e2411 commit 2d21015
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion homeassistant/components/intellifire/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.dt import utcnow

from . import IntellifireDataUpdateCoordinator
from .const import DOMAIN
from .coordinator import IntellifireDataUpdateCoordinator
from .entity import IntellifireEntity


Expand All @@ -46,6 +47,13 @@ def _time_remaining_to_timestamp(data: IntellifirePollData) -> datetime | None:
return utcnow() + timedelta(seconds=seconds_offset)


def _downtime_to_timestamp(data: IntellifirePollData) -> datetime | None:
"""Define a sensor that takes into account a timezone."""
if not (seconds_offset := data.downtime):
return None
return utcnow() - timedelta(seconds=seconds_offset)


INTELLIFIRE_SENSORS: tuple[IntellifireSensorEntityDescription, ...] = (
IntellifireSensorEntityDescription(
key="flame_height",
Expand Down Expand Up @@ -85,6 +93,40 @@ def _time_remaining_to_timestamp(data: IntellifirePollData) -> datetime | None:
device_class=SensorDeviceClass.TIMESTAMP,
value_fn=_time_remaining_to_timestamp,
),
IntellifireSensorEntityDescription(
key="downtime",
name="Downtime",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.TIMESTAMP,
value_fn=_downtime_to_timestamp,
),
IntellifireSensorEntityDescription(
key="uptime",
name="Uptime",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.TIMESTAMP,
value_fn=lambda data: utcnow() - timedelta(seconds=data.uptime),
),
IntellifireSensorEntityDescription(
key="connection_quality",
name="Connection Quality",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda data: data.connection_quality,
entity_registry_enabled_default=False,
),
IntellifireSensorEntityDescription(
key="ecm_latency",
name="ECM Latency",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda data: data.ecm_latency,
entity_registry_enabled_default=False,
),
IntellifireSensorEntityDescription(
key="ipv4_address",
name="IP",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda data: data.ipv4_address,
),
)


Expand Down

0 comments on commit 2d21015

Please sign in to comment.