Skip to content
Snippets Groups Projects
Unverified Commit 0dfe1284 authored by Jeef's avatar Jeef Committed by GitHub
Browse files

Add SimpleFin binary sensor for errors (#122554)

* Binary Sensor Support

* updated requirements

* ng ambr

* update strings.json

* update snapshot
parent d915fee8
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,10 @@ from homeassistant.core import HomeAssistant
from .const import CONF_ACCESS_URL
from .coordinator import SimpleFinDataUpdateCoordinator
PLATFORMS: list[str] = [Platform.SENSOR]
PLATFORMS: list[str] = [
Platform.BINARY_SENSOR,
Platform.SENSOR,
]
type SimpleFinConfigEntry = ConfigEntry[SimpleFinDataUpdateCoordinator]
......
"""Binary Sensor for SimpleFin."""
from collections.abc import Callable
from dataclasses import dataclass
from simplefin4py import Account
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import SimpleFinConfigEntry
from .entity import SimpleFinEntity
@dataclass(frozen=True, kw_only=True)
class SimpleFinBinarySensorEntityDescription(BinarySensorEntityDescription):
"""Describes a sensor entity."""
value_fn: Callable[[Account], bool]
SIMPLEFIN_BINARY_SENSORS: tuple[SimpleFinBinarySensorEntityDescription, ...] = (
SimpleFinBinarySensorEntityDescription(
key="possible_error",
translation_key="possible_error",
device_class=BinarySensorDeviceClass.PROBLEM,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda account: account.possible_error,
),
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: SimpleFinConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up SimpleFIN sensors for config entries."""
sf_coordinator = config_entry.runtime_data
accounts = sf_coordinator.data.accounts
async_add_entities(
SimpleFinBinarySensor(
sf_coordinator,
sensor_description,
account,
)
for account in accounts
for sensor_description in SIMPLEFIN_BINARY_SENSORS
)
class SimpleFinBinarySensor(SimpleFinEntity, BinarySensorEntity):
"""Extends IntellifireEntity with Binary Sensor specific logic."""
entity_description: SimpleFinBinarySensorEntityDescription
@property
def is_on(self) -> bool:
"""Use this to get the correct value."""
return self.entity_description.value_fn(self.account_data)
......@@ -21,6 +21,9 @@
}
},
"entity": {
"binary_sensor": {
"possible_error": { "name": "Possible error" }
},
"sensor": {
"balance": {
"name": "Balance"
......
This diff is collapsed.
"""Test SimpleFin Sensor with Snapshot data."""
from unittest.mock import AsyncMock, patch
from syrupy import SnapshotAssertion
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import setup_integration
from tests.common import MockConfigEntry, snapshot_platform
async def test_all_entities(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
mock_simplefin_client: AsyncMock,
) -> None:
"""Test all entities."""
with patch(
"homeassistant.components.simplefin.PLATFORMS", [Platform.BINARY_SENSOR]
):
await setup_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment