Add entity translations to Goalzero (#95310)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Robert Hillis 2023-10-06 08:01:21 -04:00 committed by GitHub
parent 835982ebe5
commit 62802dd487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 28 deletions

View file

@ -21,23 +21,22 @@ PARALLEL_UPDATES = 0
BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = ( BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="backlight", key="backlight",
name="Backlight", translation_key="backlight",
icon="mdi:clock-digital", icon="mdi:clock-digital",
), ),
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="app_online", key="app_online",
name="App online", translation_key="app_online",
device_class=BinarySensorDeviceClass.CONNECTIVITY, device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="isCharging", key="isCharging",
name="Charging",
device_class=BinarySensorDeviceClass.BATTERY_CHARGING, device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
), ),
BinarySensorEntityDescription( BinarySensorEntityDescription(
key="inputDetected", key="inputDetected",
name="Input detected", translation_key="input_detected",
device_class=BinarySensorDeviceClass.POWER, device_class=BinarySensorDeviceClass.POWER,
), ),
) )

View file

@ -31,14 +31,14 @@ from .entity import GoalZeroEntity
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="wattsIn", key="wattsIn",
name="Watts in", translation_key="watts_in",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="ampsIn", key="ampsIn",
name="Amps in", translation_key="amps_in",
device_class=SensorDeviceClass.CURRENT, device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -46,14 +46,14 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
), ),
SensorEntityDescription( SensorEntityDescription(
key="wattsOut", key="wattsOut",
name="Watts out", translation_key="watts_out",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="ampsOut", key="ampsOut",
name="Amps out", translation_key="amps_out",
device_class=SensorDeviceClass.CURRENT, device_class=SensorDeviceClass.CURRENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -61,7 +61,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
), ),
SensorEntityDescription( SensorEntityDescription(
key="whOut", key="whOut",
name="Wh out", translation_key="wh_out",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
@ -69,40 +69,38 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
), ),
SensorEntityDescription( SensorEntityDescription(
key="whStored", key="whStored",
name="Wh stored", translation_key="wh_stored",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
state_class=SensorStateClass.TOTAL, state_class=SensorStateClass.TOTAL,
), ),
SensorEntityDescription( SensorEntityDescription(
key="volts", key="volts",
name="Volts",
device_class=SensorDeviceClass.VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
native_unit_of_measurement=UnitOfElectricPotential.VOLT, native_unit_of_measurement=UnitOfElectricPotential.VOLT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="socPercent", key="socPercent",
name="State of charge percent", translation_key="soc_percent",
device_class=SensorDeviceClass.BATTERY, device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
), ),
SensorEntityDescription( SensorEntityDescription(
key="timeToEmptyFull", key="timeToEmptyFull",
name="Time to empty/full", translation_key="time_to_empty_full",
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
), ),
SensorEntityDescription( SensorEntityDescription(
key="temperature", key="temperature",
name="Temperature",
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
SensorEntityDescription( SensorEntityDescription(
key="wifiStrength", key="wifiStrength",
name="Wi-Fi strength", translation_key="wifi_strength",
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
@ -110,20 +108,20 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
), ),
SensorEntityDescription( SensorEntityDescription(
key="timestamp", key="timestamp",
name="Total run time", translation_key="timestamp",
native_unit_of_measurement=UnitOfTime.SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
SensorEntityDescription( SensorEntityDescription(
key="ssid", key="ssid",
name="Wi-Fi SSID", translation_key="ssid",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
SensorEntityDescription( SensorEntityDescription(
key="ipAddr", key="ipAddr",
name="IP address", translation_key="ip_addr",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),

View file

@ -22,5 +22,67 @@
"invalid_host": "[%key:common::config_flow::error::invalid_host%]", "invalid_host": "[%key:common::config_flow::error::invalid_host%]",
"unknown": "[%key:common::config_flow::error::unknown%]" "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"
}
}
} }
} }

View file

@ -14,15 +14,15 @@ from .entity import GoalZeroEntity
SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = ( SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
SwitchEntityDescription( SwitchEntityDescription(
key="v12PortStatus", key="v12PortStatus",
name="12V port status", translation_key="v12_port_status",
), ),
SwitchEntityDescription( SwitchEntityDescription(
key="usbPortStatus", key="usbPortStatus",
name="USB port status", translation_key="usb_port_status",
), ),
SwitchEntityDescription( SwitchEntityDescription(
key="acPortStatus", key="acPortStatus",
name="AC port status", translation_key="ac_port_status",
), ),
) )

View file

@ -33,41 +33,41 @@ async def test_sensors(
"""Test we get sensor data.""" """Test we get sensor data."""
await async_init_integration(hass, aioclient_mock) 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.state == "0.0"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT 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.state == "0.0"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT
assert ( assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricCurrent.AMPERE state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricCurrent.AMPERE
) )
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT 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.state == "50.5"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT 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.state == "2.1"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT
assert ( assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricCurrent.AMPERE state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricCurrent.AMPERE
) )
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT 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.state == "5.23"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY 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_UNIT_OF_MEASUREMENT) == UnitOfEnergy.WATT_HOUR
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL_INCREASING 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.state == "1330"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY 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_UNIT_OF_MEASUREMENT) == UnitOfEnergy.WATT_HOUR
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.TOTAL 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.state == "12.0"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.VOLTAGE assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.VOLTAGE
assert ( assert (