Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Support for Goal Zero Yeti Sensors."""
2 
3 from __future__ import annotations
4 
5 from typing import cast
6 
8  SensorDeviceClass,
9  SensorEntity,
10  SensorEntityDescription,
11  SensorStateClass,
12 )
13 from homeassistant.const import (
14  PERCENTAGE,
15  SIGNAL_STRENGTH_DECIBELS,
16  EntityCategory,
17  UnitOfElectricCurrent,
18  UnitOfElectricPotential,
19  UnitOfEnergy,
20  UnitOfPower,
21  UnitOfTemperature,
22  UnitOfTime,
23 )
24 from homeassistant.core import HomeAssistant
25 from homeassistant.helpers.entity_platform import AddEntitiesCallback
26 from homeassistant.helpers.typing import StateType
27 
28 from .coordinator import GoalZeroConfigEntry
29 from .entity import GoalZeroEntity
30 
31 SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
33  key="wattsIn",
34  translation_key="watts_in",
35  device_class=SensorDeviceClass.POWER,
36  native_unit_of_measurement=UnitOfPower.WATT,
37  state_class=SensorStateClass.MEASUREMENT,
38  ),
40  key="ampsIn",
41  translation_key="amps_in",
42  device_class=SensorDeviceClass.CURRENT,
43  native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
44  state_class=SensorStateClass.MEASUREMENT,
45  entity_registry_enabled_default=False,
46  ),
48  key="wattsOut",
49  translation_key="watts_out",
50  device_class=SensorDeviceClass.POWER,
51  native_unit_of_measurement=UnitOfPower.WATT,
52  state_class=SensorStateClass.MEASUREMENT,
53  ),
55  key="ampsOut",
56  translation_key="amps_out",
57  device_class=SensorDeviceClass.CURRENT,
58  native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
59  state_class=SensorStateClass.MEASUREMENT,
60  entity_registry_enabled_default=False,
61  ),
63  key="whOut",
64  translation_key="wh_out",
65  device_class=SensorDeviceClass.ENERGY,
66  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
67  state_class=SensorStateClass.TOTAL_INCREASING,
68  entity_registry_enabled_default=False,
69  ),
71  key="whStored",
72  translation_key="wh_stored",
73  device_class=SensorDeviceClass.ENERGY,
74  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
75  state_class=SensorStateClass.TOTAL,
76  ),
78  key="volts",
79  device_class=SensorDeviceClass.VOLTAGE,
80  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
81  entity_registry_enabled_default=False,
82  ),
84  key="socPercent",
85  translation_key="soc_percent",
86  device_class=SensorDeviceClass.BATTERY,
87  native_unit_of_measurement=PERCENTAGE,
88  ),
90  key="timeToEmptyFull",
91  translation_key="time_to_empty_full",
92  device_class=SensorDeviceClass.DURATION,
93  native_unit_of_measurement=UnitOfTime.MINUTES,
94  ),
96  key="temperature",
97  device_class=SensorDeviceClass.TEMPERATURE,
98  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
99  entity_category=EntityCategory.DIAGNOSTIC,
100  ),
102  key="wifiStrength",
103  translation_key="wifi_strength",
104  device_class=SensorDeviceClass.SIGNAL_STRENGTH,
105  native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
106  entity_registry_enabled_default=False,
107  entity_category=EntityCategory.DIAGNOSTIC,
108  ),
110  key="timestamp",
111  translation_key="timestamp",
112  native_unit_of_measurement=UnitOfTime.SECONDS,
113  entity_registry_enabled_default=False,
114  entity_category=EntityCategory.DIAGNOSTIC,
115  ),
117  key="ssid",
118  translation_key="ssid",
119  entity_registry_enabled_default=False,
120  entity_category=EntityCategory.DIAGNOSTIC,
121  ),
123  key="ipAddr",
124  translation_key="ip_addr",
125  entity_registry_enabled_default=False,
126  entity_category=EntityCategory.DIAGNOSTIC,
127  ),
128 )
129 
130 
132  hass: HomeAssistant,
133  entry: GoalZeroConfigEntry,
134  async_add_entities: AddEntitiesCallback,
135 ) -> None:
136  """Set up the Goal Zero Yeti sensor."""
138  GoalZeroSensor(entry.runtime_data, description) for description in SENSOR_TYPES
139  )
140 
141 
143  """Representation of a Goal Zero Yeti sensor."""
144 
145  @property
146  def native_value(self) -> StateType:
147  """Return the state."""
148  return cast(StateType, self._api_api.data[self.entity_descriptionentity_description.key])
None async_setup_entry(HomeAssistant hass, GoalZeroConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:135