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
20 changes: 18 additions & 2 deletions homeassistant/components/opower/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfEnergy, UnitOfVolume
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
Expand Down Expand Up @@ -71,6 +72,8 @@ class OpowerEntityDescription(SensorEntityDescription, OpowerEntityDescriptionMi
key="elec_cost_to_date",
name="Current bill electric cost to date",
device_class=SensorDeviceClass.MONETARY,
native_unit_of_measurement="USD",
suggested_unit_of_measurement="USD",
state_class=SensorStateClass.TOTAL,
suggested_display_precision=0,
value_fn=lambda data: data.cost_to_date,
Expand All @@ -79,6 +82,8 @@ class OpowerEntityDescription(SensorEntityDescription, OpowerEntityDescriptionMi
key="elec_forecasted_cost",
name="Current bill electric forecasted cost",
device_class=SensorDeviceClass.MONETARY,
native_unit_of_measurement="USD",
suggested_unit_of_measurement="USD",
state_class=SensorStateClass.TOTAL,
suggested_display_precision=0,
value_fn=lambda data: data.forecasted_cost,
Expand All @@ -87,6 +92,8 @@ class OpowerEntityDescription(SensorEntityDescription, OpowerEntityDescriptionMi
key="elec_typical_cost",
name="Typical monthly electric cost",
device_class=SensorDeviceClass.MONETARY,
native_unit_of_measurement="USD",
suggested_unit_of_measurement="USD",
state_class=SensorStateClass.TOTAL,
suggested_display_precision=0,
value_fn=lambda data: data.typical_cost,
Expand Down Expand Up @@ -127,6 +134,8 @@ class OpowerEntityDescription(SensorEntityDescription, OpowerEntityDescriptionMi
key="gas_cost_to_date",
name="Current bill gas cost to date",
device_class=SensorDeviceClass.MONETARY,
native_unit_of_measurement="USD",
suggested_unit_of_measurement="USD",
state_class=SensorStateClass.TOTAL,
suggested_display_precision=0,
value_fn=lambda data: data.cost_to_date,
Expand All @@ -135,6 +144,8 @@ class OpowerEntityDescription(SensorEntityDescription, OpowerEntityDescriptionMi
key="gas_forecasted_cost",
name="Current bill gas forecasted cost",
device_class=SensorDeviceClass.MONETARY,
native_unit_of_measurement="USD",
suggested_unit_of_measurement="USD",
state_class=SensorStateClass.TOTAL,
suggested_display_precision=0,
value_fn=lambda data: data.forecasted_cost,
Expand All @@ -143,6 +154,8 @@ class OpowerEntityDescription(SensorEntityDescription, OpowerEntityDescriptionMi
key="gas_typical_cost",
name="Typical monthly gas cost",
device_class=SensorDeviceClass.MONETARY,
native_unit_of_measurement="USD",
suggested_unit_of_measurement="USD",
state_class=SensorStateClass.TOTAL,
suggested_display_precision=0,
value_fn=lambda data: data.typical_cost,
Expand All @@ -165,6 +178,7 @@ async def async_setup_entry(
name=f"{forecast.account.meter_type.name} account {forecast.account.utility_account_id}",
manufacturer="Opower",
model=coordinator.api.utility.name(),
entry_type=DeviceEntryType.SERVICE,
)
sensors: tuple[OpowerEntityDescription, ...] = ()
if (
Expand All @@ -191,9 +205,11 @@ async def async_setup_entry(
async_add_entities(entities)


class OpowerSensor(SensorEntity, CoordinatorEntity[OpowerCoordinator]):
class OpowerSensor(CoordinatorEntity[OpowerCoordinator], SensorEntity):
"""Representation of an Opower sensor."""

entity_description: OpowerEntityDescription

def __init__(
self,
coordinator: OpowerCoordinator,
Expand All @@ -204,7 +220,7 @@ def __init__(
) -> None:
"""Initialize the sensor."""
super().__init__(coordinator)
self.entity_description: OpowerEntityDescription = description
self.entity_description = description
self._attr_unique_id = f"{device_id}_{description.key}"
self._attr_device_info = device
self.utility_account_id = utility_account_id
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/opower/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/components/opower/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest

from homeassistant.components.opower.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry
Expand All @@ -19,7 +18,6 @@ def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
"username": "test-username",
"password": "test-password",
},
state=ConfigEntryState.LOADED,
)
config_entry.add_to_hass(hass)
return config_entry
2 changes: 2 additions & 0 deletions tests/components/opower/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homeassistant import config_entries
from homeassistant.components.opower.const import DOMAIN
from homeassistant.components.recorder import Recorder
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType

Expand Down Expand Up @@ -172,6 +173,7 @@ async def test_form_valid_reauth(
mock_config_entry: MockConfigEntry,
) -> None:
"""Test that we can handle a valid reauth."""
mock_config_entry.state = ConfigEntryState.LOADED
mock_config_entry.async_start_reauth(hass)
await hass.async_block_till_done()

Expand Down