<commit_before>"""The Wolf SmartSet sensors."""
import logging

from wolf_smartset.models import (
    HoursParameter,
    ListItemParameter,
    Parameter,
    PercentageParameter,
    Pressure,
    SimpleParameter,
    Temperature,
)

from homeassistant.components.wolflink.const import (
    COORDINATOR,
    DEVICE_ID,
    DOMAIN,
    PARAMETERS,
    STATES,
)
from homeassistant.const import (
    DEVICE_CLASS_PRESSURE,
    DEVICE_CLASS_TEMPERATURE,
    PRESSURE_BAR,
    TEMP_CELSIUS,
    TIME_HOURS,
)
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
    """Set up all entries for Wolf Platform."""

    coordinator = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]
    parameters = hass.data[DOMAIN][config_entry.entry_id][PARAMETERS]
    device_id = hass.data[DOMAIN][config_entry.entry_id][DEVICE_ID]

    entities = []
    for parameter in parameters:
        if isinstance(parameter, Temperature):
            entities.append(WolfLinkTemperature(coordinator, parameter, device_id))
        if isinstance(parameter, Pressure):
            entities.append(WolfLinkPressure(coordinator, parameter, device_id))
        if isinstance(parameter, PercentageParameter):
            entities.append(WolfLinkPercentage(coordinator, parameter, device_id))
        if isinstance(parameter, ListItemParameter):
            entities.append(WolfLinkState(coordinator, parameter, device_id))
        if isinstance(parameter, HoursParameter):
            entities.append(WolfLinkHours(coordinator, parameter, device_id))
        if isinstance(parameter, SimpleParameter):
            entities.append(WolfLinkSensor(coordinator, parameter, device_id))

    async_add_entities(entities, True)


class WolfLinkSensor(Entity):
    """Base class for all Wolf entities."""

    def __init__(self, coordinator, wolf_object: Parameter, device_id):
        """Initialize."""
        self.coordinator = coordinator
        self.wolf_object = wolf_object
        self.device_id = device_id

    @property
    def name(self):
        """Return the name."""
        return f"{self.wolf_object.name}"

    @property
    def state(self):
        """Return the state."""
        return self.coordinator.data[self.wolf_object.value_id]

    @property
    def device_state_attributes(self):
        """Return the state attributes."""
        return {
            "parameter_id": self.wolf_object.parameter_id,
            "value_id": self.wolf_object.value_id,
            "parent": self.wolf_object.parent,
        }

    @property
    def unique_id(self):
        """Return a unique_id for this entity."""
        return f"{self.device_id}:{self.wolf_object.parameter_id}"

    @property
    def available(self):
        """Return True if entity is available."""
        return self.coordinator.last_update_success

    @property
    def should_poll(self):
        """No need to poll. Coordinator notifies entity of updates."""
        return False

    async def async_added_to_hass(self):
        """When entity is added to hass."""
        self.async_on_remove(
            self.coordinator.async_add_listener(self.async_write_ha_state)
        )

    async def async_update(self):
        """Update the sensor."""
        await self.coordinator.async_request_refresh()
        _LOGGER.debug("Updating %s", self.coordinator.data[self.wolf_object.value_id])


class WolfLinkHours(WolfLinkSensor):
    """Class for hour based entities."""

    @property
    def icon(self):
        """Icon to display in the front Aend."""
        return "mdi:clock"

    @property
    def unit_of_measurement(self):
        """Return the unit the value is expressed in."""
        return TIME_HOURS


class WolfLinkTemperature(WolfLinkSensor):
    """Class for temperature based entities."""

    @property
    def device_class(self):
        """Return the device_class."""
        return DEVICE_CLASS_TEMPERATURE

    @property
    def unit_of_measurement(self):
        """Return the unit the value is expressed in."""
        return TEMP_CELSIUS
<commit_msg>Update wolflink to use CoordinatorEntity (#39444)<commit_after>"""The Wolf SmartSet sensors."""
import logging

from wolf_smartset.models import (
    HoursParameter,
    ListItemParameter,
    Parameter,
    PercentageParameter,
    Pressure,
    SimpleParameter,
    Temperature,
)

from homeassistant.components.wolflink.const import (
    COORDINATOR,
    DEVICE_ID,
    DOMAIN,
    PARAMETERS,
    STATES,
)
from homeassistant.const import (
    DEVICE_CLASS_PRESSURE,
    DEVICE_CLASS_TEMPERATURE,
    PRESSURE_BAR,
    TEMP_CELSIUS,
    TIME_HOURS,
)
from homeassistant.helpers.update_coordinator import CoordinatorEntity

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
    """Set up all entries for Wolf Platform."""

    coordinator = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]
    parameters = hass.data[DOMAIN][config_entry.entry_id][PARAMETERS]
    device_id = hass.data[DOMAIN][config_entry.entry_id][DEVICE_ID]

    entities = []
    for parameter in parameters:
        if isinstance(parameter, Temperature):
            entities.append(WolfLinkTemperature(coordinator, parameter, device_id))
        if isinstance(parameter, Pressure):
            entities.append(WolfLinkPressure(coordinator, parameter, device_id))
        if isinstance(parameter, PercentageParameter):
            entities.append(WolfLinkPercentage(coordinator, parameter, device_id))
        if isinstance(parameter, ListItemParameter):
            entities.append(WolfLinkState(coordinator, parameter, device_id))
        if isinstance(parameter, HoursParameter):
            entities.append(WolfLinkHours(coordinator, parameter, device_id))
        if isinstance(parameter, SimpleParameter):
            entities.append(WolfLinkSensor(coordinator, parameter, device_id))

    async_add_entities(entities, True)


class WolfLinkSensor(CoordinatorEntity):
    """Base class for all Wolf entities."""

    def __init__(self, coordinator, wolf_object: Parameter, device_id):
        """Initialize."""
        super().__init__(coordinator)
        self.wolf_object = wolf_object
        self.device_id = device_id

    @property
    def name(self):
        """Return the name."""
        return f"{self.wolf_object.name}"

    @property
    def state(self):
        """Return the state."""
        return self.coordinator.data[self.wolf_object.value_id]

    @property
    def device_state_attributes(self):
        """Return the state attributes."""
        return {
            "parameter_id": self.wolf_object.parameter_id,
            "value_id": self.wolf_object.value_id,
            "parent": self.wolf_object.parent,
        }

    @property
    def unique_id(self):
        """Return a unique_id for this entity."""
        return f"{self.device_id}:{self.wolf_object.parameter_id}"


class WolfLinkHours(WolfLinkSensor):
    """Class for hour based entities."""

    @property
    def icon(self):
        """Icon to display in the front Aend."""
        return "mdi:clock"

    @property
    def unit_of_measurement(self):
        """Return the unit the value is expressed in."""
        return TIME_HOURS


class WolfLinkTemperature(WolfLinkSensor):
    """Class for temperature based entities."""

    @property
    def device_class(self):
        """Return the device_class."""
        return DEVICE_CLASS_TEMPERATURE

    @property
    def unit_of_measurement(self):
        """Return the unit the value is expressed in."""
        return TEMP_CELSIUS

{'fraction_non_alphanumeric': 0.0983820459290188, 'fraction_numerical': 0.0006524008350730689, 'mean_word_length': 3.220814977973568, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '1073661', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2150, 'n_words': 493}