Merge pull request 'chore: rename integration and references in unit tests' (#1) from customise-blueprint into main

Reviewed-on: #1
This commit is contained in:
alex 2021-12-11 12:07:43 +00:00 committed by Alex Berry
commit 8da76a6b11
Signed by: alex
GPG Key ID: D5BB9F05EB47A31A
19 changed files with 37 additions and 37 deletions

View File

@ -14,7 +14,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .api import IntegrationBlueprintApiClient from .api import OctopusEnergyApiClient
from .const import ( from .const import (
CONF_PASSWORD, CONF_PASSWORD,
@ -44,7 +44,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
password = entry.data.get(CONF_PASSWORD) password = entry.data.get(CONF_PASSWORD)
session = async_get_clientsession(hass) session = async_get_clientsession(hass)
client = IntegrationBlueprintApiClient(username, password, session) client = OctopusEnergyApiClient(username, password, session)
coordinator = BlueprintDataUpdateCoordinator(hass, client=client) coordinator = BlueprintDataUpdateCoordinator(hass, client=client)
await coordinator.async_refresh() await coordinator.async_refresh()
@ -69,7 +69,7 @@ class BlueprintDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching data from the API.""" """Class to manage fetching data from the API."""
def __init__( def __init__(
self, hass: HomeAssistant, client: IntegrationBlueprintApiClient self, hass: HomeAssistant, client: OctopusEnergyApiClient
) -> None: ) -> None:
"""Initialize.""" """Initialize."""
self.api = client self.api = client

View File

@ -14,7 +14,7 @@ _LOGGER: logging.Logger = logging.getLogger(__package__)
HEADERS = {"Content-type": "application/json; charset=UTF-8"} HEADERS = {"Content-type": "application/json; charset=UTF-8"}
class IntegrationBlueprintApiClient: class OctopusEnergyApiClient:
def __init__( def __init__(
self, username: str, password: str, session: aiohttp.ClientSession self, username: str, password: str, session: aiohttp.ClientSession
) -> None: ) -> None:

View File

@ -7,16 +7,16 @@ from .const import (
DEFAULT_NAME, DEFAULT_NAME,
DOMAIN, DOMAIN,
) )
from .entity import IntegrationBlueprintEntity from .entity import OctopusEnergyEntity
async def async_setup_entry(hass, entry, async_add_devices): async def async_setup_entry(hass, entry, async_add_devices):
"""Setup binary_sensor platform.""" """Setup binary_sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id] coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([IntegrationBlueprintBinarySensor(coordinator, entry)]) async_add_devices([OctopusEnergyBinarySensor(coordinator, entry)])
class IntegrationBlueprintBinarySensor(IntegrationBlueprintEntity, BinarySensorEntity): class OctopusEnergyBinarySensor(OctopusEnergyEntity, BinarySensorEntity):
"""integration_blueprint binary_sensor class.""" """integration_blueprint binary_sensor class."""
@property @property

View File

@ -4,7 +4,7 @@ from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.aiohttp_client import async_create_clientsession
import voluptuous as vol import voluptuous as vol
from .api import IntegrationBlueprintApiClient from .api import OctopusEnergyApiClient
from .const import ( from .const import (
CONF_PASSWORD, CONF_PASSWORD,
CONF_USERNAME, CONF_USERNAME,
@ -73,7 +73,7 @@ class BlueprintFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Return true if credentials is valid.""" """Return true if credentials is valid."""
try: try:
session = async_create_clientsession(self.hass) session = async_create_clientsession(self.hass)
client = IntegrationBlueprintApiClient(username, password, session) client = OctopusEnergyApiClient(username, password, session)
await client.async_get_data() await client.async_get_data()
return True return True
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except

View File

@ -4,7 +4,7 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN, NAME, VERSION, ATTRIBUTION from .const import DOMAIN, NAME, VERSION, ATTRIBUTION
class IntegrationBlueprintEntity(CoordinatorEntity): class OctopusEnergyEntity(CoordinatorEntity):
def __init__(self, coordinator, config_entry): def __init__(self, coordinator, config_entry):
super().__init__(coordinator) super().__init__(coordinator)
self.config_entry = config_entry self.config_entry = config_entry

View File

@ -1,15 +1,15 @@
"""Sensor platform for integration_blueprint.""" """Sensor platform for integration_blueprint."""
from .const import DEFAULT_NAME, DOMAIN, ICON, SENSOR from .const import DEFAULT_NAME, DOMAIN, ICON, SENSOR
from .entity import IntegrationBlueprintEntity from .entity import OctopusEnergyEntity
async def async_setup_entry(hass, entry, async_add_devices): async def async_setup_entry(hass, entry, async_add_devices):
"""Setup sensor platform.""" """Setup sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id] coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([IntegrationBlueprintSensor(coordinator, entry)]) async_add_devices([OctopusEnergySensor(coordinator, entry)])
class IntegrationBlueprintSensor(IntegrationBlueprintEntity): class OctopusEnergySensor(OctopusEnergyEntity):
"""integration_blueprint Sensor class.""" """integration_blueprint Sensor class."""
@property @property

View File

@ -2,16 +2,16 @@
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from .const import DEFAULT_NAME, DOMAIN, ICON, SWITCH from .const import DEFAULT_NAME, DOMAIN, ICON, SWITCH
from .entity import IntegrationBlueprintEntity from .entity import OctopusEnergyEntity
async def async_setup_entry(hass, entry, async_add_devices): async def async_setup_entry(hass, entry, async_add_devices):
"""Setup sensor platform.""" """Setup sensor platform."""
coordinator = hass.data[DOMAIN][entry.entry_id] coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([IntegrationBlueprintBinarySwitch(coordinator, entry)]) async_add_devices([OctopusEnergyBinarySwitch(coordinator, entry)])
class IntegrationBlueprintBinarySwitch(IntegrationBlueprintEntity, SwitchEntity): class OctopusEnergyBinarySwitch(OctopusEnergyEntity, SwitchEntity):
"""integration_blueprint switch class.""" """integration_blueprint switch class."""
async def async_turn_on(self, **kwargs): # pylint: disable=unused-argument async def async_turn_on(self, **kwargs): # pylint: disable=unused-argument

View File

@ -1 +1 @@
"""Tests for integration_blueprint integration.""" """Tests for octopusenergy integration."""

View File

@ -1,4 +1,4 @@
"""Global fixtures for integration_blueprint integration.""" """Global fixtures for octopusenergy integration."""
# Fixtures allow you to replace functions with a Mock object. You can perform # Fixtures allow you to replace functions with a Mock object. You can perform
# many options via the Mock to reflect a particular behavior from the original # many options via the Mock to reflect a particular behavior from the original
# function that you want to see without going through the function's actual logic. # function that you want to see without going through the function's actual logic.
@ -46,7 +46,7 @@ def skip_notifications_fixture():
def bypass_get_data_fixture(): def bypass_get_data_fixture():
"""Skip calls to get data from API.""" """Skip calls to get data from API."""
with patch( with patch(
"custom_components.integration_blueprint.IntegrationBlueprintApiClient.async_get_data" "custom_components.octopusenergy.OctopusEnergyApiClient.async_get_data"
): ):
yield yield
@ -57,7 +57,7 @@ def bypass_get_data_fixture():
def error_get_data_fixture(): def error_get_data_fixture():
"""Simulate error when retrieving data from API.""" """Simulate error when retrieving data from API."""
with patch( with patch(
"custom_components.integration_blueprint.IntegrationBlueprintApiClient.async_get_data", "custom_components.octopusenergy.OctopusEnergyApiClient.async_get_data",
side_effect=Exception, side_effect=Exception,
): ):
yield yield

View File

@ -1,5 +1,5 @@
"""Constants for integration_blueprint tests.""" """Constants for octopusenergy tests."""
from custom_components.integration_blueprint.const import CONF_PASSWORD, CONF_USERNAME from custom_components.octopusenergy.const import CONF_PASSWORD, CONF_USERNAME
# Mock config data to be used across multiple tests # Mock config data to be used across multiple tests
MOCK_CONFIG = {CONF_USERNAME: "test_username", CONF_PASSWORD: "test_password"} MOCK_CONFIG = {CONF_USERNAME: "test_username", CONF_PASSWORD: "test_password"}

View File

@ -1,17 +1,17 @@
"""Tests for integration_blueprint api.""" """Tests for octopusenergy api."""
import asyncio import asyncio
import aiohttp import aiohttp
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from custom_components.integration_blueprint.api import IntegrationBlueprintApiClient from custom_components.octopusenergy.api import OctopusEnergyApiClient
async def test_api(hass, aioclient_mock, caplog): async def test_api(hass, aioclient_mock, caplog):
"""Test API calls.""" """Test API calls."""
# To test the api submodule, we first create an instance of our API client # To test the api submodule, we first create an instance of our API client
api = IntegrationBlueprintApiClient("test", "test", async_get_clientsession(hass)) api = OctopusEnergyApiClient("test", "test", async_get_clientsession(hass))
# Use aioclient_mock which is provided by `pytest_homeassistant_custom_components` # Use aioclient_mock which is provided by `pytest_homeassistant_custom_components`
# to mock responses to aiohttp requests. In this case we are telling the mock to # to mock responses to aiohttp requests. In this case we are telling the mock to

View File

@ -1,11 +1,11 @@
"""Test integration_blueprint config flow.""" """Test octopusenergy config flow."""
from unittest.mock import patch from unittest.mock import patch
from homeassistant import config_entries, data_entry_flow from homeassistant import config_entries, data_entry_flow
import pytest import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components.integration_blueprint.const import ( from custom_components.octopusenergy.const import (
BINARY_SENSOR, BINARY_SENSOR,
DOMAIN, DOMAIN,
PLATFORMS, PLATFORMS,
@ -23,10 +23,10 @@ from .const import MOCK_CONFIG
def bypass_setup_fixture(): def bypass_setup_fixture():
"""Prevent setup.""" """Prevent setup."""
with patch( with patch(
"custom_components.integration_blueprint.async_setup", "custom_components.octopusenergy.async_setup",
return_value=True, return_value=True,
), patch( ), patch(
"custom_components.integration_blueprint.async_setup_entry", "custom_components.octopusenergy.async_setup_entry",
return_value=True, return_value=True,
): ):
yield yield

View File

@ -1,15 +1,15 @@
"""Test integration_blueprint setup process.""" """Test octopusenergy setup process."""
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
import pytest import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components.integration_blueprint import ( from custom_components.octopusenergy import (
BlueprintDataUpdateCoordinator, BlueprintDataUpdateCoordinator,
async_reload_entry, async_reload_entry,
async_setup_entry, async_setup_entry,
async_unload_entry, async_unload_entry,
) )
from custom_components.integration_blueprint.const import DOMAIN from custom_components.octopusenergy.const import DOMAIN
from .const import MOCK_CONFIG from .const import MOCK_CONFIG
@ -26,7 +26,7 @@ async def test_setup_unload_and_reload_entry(hass, bypass_get_data):
# Set up the entry and assert that the values set during setup are where we expect # Set up the entry and assert that the values set during setup are where we expect
# them to be. Because we have patched the BlueprintDataUpdateCoordinator.async_get_data # them to be. Because we have patched the BlueprintDataUpdateCoordinator.async_get_data
# call, no code from custom_components/integration_blueprint/api.py actually runs. # call, no code from custom_components/octopusenergy/api.py actually runs.
assert await async_setup_entry(hass, config_entry) assert await async_setup_entry(hass, config_entry)
assert DOMAIN in hass.data and config_entry.entry_id in hass.data[DOMAIN] assert DOMAIN in hass.data and config_entry.entry_id in hass.data[DOMAIN]
assert ( assert (

View File

@ -1,12 +1,12 @@
"""Test integration_blueprint switch.""" """Test octopusenergy switch."""
from unittest.mock import call, patch from unittest.mock import call, patch
from homeassistant.components.switch import SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.components.switch import SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
from pytest_homeassistant_custom_component.common import MockConfigEntry from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components.integration_blueprint import async_setup_entry from custom_components.octopusenergy import async_setup_entry
from custom_components.integration_blueprint.const import DEFAULT_NAME, DOMAIN, SWITCH from custom_components.octopusenergy.const import DEFAULT_NAME, DOMAIN, SWITCH
from .const import MOCK_CONFIG from .const import MOCK_CONFIG
@ -21,7 +21,7 @@ async def test_switch_services(hass):
# Functions/objects can be patched directly in test code as well and can be used to test # Functions/objects can be patched directly in test code as well and can be used to test
# additional things, like whether a function was called or what arguments it was called with # additional things, like whether a function was called or what arguments it was called with
with patch( with patch(
"custom_components.integration_blueprint.IntegrationBlueprintApiClient.async_set_title" "custom_components.octopusenergy.OctopusEnergyApiClient.async_set_title"
) as title_func: ) as title_func:
await hass.services.async_call( await hass.services.async_call(
SWITCH, SWITCH,