Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework goalzero for EntityDescription #54786

Merged
merged 5 commits into from Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion homeassistant/components/goalzero/binary_sensor.py
@@ -1,5 +1,8 @@
"""Support for Goal Zero Yeti Sensors."""
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY_CHARGING,
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_POWER,
BinarySensorEntity,
BinarySensorEntityDescription,
)
Expand All @@ -10,10 +13,33 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from . import Yeti, YetiEntity
from .const import BINARY_SENSOR_TYPES, DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN
from .const import DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN

PARALLEL_UPDATES = 0

BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
tkdrob marked this conversation as resolved.
Show resolved Hide resolved
BinarySensorEntityDescription(
key="backlight",
name="Backlight",
icon="mdi:clock-digital",
),
BinarySensorEntityDescription(
key="app_online",
name="App Online",
device_class=DEVICE_CLASS_CONNECTIVITY,
),
BinarySensorEntityDescription(
key="isCharging",
name="Charging",
device_class=DEVICE_CLASS_BATTERY_CHARGING,
),
BinarySensorEntityDescription(
key="inputDetected",
name="Input Detected",
device_class=DEVICE_CLASS_POWER,
),
)


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
Expand Down
165 changes: 0 additions & 165 deletions homeassistant/components/goalzero/const.py
@@ -1,37 +1,6 @@
"""Constants for the Goal Zero Yeti integration."""
from __future__ import annotations

from datetime import timedelta

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY_CHARGING,
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_POWER,
BinarySensorEntityDescription,
)
from homeassistant.components.sensor import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_SIGNAL_STRENGTH,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE,
STATE_CLASS_MEASUREMENT,
SensorEntityDescription,
)
from homeassistant.components.switch import SwitchEntityDescription
from homeassistant.const import (
ELECTRIC_CURRENT_AMPERE,
ELECTRIC_POTENTIAL_VOLT,
ENERGY_WATT_HOUR,
PERCENTAGE,
POWER_WATT,
SIGNAL_STRENGTH_DECIBELS,
TEMP_CELSIUS,
TIME_MINUTES,
TIME_SECONDS,
)

ATTRIBUTION = "Data provided by Goal Zero"
ATTR_DEFAULT_ENABLED = "default_enabled"

Expand All @@ -41,137 +10,3 @@
DATA_KEY_API = "api"

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)

BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription(
key="backlight",
name="Backlight",
icon="mdi:clock-digital",
),
BinarySensorEntityDescription(
key="app_online",
name="App Online",
device_class=DEVICE_CLASS_CONNECTIVITY,
),
BinarySensorEntityDescription(
key="isCharging",
name="Charging",
device_class=DEVICE_CLASS_BATTERY_CHARGING,
),
BinarySensorEntityDescription(
key="inputDetected",
name="Input Detected",
device_class=DEVICE_CLASS_POWER,
),
)

SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="wattsIn",
name="Watts In",
device_class=DEVICE_CLASS_POWER,
unit_of_measurement=POWER_WATT,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key="ampsIn",
name="Amps In",
device_class=DEVICE_CLASS_CURRENT,
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="wattsOut",
name="Watts Out",
device_class=DEVICE_CLASS_POWER,
unit_of_measurement=POWER_WATT,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key="ampsOut",
name="Amps Out",
device_class=DEVICE_CLASS_CURRENT,
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="whOut",
name="WH Out",
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="whStored",
name="WH Stored",
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key="volts",
name="Volts",
device_class=DEVICE_CLASS_VOLTAGE,
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="socPercent",
name="State of Charge Percent",
device_class=DEVICE_CLASS_BATTERY,
unit_of_measurement=PERCENTAGE,
),
SensorEntityDescription(
key="timeToEmptyFull",
name="Time to Empty/Full",
device_class=TIME_MINUTES,
unit_of_measurement=TIME_MINUTES,
),
SensorEntityDescription(
key="temperature",
name="Temperature",
device_class=DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS,
),
SensorEntityDescription(
key="wifiStrength",
name="Wifi Strength",
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
),
SensorEntityDescription(
key="timestamp",
name="Total Run Time",
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
unit_of_measurement=TIME_SECONDS,
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,
),
)

SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
SwitchEntityDescription(
key="v12PortStatus",
name="12V Port Status",
),
SwitchEntityDescription(
key="usbPortStatus",
name="USB Port Status",
),
SwitchEntityDescription(
key="acPortStatus",
name="AC Port Status",
),
)
125 changes: 122 additions & 3 deletions homeassistant/components/goalzero/sensor.py
@@ -1,15 +1,134 @@
"""Support for Goal Zero Yeti Sensors."""
from __future__ import annotations

from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME
from homeassistant.const import (
CONF_NAME,
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,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from . import Yeti, YetiEntity
from .const import DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN, SENSOR_TYPES
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,
unit_of_measurement=POWER_WATT,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key="ampsIn",
name="Amps In",
device_class=DEVICE_CLASS_CURRENT,
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="wattsOut",
name="Watts Out",
device_class=DEVICE_CLASS_POWER,
unit_of_measurement=POWER_WATT,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key="ampsOut",
name="Amps Out",
device_class=DEVICE_CLASS_CURRENT,
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="whOut",
name="WH Out",
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR,
state_class=STATE_CLASS_TOTAL_INCREASING,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="whStored",
name="WH Stored",
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR,
state_class=STATE_CLASS_MEASUREMENT,
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
),
SensorEntityDescription(
key="volts",
name="Volts",
device_class=DEVICE_CLASS_VOLTAGE,
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="socPercent",
name="State of Charge Percent",
device_class=DEVICE_CLASS_BATTERY,
unit_of_measurement=PERCENTAGE,
),
SensorEntityDescription(
key="timeToEmptyFull",
name="Time to Empty/Full",
device_class=TIME_MINUTES,
unit_of_measurement=TIME_MINUTES,
),
SensorEntityDescription(
key="temperature",
name="Temperature",
device_class=DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS,
),
SensorEntityDescription(
key="wifiStrength",
name="Wifi Strength",
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
),
SensorEntityDescription(
key="timestamp",
name="Total Run Time",
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
tkdrob marked this conversation as resolved.
Show resolved Hide resolved
unit_of_measurement=TIME_SECONDS,
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
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,
),
)


async def async_setup_entry(
Expand Down
17 changes: 16 additions & 1 deletion homeassistant/components/goalzero/switch.py
Expand Up @@ -9,7 +9,22 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from . import Yeti, YetiEntity
from .const import DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN, SWITCH_TYPES
from .const import DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN

SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
SwitchEntityDescription(
key="v12PortStatus",
name="12V Port Status",
),
SwitchEntityDescription(
key="usbPortStatus",
name="USB Port Status",
),
SwitchEntityDescription(
key="acPortStatus",
name="AC Port Status",
),
)


async def async_setup_entry(
Expand Down