<commit_before>"""Support for OVO Energy sensors."""
from datetime import timedelta
import logging

from ovoenergy import OVODailyUsage
from ovoenergy.ovoenergy import OVOEnergy

from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from . import OVOEnergyDeviceEntity
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN

_LOGGER = logging.getLogger(__name__)

SCAN_INTERVAL = timedelta(seconds=300)
PARALLEL_UPDATES = 4


async def async_setup_entry(
    hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
) -> None:
    """Set up OVO Energy sensor based on a config entry."""
    coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
        DATA_COORDINATOR
    ]
    client: OVOEnergy = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]

    currency = coordinator.data.electricity[
        len(coordinator.data.electricity) - 1
    ].cost.currency_unit

    async_add_entities(
        [
            OVOEnergyLastElectricityReading(coordinator, client),
            OVOEnergyLastGasReading(coordinator, client),
            OVOEnergyLastElectricityCost(coordinator, client, currency),
            OVOEnergyLastGasCost(coordinator, client, currency),
        ],
        True,
    )

<commit_msg>Fix creation of unrequired sensors in OVO energy (#38835)<commit_after>"""Support for OVO Energy sensors."""
from datetime import timedelta
import logging

from ovoenergy import OVODailyUsage
from ovoenergy.ovoenergy import OVOEnergy

from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from . import OVOEnergyDeviceEntity
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN

_LOGGER = logging.getLogger(__name__)

SCAN_INTERVAL = timedelta(seconds=300)
PARALLEL_UPDATES = 4


async def async_setup_entry(
    hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
) -> None:
    """Set up OVO Energy sensor based on a config entry."""
    coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
        DATA_COORDINATOR
    ]
    client: OVOEnergy = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]

    entities = []

    if coordinator.data.electricity:
        currency = coordinator.data.electricity[
            len(coordinator.data.electricity) - 1
        ].cost.currency_unit
        entities.append(OVOEnergyLastElectricityReading(coordinator, client))
        entities.append(OVOEnergyLastElectricityCost(coordinator, client, currency))
    if coordinator.data.gas:
        entities.append(OVOEnergyLastGasReading(coordinator, client))
        entities.append(OVOEnergyLastGasCost(coordinator, client, currency))

    async_add_entities(
        entities, True,
    )


{'fraction_non_alphanumeric': 0.07560137457044673, 'fraction_numerical': 0.005154639175257732, 'mean_word_length': 4.4309701492537314, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1075673', 'n_tokens_mistral': 884, 'n_tokens_neox': 845, 'n_words': 192}