Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/ambient_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CONCENTRATION_PARTS_PER_MILLION,
CONF_API_KEY,
EVENT_HOMEASSISTANT_STOP,
POWER_WATT,
SPEED_MILES_PER_HOUR,
TEMP_FAHRENHEIT,
UNIT_PERCENTAGE,
Expand Down Expand Up @@ -200,7 +201,7 @@
TYPE_SOILTEMP7F: ("Soil Temp 7", TEMP_FAHRENHEIT, TYPE_SENSOR, "temperature"),
TYPE_SOILTEMP8F: ("Soil Temp 8", TEMP_FAHRENHEIT, TYPE_SENSOR, "temperature"),
TYPE_SOILTEMP9F: ("Soil Temp 9", TEMP_FAHRENHEIT, TYPE_SENSOR, "temperature"),
TYPE_SOLARRADIATION: ("Solar Rad", "W/m^2", TYPE_SENSOR, None),
TYPE_SOLARRADIATION: ("Solar Rad", f"{POWER_WATT}/m^2", TYPE_SENSOR, None),
TYPE_SOLARRADIATION_LX: ("Solar Rad (lx)", "lx", TYPE_SENSOR, "illuminance"),
TYPE_TEMP10F: ("Temp 10", TEMP_FAHRENHEIT, TYPE_SENSOR, "temperature"),
TYPE_TEMP1F: ("Temp 1", TEMP_FAHRENHEIT, TYPE_SENSOR, "temperature"),
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/aqualogic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_MONITORED_CONDITIONS,
POWER_WATT,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UNIT_PERCENTAGE,
Expand All @@ -21,7 +22,7 @@
TEMP_UNITS = [TEMP_CELSIUS, TEMP_FAHRENHEIT]
PERCENT_UNITS = [UNIT_PERCENTAGE, UNIT_PERCENTAGE]
SALT_UNITS = ["g/L", "PPM"]
WATT_UNITS = ["W", "W"]
WATT_UNITS = [POWER_WATT, POWER_WATT]
NO_UNITS = [None, None]

# sensor_type [ description, unit, icon ]
Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/bom/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import voluptuous as vol

from homeassistant.components.weather import PLATFORM_SCHEMA, WeatherEntity
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS
from homeassistant.const import (
CONF_LATITUDE,
CONF_LONGITUDE,
CONF_NAME,
POWER_WATT,
TEMP_CELSIUS,
)
from homeassistant.helpers import config_validation as cv

# Reuse data and API logic from the sensor implementation
Expand Down Expand Up @@ -99,7 +105,7 @@ def wind_bearing(self):
"SSW",
"SW",
"WSW",
"W",
POWER_WATT,
"WNW",
"NW",
"NNW",
Expand Down
22 changes: 14 additions & 8 deletions homeassistant/components/growatt_server/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CONF_PASSWORD,
CONF_USERNAME,
ENERGY_KILO_WATT_HOUR,
POWER_WATT,
UNIT_VOLT,
)
import homeassistant.helpers.config_validation as cv
Expand All @@ -35,14 +36,14 @@
"todayEnergy",
"power",
),
"total_output_power": ("Output Power", "W", "invTodayPpv", "power"),
"total_output_power": ("Output Power", POWER_WATT, "invTodayPpv", "power"),
"total_energy_output": (
"Lifetime energy output",
ENERGY_KILO_WATT_HOUR,
"totalEnergy",
"power",
),
"total_maximum_output": ("Maximum power", "W", "nominalPower", "power"),
"total_maximum_output": ("Maximum power", POWER_WATT, "nominalPower", "power"),
}

INVERTER_SENSOR_TYPES = {
Expand All @@ -60,19 +61,24 @@
),
"inverter_voltage_input_1": ("Input 1 voltage", UNIT_VOLT, "vpv1", None),
"inverter_amperage_input_1": ("Input 1 Amperage", "A", "ipv1", None),
"inverter_wattage_input_1": ("Input 1 Wattage", "W", "ppv1", "power"),
"inverter_wattage_input_1": ("Input 1 Wattage", POWER_WATT, "ppv1", "power"),
"inverter_voltage_input_2": ("Input 2 voltage", UNIT_VOLT, "vpv2", None),
"inverter_amperage_input_2": ("Input 2 Amperage", "A", "ipv2", None),
"inverter_wattage_input_2": ("Input 2 Wattage", "W", "ppv2", "power"),
"inverter_wattage_input_2": ("Input 2 Wattage", POWER_WATT, "ppv2", "power"),
"inverter_voltage_input_3": ("Input 3 voltage", UNIT_VOLT, "vpv3", None),
"inverter_amperage_input_3": ("Input 3 Amperage", "A", "ipv3", None),
"inverter_wattage_input_3": ("Input 3 Wattage", "W", "ppv3", "power"),
"inverter_internal_wattage": ("Internal wattage", "W", "ppv", "power"),
"inverter_wattage_input_3": ("Input 3 Wattage", POWER_WATT, "ppv3", "power"),
"inverter_internal_wattage": ("Internal wattage", POWER_WATT, "ppv", "power"),
"inverter_reactive_voltage": ("Reactive voltage", UNIT_VOLT, "vacr", None),
"inverter_inverter_reactive_amperage": ("Reactive amperage", "A", "iacr", None),
"inverter_frequency": ("AC frequency", "Hz", "fac", None),
"inverter_current_wattage": ("Output power", "W", "pac", "power"),
"inverter_current_reactive_wattage": ("Reactive wattage", "W", "pacr", "power"),
"inverter_current_wattage": ("Output power", POWER_WATT, "pac", "power"),
"inverter_current_reactive_wattage": (
"Reactive wattage",
POWER_WATT,
"pacr",
"power",
),
}

SENSOR_TYPES = {**TOTAL_SENSOR_TYPES, **INVERTER_SENSOR_TYPES}
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/homematicip_cloud/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def _get_wind_direction(wind_direction_degree: float) -> str:
if 236.25 <= wind_direction_degree < 258.75:
return "WSW"
if 258.75 <= wind_direction_degree < 281.25:
return "W"
return POWER_WATT
if 281.25 <= wind_direction_degree < 303.75:
return "WNW"
if 303.75 <= wind_direction_degree < 326.25:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/isy994/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"71": UNIT_UV_INDEX,
"72": UNIT_VOLT,
"73": POWER_WATT,
"74": "W/m²",
"74": f"{POWER_WATT}/m²",
"75": "weekday",
"76": "Wind Direction (°)",
"77": TIME_YEARS,
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/solarlog/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@
"mdi:solar-power",
],
"capacity": ["CAPACITY", "capacity", UNIT_PERCENTAGE, "mdi:solar-power"],
"efficiency": ["EFFICIENCY", "efficiency", "% W/Wp", "mdi:solar-power"],
"efficiency": [
"EFFICIENCY",
"efficiency",
f"% {POWER_WATT}/{POWER_WATT}p",
"mdi:solar-power",
],
"power_available": [
"powerAVAILABLE",
"power available",
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/tibber/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import aiohttp

from homeassistant.const import POWER_WATT
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle, dt as dt_util
Expand Down Expand Up @@ -194,7 +195,7 @@ def icon(self):
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity."""
return "W"
return POWER_WATT

@property
def unique_id(self):
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/waterfurnace/sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Support for Waterfurnace."""

from homeassistant.components.sensor import ENTITY_ID_FORMAT
from homeassistant.const import TEMP_FAHRENHEIT, UNIT_PERCENTAGE
from homeassistant.const import POWER_WATT, TEMP_FAHRENHEIT, UNIT_PERCENTAGE
from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify
Expand All @@ -24,7 +24,7 @@ def __init__(

SENSORS = [
WFSensorConfig("Furnace Mode", "mode"),
WFSensorConfig("Total Power", "totalunitpower", "mdi:flash", "W"),
WFSensorConfig("Total Power", "totalunitpower", "mdi:flash", POWER_WATT),
WFSensorConfig(
"Active Setpoint", "tstatactivesetpoint", "mdi:thermometer", TEMP_FAHRENHEIT
),
Expand All @@ -39,10 +39,10 @@ def __init__(
WFSensorConfig(
"Humidity", "tstatrelativehumidity", "mdi:water-percent", UNIT_PERCENTAGE
),
WFSensorConfig("Compressor Power", "compressorpower", "mdi:flash", "W"),
WFSensorConfig("Fan Power", "fanpower", "mdi:flash", "W"),
WFSensorConfig("Aux Power", "auxpower", "mdi:flash", "W"),
WFSensorConfig("Loop Pump Power", "looppumppower", "mdi:flash", "W"),
WFSensorConfig("Compressor Power", "compressorpower", "mdi:flash", POWER_WATT),
WFSensorConfig("Fan Power", "fanpower", "mdi:flash", POWER_WATT),
WFSensorConfig("Aux Power", "auxpower", "mdi:flash", POWER_WATT),
WFSensorConfig("Loop Pump Power", "looppumppower", "mdi:flash", POWER_WATT),
WFSensorConfig("Compressor Speed", "actualcompressorspeed", "mdi:speedometer"),
WFSensorConfig("Fan Speed", "airflowcurrentspeed", "mdi:fan"),
]
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@
UNIT_VOLT = "V"

# Energy units
ENERGY_KILO_WATT_HOUR = "kWh"
ENERGY_WATT_HOUR = "Wh"
ENERGY_WATT_HOUR = f"{POWER_WATT}h"
ENERGY_KILO_WATT_HOUR = f"k{ENERGY_WATT_HOUR}"

# Temperature units
TEMP_CELSIUS = "°C"
Expand Down
6 changes: 3 additions & 3 deletions tests/components/derivative/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import timedelta
from unittest.mock import patch

from homeassistant.const import TIME_HOURS, TIME_MINUTES, TIME_SECONDS
from homeassistant.const import POWER_WATT, TIME_HOURS, TIME_MINUTES, TIME_SECONDS
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util

Expand Down Expand Up @@ -192,14 +192,14 @@ async def test_prefix(hass):

entity_id = config["sensor"]["source"]
hass.states.async_set(
entity_id, 1000, {"unit_of_measurement": "W"}, force_update=True
entity_id, 1000, {"unit_of_measurement": POWER_WATT}, force_update=True
)
await hass.async_block_till_done()

now = dt_util.utcnow() + timedelta(seconds=3600)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.states.async_set(
entity_id, 1000, {"unit_of_measurement": "W"}, force_update=True
entity_id, 1000, {"unit_of_measurement": POWER_WATT}, force_update=True
)
await hass.async_block_till_done()

Expand Down
2 changes: 1 addition & 1 deletion tests/components/homematicip_cloud/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async def test_hmip_windspeed_sensor(hass, default_mock_hap_factory):
205: "SSW",
227.5: "SW",
250: "WSW",
272.5: "W",
272.5: POWER_WATT,
295: "WNW",
317.5: "NW",
340: "NNW",
Expand Down
6 changes: 3 additions & 3 deletions tests/components/integration/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import timedelta
from unittest.mock import patch

from homeassistant.const import ENERGY_KILO_WATT_HOUR, TIME_SECONDS
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT, TIME_SECONDS
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util

Expand Down Expand Up @@ -155,13 +155,13 @@ async def test_prefix(hass):
assert await async_setup_component(hass, "sensor", config)

entity_id = config["sensor"]["source"]
hass.states.async_set(entity_id, 1000, {"unit_of_measurement": "W"})
hass.states.async_set(entity_id, 1000, {"unit_of_measurement": POWER_WATT})
await hass.async_block_till_done()

now = dt_util.utcnow() + timedelta(seconds=3600)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.states.async_set(
entity_id, 1000, {"unit_of_measurement": "W"}, force_update=True
entity_id, 1000, {"unit_of_measurement": POWER_WATT}, force_update=True
)
await hass.async_block_till_done()

Expand Down
9 changes: 5 additions & 4 deletions tests/components/zha/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CONF_UNIT_SYSTEM,
CONF_UNIT_SYSTEM_IMPERIAL,
CONF_UNIT_SYSTEM_METRIC,
POWER_WATT,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
TEMP_CELSIUS,
Expand Down Expand Up @@ -76,17 +77,17 @@ async def async_test_electrical_measurement(hass, cluster, entity_id):
) as divisor_mock:
divisor_mock.return_value = 1
await send_attributes_report(hass, cluster, {0: 1, 1291: 100, 10: 1000})
assert_state(hass, entity_id, "100", "W")
assert_state(hass, entity_id, "100", POWER_WATT)

await send_attributes_report(hass, cluster, {0: 1, 1291: 99, 10: 1000})
assert_state(hass, entity_id, "99", "W")
assert_state(hass, entity_id, "99", POWER_WATT)

divisor_mock.return_value = 10
await send_attributes_report(hass, cluster, {0: 1, 1291: 1000, 10: 5000})
assert_state(hass, entity_id, "100", "W")
assert_state(hass, entity_id, "100", POWER_WATT)

await send_attributes_report(hass, cluster, {0: 1, 1291: 99, 10: 5000})
assert_state(hass, entity_id, "9.9", "W")
assert_state(hass, entity_id, "9.9", POWER_WATT)


@pytest.mark.parametrize(
Expand Down