"""Support for Pocket Casts."""
import logging

from datetime import timedelta

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)

ICON = "mdi:rss"

SENSOR_NAME = "Pocketcasts unlistened episodes"

SCAN_INTERVAL = timedelta(minutes=5)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {vol.Required(CONF_PASSWORD): cv.string, vol.Required(CONF_USERNAME): cv.string}
)


def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the pocketcasts platform for sensors."""
    import pocketcasts

    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)

    try:
        api = pocketcasts.Api(username, password)
        _LOGGER.debug("Found %d podcasts", len(api.my_podcasts()))
        add_entities([PocketCastsSensor(api)], True)
    except OSError as err:
        _LOGGER.error("Connection to server failed: %s", err)
        return False


class PocketCastsSensor(Entity):
    """Representation of a pocket casts sensor."""

    def __init__(self, api):
        """Initialize the sensor."""
        self._api = api
        self._state = None

    @property
    def name(self):
        """Return the name of the sensor."""
        return SENSOR_NAME

    @property
    def state(self):
        """Return the sensor state."""
        return self._state

    @property
    def icon(self):
        """Return the icon for the sensor."""
        return ICON

    def update(self):
        """Update sensor values."""
        try:
            self._state = len(self._api.new_episodes_released())
            _LOGGER.debug("Found %d new episodes", self._state)
        except OSError as err:
            _LOGGER.warning("Failed to contact server: %s", err)

@@ -29,24 +29,8 @@
 %22%22%22%0A
-import logging%0A%0A
 from
@@ -60,87 +60,68 @@
 lta%0A
-%0A
 import 
-voluptuous as vol%0A%0Aimport homeassistant.helpers.config_validation as cv
+logging%0A%0Aimport pocketcasts%0Aimport voluptuous as vol%0A
 %0Afro
@@ -218,31 +218,84 @@
 ONF_
-USERNAME, CONF_PASSWORD
+PASSWORD, CONF_USERNAME%0Aimport homeassistant.helpers.config_validation as cv
 %0Afro
@@ -743,32 +743,8 @@
 %22%22%22%0A
-    import pocketcasts%0A%0A
     

Move imports in pocketcasts component (#28084)