include a test sensor
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
"""Constants for fpl."""
|
||||
#
|
||||
DEBUG = True
|
||||
|
||||
|
||||
# Base component constants
|
||||
NAME = "FPL Integration"
|
||||
DOMAIN = "fpl"
|
||||
@@ -25,15 +29,6 @@ PLATFORMS = [SENSOR]
|
||||
# Device classes
|
||||
BINARY_SENSOR_DEVICE_CLASS = "connectivity"
|
||||
|
||||
# Configuration
|
||||
CONF_BINARY_SENSOR = "binary_sensor"
|
||||
CONF_SENSOR = "sensor"
|
||||
CONF_SWITCH = "switch"
|
||||
CONF_ENABLED = "enabled"
|
||||
CONF_NAME = "name"
|
||||
CONF_USERNAME = "username"
|
||||
CONF_PASSWORD = "password"
|
||||
|
||||
# Defaults
|
||||
DEFAULT_NAME = DOMAIN
|
||||
|
||||
|
||||
@@ -31,18 +31,26 @@ from .sensor_DailyUsageSensor import (
|
||||
FplDailyDeliveredKWHSensor,
|
||||
FplDailyReceivedKWHSensor,
|
||||
)
|
||||
from .const import DOMAIN
|
||||
|
||||
from .sensor_test import TestSensor
|
||||
|
||||
from .const import DOMAIN, DEBUG
|
||||
|
||||
# from .TestSensor import TestSensor
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_devices):
|
||||
"""Setup sensor platform."""
|
||||
|
||||
accounts = entry.data.get("accounts")
|
||||
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
fpl_accounts = []
|
||||
|
||||
if DEBUG:
|
||||
for account in accounts:
|
||||
fpl_accounts.append(TestSensor(coordinator, entry, account))
|
||||
else:
|
||||
for account in accounts:
|
||||
# Test Sensor
|
||||
# fpl_accounts.append(TestSensor(coordinator, entry, account))
|
||||
|
||||
43
custom_components/fpl/sensor_test.py
Normal file
43
custom_components/fpl/sensor_test.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""Test Sensors"""
|
||||
from datetime import timedelta, datetime
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from .fplEntity import FplEnergyEntity
|
||||
|
||||
|
||||
class TestSensor(FplEnergyEntity):
|
||||
"""Daily Usage Kwh Sensor"""
|
||||
|
||||
def __init__(self, coordinator, config, account):
|
||||
super().__init__(coordinator, config, account, "Test Sensor")
|
||||
|
||||
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
_attr_device_class = DEVICE_CLASS_ENERGY
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
data = self.getData("daily_usage")
|
||||
|
||||
if data is not None and len(data) > 0 and "usage" in data[-1].keys():
|
||||
return data[-1]["usage"]
|
||||
|
||||
return None
|
||||
|
||||
@property
|
||||
def last_reset(self) -> datetime | None:
|
||||
data = self.getData("daily_usage")
|
||||
date = data[-1]["readTime"]
|
||||
last_reset = date - timedelta(days=1)
|
||||
return last_reset
|
||||
|
||||
def customAttributes(self):
|
||||
"""Return the state attributes."""
|
||||
data = self.getData("daily_usage")
|
||||
date = data[-1]["readTime"]
|
||||
|
||||
attributes = {}
|
||||
attributes["date"] = date
|
||||
return attributes
|
||||
Reference in New Issue
Block a user