<commit_before>"""
Platform for the opengarage.io cover component.

For more details about this platform, please refer to the documentation
https://home-assistant.io/components/cover.opengarage/
"""
import logging

import requests
import voluptuous as vol

from homeassistant.components.cover import (
    CoverDevice, PLATFORM_SCHEMA, SUPPORT_OPEN, SUPPORT_CLOSE)
from homeassistant.const import (
    CONF_DEVICE, CONF_NAME, STATE_UNKNOWN, STATE_CLOSED, STATE_OPEN,
    CONF_COVERS, CONF_HOST, CONF_PORT)
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

ATTR_DISTANCE_SENSOR = "distance_sensor"
ATTR_DOOR_STATE = "door_state"
ATTR_SIGNAL_STRENGTH = "wifi_signal"

CONF_DEVICEKEY = "device_key"

DEFAULT_NAME = 'OpenGarage'
DEFAULT_PORT = 80

STATE_CLOSING = "closing"
STATE_OFFLINE = "offline"
STATE_OPENING = "opening"
STATE_STOPPED = "stopped"

STATES_MAP = {
    0: STATE_CLOSED,
    1: STATE_OPEN
}

COVER_SCHEMA = vol.Schema({
    vol.Required(CONF_DEVICEKEY): cv.string,
    vol.Required(CONF_HOST): cv.string,
    vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
    vol.Optional(CONF_NAME): cv.string
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_COVERS): vol.Schema({cv.slug: COVER_SCHEMA}),
})


def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up OpenGarage covers."""
    covers = []
    devices = config.get(CONF_COVERS)

    for device_id, device_config in devices.items():
        args = {
            CONF_NAME: device_config.get(CONF_NAME),
            CONF_HOST: device_config.get(CONF_HOST),
            CONF_PORT: device_config.get(CONF_PORT),
            "device_id": device_config.get(CONF_DEVICE, device_id),
            CONF_DEVICEKEY: device_config.get(CONF_DEVICEKEY)
        }

        covers.append(OpenGarageCover(hass, args))

    add_devices(covers, True)


class OpenGarageCover(CoverDevice):
    """Representation of a OpenGarage cover."""

    # pylint: disable=no-self-use
    def __init__(self, hass, args):
        """Initialize the cover."""
        self.opengarage_url = 'http://{}:{}'.format(
            args[CONF_HOST], args[CONF_PORT])
        self.hass = hass
        self._name = args[CONF_NAME]
        self.device_id = args['device_id']
        self._devicekey = args[CONF_DEVICEKEY]
        self._state = STATE_UNKNOWN
        self._state_before_move = None
        self.dist = None
        self.signal = None
        self._available = True

    @property
    def name(self):
        """Return the name of the cover."""
        return self._name

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

    @property
    def device_state_attributes(self):
        """Return the device state attributes."""
        data = {}

        if self.signal is not None:
            data[ATTR_SIGNAL_STRENGTH] = self.signal

        if self.dist is not None:
            data[ATTR_DISTANCE_SENSOR] = self.dist

        if self._state is not None:
            data[ATTR_DOOR_STATE] = self._state

        return data

    @property
    def is_closed(self):
        """Return if the cover is closed."""
        if self._state == STATE_UNKNOWN:
            return None
        return self._state in [STATE_CLOSED, STATE_OPENING]
<commit_msg>OpenGarage - correctly handle offline status (#12612) (#12613)<commit_after>"""
Platform for the opengarage.io cover component.

For more details about this platform, please refer to the documentation
https://home-assistant.io/components/cover.opengarage/
"""
import logging

import requests
import voluptuous as vol

from homeassistant.components.cover import (
    CoverDevice, PLATFORM_SCHEMA, SUPPORT_OPEN, SUPPORT_CLOSE)
from homeassistant.const import (
    CONF_DEVICE, CONF_NAME, STATE_UNKNOWN, STATE_CLOSED, STATE_OPEN,
    CONF_COVERS, CONF_HOST, CONF_PORT)
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

ATTR_DISTANCE_SENSOR = "distance_sensor"
ATTR_DOOR_STATE = "door_state"
ATTR_SIGNAL_STRENGTH = "wifi_signal"

CONF_DEVICEKEY = "device_key"

DEFAULT_NAME = 'OpenGarage'
DEFAULT_PORT = 80

STATE_CLOSING = "closing"
STATE_OFFLINE = "offline"
STATE_OPENING = "opening"
STATE_STOPPED = "stopped"

STATES_MAP = {
    0: STATE_CLOSED,
    1: STATE_OPEN
}

COVER_SCHEMA = vol.Schema({
    vol.Required(CONF_DEVICEKEY): cv.string,
    vol.Required(CONF_HOST): cv.string,
    vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
    vol.Optional(CONF_NAME): cv.string
})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_COVERS): vol.Schema({cv.slug: COVER_SCHEMA}),
})


def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up OpenGarage covers."""
    covers = []
    devices = config.get(CONF_COVERS)

    for device_id, device_config in devices.items():
        args = {
            CONF_NAME: device_config.get(CONF_NAME),
            CONF_HOST: device_config.get(CONF_HOST),
            CONF_PORT: device_config.get(CONF_PORT),
            "device_id": device_config.get(CONF_DEVICE, device_id),
            CONF_DEVICEKEY: device_config.get(CONF_DEVICEKEY)
        }

        covers.append(OpenGarageCover(hass, args))

    add_devices(covers, True)


class OpenGarageCover(CoverDevice):
    """Representation of a OpenGarage cover."""

    # pylint: disable=no-self-use
    def __init__(self, hass, args):
        """Initialize the cover."""
        self.opengarage_url = 'http://{}:{}'.format(
            args[CONF_HOST], args[CONF_PORT])
        self.hass = hass
        self._name = args[CONF_NAME]
        self.device_id = args['device_id']
        self._devicekey = args[CONF_DEVICEKEY]
        self._state = STATE_UNKNOWN
        self._state_before_move = None
        self.dist = None
        self.signal = None
        self._available = True

    @property
    def name(self):
        """Return the name of the cover."""
        return self._name

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

    @property
    def device_state_attributes(self):
        """Return the device state attributes."""
        data = {}

        if self.signal is not None:
            data[ATTR_SIGNAL_STRENGTH] = self.signal

        if self.dist is not None:
            data[ATTR_DISTANCE_SENSOR] = self.dist

        if self._state is not None:
            data[ATTR_DOOR_STATE] = self._state

        return data

    @property
    def is_closed(self):
        """Return if the cover is closed."""
        if self._state in [STATE_UNKNOWN, STATE_OFFLINE]:
            return None
        return self._state in [STATE_CLOSED, STATE_OPENING]

{'fraction_non_alphanumeric': 0.10177514792899409, 'fraction_numerical': 0.0026627218934911242, 'mean_word_length': 3.117539585870889, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1110', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2122, 'n_words': 480}