2021-07-02 15:43:37 +00:00
|
|
|
"""Support for Goal Zero Yeti Sensors."""
|
2021-07-21 06:53:53 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-08-17 20:38:20 +00:00
|
|
|
from homeassistant.components.sensor import (
|
2021-08-19 02:24:44 +00:00
|
|
|
STATE_CLASS_MEASUREMENT,
|
|
|
|
STATE_CLASS_TOTAL_INCREASING,
|
2021-08-17 20:38:20 +00:00
|
|
|
SensorEntity,
|
2021-08-19 02:24:44 +00:00
|
|
|
SensorEntityDescription,
|
2021-08-17 20:38:20 +00:00
|
|
|
)
|
2021-08-19 02:24:44 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-07-02 15:43:37 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
CONF_NAME,
|
2021-08-19 02:24:44 +00:00
|
|
|
DEVICE_CLASS_BATTERY,
|
|
|
|
DEVICE_CLASS_CURRENT,
|
|
|
|
DEVICE_CLASS_ENERGY,
|
|
|
|
DEVICE_CLASS_POWER,
|
|
|
|
DEVICE_CLASS_SIGNAL_STRENGTH,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
DEVICE_CLASS_VOLTAGE,
|
|
|
|
ELECTRIC_CURRENT_AMPERE,
|
|
|
|
ELECTRIC_POTENTIAL_VOLT,
|
|
|
|
ENERGY_WATT_HOUR,
|
|
|
|
PERCENTAGE,
|
|
|
|
POWER_WATT,
|
|
|
|
SIGNAL_STRENGTH_DECIBELS,
|
|
|
|
TEMP_CELSIUS,
|
|
|
|
TIME_MINUTES,
|
|
|
|
TIME_SECONDS,
|
2021-07-02 15:43:37 +00:00
|
|
|
)
|
2021-08-19 02:24:44 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
2021-07-02 15:43:37 +00:00
|
|
|
|
2021-08-19 02:24:44 +00:00
|
|
|
from . import Yeti, YetiEntity
|
|
|
|
from .const import DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN
|
|
|
|
|
|
|
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="wattsIn",
|
|
|
|
name="Watts In",
|
|
|
|
device_class=DEVICE_CLASS_POWER,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=POWER_WATT,
|
2021-08-19 02:24:44 +00:00
|
|
|
state_class=STATE_CLASS_MEASUREMENT,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="ampsIn",
|
|
|
|
name="Amps In",
|
|
|
|
device_class=DEVICE_CLASS_CURRENT,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
2021-08-19 02:24:44 +00:00
|
|
|
state_class=STATE_CLASS_MEASUREMENT,
|
|
|
|
entity_registry_enabled_default=False,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="wattsOut",
|
|
|
|
name="Watts Out",
|
|
|
|
device_class=DEVICE_CLASS_POWER,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=POWER_WATT,
|
2021-08-19 02:24:44 +00:00
|
|
|
state_class=STATE_CLASS_MEASUREMENT,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="ampsOut",
|
|
|
|
name="Amps Out",
|
|
|
|
device_class=DEVICE_CLASS_CURRENT,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
2021-08-19 02:24:44 +00:00
|
|
|
state_class=STATE_CLASS_MEASUREMENT,
|
|
|
|
entity_registry_enabled_default=False,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="whOut",
|
|
|
|
name="WH Out",
|
|
|
|
device_class=DEVICE_CLASS_ENERGY,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
2021-08-19 02:24:44 +00:00
|
|
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
|
|
|
entity_registry_enabled_default=False,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="whStored",
|
|
|
|
name="WH Stored",
|
|
|
|
device_class=DEVICE_CLASS_ENERGY,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
2021-08-19 02:24:44 +00:00
|
|
|
state_class=STATE_CLASS_MEASUREMENT,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="volts",
|
|
|
|
name="Volts",
|
|
|
|
device_class=DEVICE_CLASS_VOLTAGE,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
2021-08-19 02:24:44 +00:00
|
|
|
entity_registry_enabled_default=False,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="socPercent",
|
|
|
|
name="State of Charge Percent",
|
|
|
|
device_class=DEVICE_CLASS_BATTERY,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=PERCENTAGE,
|
2021-08-19 02:24:44 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="timeToEmptyFull",
|
|
|
|
name="Time to Empty/Full",
|
|
|
|
device_class=TIME_MINUTES,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=TIME_MINUTES,
|
2021-08-19 02:24:44 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="temperature",
|
|
|
|
name="Temperature",
|
|
|
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=TEMP_CELSIUS,
|
2021-08-19 02:24:44 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="wifiStrength",
|
|
|
|
name="Wifi Strength",
|
|
|
|
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
2021-08-22 18:13:44 +00:00
|
|
|
entity_registry_enabled_default=False,
|
2021-08-19 02:24:44 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="timestamp",
|
|
|
|
name="Total Run Time",
|
2021-08-20 13:54:57 +00:00
|
|
|
native_unit_of_measurement=TIME_SECONDS,
|
2021-08-19 02:24:44 +00:00
|
|
|
entity_registry_enabled_default=False,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="ssid",
|
|
|
|
name="Wi-Fi SSID",
|
|
|
|
entity_registry_enabled_default=False,
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="ipAddr",
|
|
|
|
name="IP Address",
|
|
|
|
entity_registry_enabled_default=False,
|
|
|
|
),
|
2021-07-02 15:43:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-19 02:24:44 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
2021-07-02 15:43:37 +00:00
|
|
|
"""Set up the Goal Zero Yeti sensor."""
|
|
|
|
name = entry.data[CONF_NAME]
|
|
|
|
goalzero_data = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
sensors = [
|
|
|
|
YetiSensor(
|
|
|
|
goalzero_data[DATA_KEY_API],
|
|
|
|
goalzero_data[DATA_KEY_COORDINATOR],
|
|
|
|
name,
|
2021-08-19 02:24:44 +00:00
|
|
|
description,
|
2021-07-02 15:43:37 +00:00
|
|
|
entry.entry_id,
|
|
|
|
)
|
2021-08-19 02:24:44 +00:00
|
|
|
for description in SENSOR_TYPES
|
2021-07-02 15:43:37 +00:00
|
|
|
]
|
|
|
|
async_add_entities(sensors, True)
|
|
|
|
|
|
|
|
|
2021-08-17 20:38:20 +00:00
|
|
|
class YetiSensor(YetiEntity, SensorEntity):
|
2021-07-02 15:43:37 +00:00
|
|
|
"""Representation of a Goal Zero Yeti sensor."""
|
|
|
|
|
2021-08-19 02:24:44 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
api: Yeti,
|
|
|
|
coordinator: DataUpdateCoordinator,
|
|
|
|
name: str,
|
|
|
|
description: SensorEntityDescription,
|
|
|
|
server_unique_id: str,
|
|
|
|
) -> None:
|
2021-07-02 15:43:37 +00:00
|
|
|
"""Initialize a Goal Zero Yeti sensor."""
|
|
|
|
super().__init__(api, coordinator, name, server_unique_id)
|
2021-08-19 02:24:44 +00:00
|
|
|
self._attr_name = f"{name} {description.name}"
|
|
|
|
self.entity_description = description
|
|
|
|
self._attr_unique_id = f"{server_unique_id}/{description.key}"
|
2021-07-02 15:43:37 +00:00
|
|
|
|
|
|
|
@property
|
2021-08-19 02:24:44 +00:00
|
|
|
def native_value(self) -> str:
|
2021-07-02 15:43:37 +00:00
|
|
|
"""Return the state."""
|
2021-08-19 02:24:44 +00:00
|
|
|
return self.api.data.get(self.entity_description.key)
|