"""Sensors flow for Withings."""
import typing as types

from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util import slugify

from . import const
from .common import _LOGGER, WithingsDataManager, get_data_manager

# There's only 3 calls (per profile) made to the withings api every 5
# minutes (see throttle values). This component wouldn't benefit
# much from parallel updates.
PARALLEL_UPDATES = 1


async def async_setup_entry(
    hass: HomeAssistantType,
    entry: ConfigEntry,
    async_add_entities: types.Callable[[types.List[Entity], bool], None],
):
    """Set up the sensor config entry."""
    data_manager = get_data_manager(hass, entry)
    entities = create_sensor_entities(data_manager)
    async_add_entities(entities, True)


def get_measures():
    """Get all the measures.

    This function exists to be easily mockable so we can test
    one measure at a time. This becomes necessary when integration
    testing throttle functionality in the data manager.
    """
    return list(WITHINGS_MEASUREMENTS_MAP)


def create_sensor_entities(data_manager: WithingsDataManager):
    """Create sensor entities."""
    entities = []

    measures = get_measures()

    for attribute in WITHINGS_ATTRIBUTES:
        if attribute.measurement not in measures:
            _LOGGER.debug(
                "Skipping measurement %s as it is not in the"
                "list of measurements to use",
                attribute.measurement,
            )
            continue

        _LOGGER.debug(
            "Creating entity for measurement: %s, measure_type: %s,"
            "friendly_name: %s, unit_of_measurement: %s",
            attribute.measurement,
            attribute.measure_type,
            attribute.friendly_name,
            attribute.unit_of_measurement,
        )

        entity = WithingsHealthSensor(data_manager, attribute)

        entities.append(entity)

    return entities


class WithingsAttribute:
    """Base class for modeling withing data."""

    def __init__(
        self,
        measurement: str,
        measure_type,
        friendly_name: str,
        unit_of_measurement: str,
        icon: str,
    ) -> None:
        """Constructor."""
        self.measurement = measurement
        self.measure_type = measure_type
        self.friendly_name = friendly_name
        self.unit_of_measurement = unit_of_measurement
        self.icon = icon


class WithingsMeasureAttribute(WithingsAttribute):
    """Model measure attributes."""


class WithingsSleepStateAttribute(WithingsAttribute):