Skip to content

Commit

Permalink
Add entity translations to Goalzero (#95310)
Browse files Browse the repository at this point in the history
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
  • Loading branch information
3 people committed Oct 6, 2023
1 parent 835982e commit 62802dd
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 28 deletions.
7 changes: 3 additions & 4 deletions homeassistant/components/goalzero/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription(
key="backlight",
name="Backlight",
translation_key="backlight",
icon="mdi:clock-digital",
),
BinarySensorEntityDescription(
key="app_online",
name="App online",
translation_key="app_online",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=EntityCategory.DIAGNOSTIC,
),
BinarySensorEntityDescription(
key="isCharging",
name="Charging",
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
),
BinarySensorEntityDescription(
key="inputDetected",
name="Input detected",
translation_key="input_detected",
device_class=BinarySensorDeviceClass.POWER,
),
)
Expand Down
26 changes: 12 additions & 14 deletions homeassistant/components/goalzero/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,99 +31,97 @@
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="wattsIn",
name="Watts in",
translation_key="watts_in",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="ampsIn",
name="Amps in",
translation_key="amps_in",
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="wattsOut",
name="Watts out",
translation_key="watts_out",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="ampsOut",
name="Amps out",
translation_key="amps_out",
device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="whOut",
name="Wh out",
translation_key="wh_out",
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="whStored",
name="Wh stored",
translation_key="wh_stored",
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL,
),
SensorEntityDescription(
key="volts",
name="Volts",
device_class=SensorDeviceClass.VOLTAGE,
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="socPercent",
name="State of charge percent",
translation_key="soc_percent",
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
),
SensorEntityDescription(
key="timeToEmptyFull",
name="Time to empty/full",
translation_key="time_to_empty_full",
device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.MINUTES,
),
SensorEntityDescription(
key="temperature",
name="Temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
entity_category=EntityCategory.DIAGNOSTIC,
),
SensorEntityDescription(
key="wifiStrength",
name="Wi-Fi strength",
translation_key="wifi_strength",
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
SensorEntityDescription(
key="timestamp",
name="Total run time",
translation_key="timestamp",
native_unit_of_measurement=UnitOfTime.SECONDS,
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
SensorEntityDescription(
key="ssid",
name="Wi-Fi SSID",
translation_key="ssid",
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
SensorEntityDescription(
key="ipAddr",
name="IP address",
translation_key="ip_addr",
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
Expand Down
62 changes: 62 additions & 0 deletions homeassistant/components/goalzero/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,67 @@
"invalid_host": "[%key:common::config_flow::error::invalid_host%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
}
},
"entity": {
"binary_sensor": {
"backlight": {
"name": "Backlight"
},
"app_online": {
"name": "App online"
},
"input_detected": {
"name": "Input detected"
}
},
"sensor": {
"watts_in": {
"name": "Power in"
},
"amps_in": {
"name": "Current in"
},
"watts_out": {
"name": "Power out"
},
"amps_out": {
"name": "Current out"
},
"wh_out": {
"name": "Energy out"
},
"wh_stored": {
"name": "Energy stored"
},
"soc_percent": {
"name": "State of charge percent"
},
"time_to_empty_full": {
"name": "Time to empty/full"
},
"wifi_strength": {
"name": "Wi-Fi strength"
},
"timestamp": {
"name": "Total run time"
},
"ssid": {
"name": "Wi-Fi SSID"
},
"ip_addr": {
"name": "IP address"
}
},
"switch": {
"v12_port_status": {
"name": "12V port status"
},
"usb_port_status": {
"name": "USB port status"
},
"ac_port_status": {
"name": "AC port status"
}
}
}
}
6 changes: 3 additions & 3 deletions homeassistant/components/goalzero/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
SwitchEntityDescription(
key="v12PortStatus",
name="12V port status",
translation_key="v12_port_status",
),
SwitchEntityDescription(
key="usbPortStatus",
name="USB port status",
translation_key="usb_port_status",
),
SwitchEntityDescription(
key="acPortStatus",
name="AC port status",
translation_key="ac_port_status",
),
)

Expand Down
14 changes: 7 additions & 7 deletions tests/components/goalzero/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,41 @@ async def test_sensors(
"""Test we get sensor data."""
await async_init_integration(hass, aioclient_mock)

state = hass.states.get(f"sensor.{DEFAULT_NAME}_watts_in")
state = hass.states.get(f"sensor.{DEFAULT_NAME}_power_in")
assert state.state == "0.0"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
state = hass.states.get(f"sensor.{DEFAULT_NAME}_amps_in")
state = hass.states.get(f"sensor.{DEFAULT_NAME}_current_in")
assert state.state == "0.0"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricCurrent.AMPERE
)
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
state = hass.states.get(f"sensor.{DEFAULT_NAME}_watts_out")
state = hass.states.get(f"sensor.{DEFAULT_NAME}_power_out")
assert state.state == "50.5"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
state = hass.states.get(f"sensor.{DEFAULT_NAME}_amps_out")
state = hass.states.get(f"sensor.{DEFAULT_NAME}_current_out")
assert state.state == "2.1"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricCurrent.AMPERE
)
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
state = hass.states.get(f"sensor.{DEFAULT_NAME}_wh_out")
state = hass.states.get(f"sensor.{DEFAULT_NAME}_energy_out")
assert state.state == "5.23"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.WATT_HOUR
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING
state = hass.states.get(f"sensor.{DEFAULT_NAME}_wh_stored")
state = hass.states.get(f"sensor.{DEFAULT_NAME}_energy_stored")
assert state.state == "1330"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.WATT_HOUR
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL
state = hass.states.get(f"sensor.{DEFAULT_NAME}_volts")
state = hass.states.get(f"sensor.{DEFAULT_NAME}_voltage")
assert state.state == "12.0"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.VOLTAGE
assert (
Expand Down

0 comments on commit 62802dd

Please sign in to comment.