Skip to content

Commit

Permalink
Format imports and general coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
h4de5 committed Aug 9, 2021
1 parent e9ed28b commit 365a239
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 131 deletions.
90 changes: 42 additions & 48 deletions custom_components/vimar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
"""Vimar Platform integration."""
from datetime import timedelta
import logging
import asyncio
import async_timeout
import logging
import os
from datetime import timedelta
from typing import Tuple

from homeassistant.helpers.typing import HomeAssistantType, ConfigType
from homeassistant.const import (
CONF_PORT, CONF_HOST, CONF_PASSWORD, CONF_USERNAME, CONF_TIMEOUT)
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
import async_timeout
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from .vimarlink.vimarlink import (VimarLink, VimarProject, VimarApiError)

from .const import (
DOMAIN,
CONF_SCHEMA,
CONF_CERTIFICATE,
CONF_GLOBAL_CHANNEL_ID,
CONF_IGNORE_PLATFORM,
CONF_OVERRIDE,
DEFAULT_USERNAME,
DEFAULT_SCHEMA,
DEFAULT_PORT,
DEFAULT_CERTIFICATE,
DEFAULT_TIMEOUT,
AVAILABLE_PLATFORMS
)
from homeassistant.const import (CONF_HOST, CONF_PASSWORD, CONF_PORT,
CONF_TIMEOUT, CONF_USERNAME)
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from homeassistant.helpers.update_coordinator import (DataUpdateCoordinator,
UpdateFailed)

from .const import (AVAILABLE_PLATFORMS, CONF_CERTIFICATE,
CONF_GLOBAL_CHANNEL_ID, CONF_IGNORE_PLATFORM,
CONF_OVERRIDE, CONF_SCHEMA, DEFAULT_CERTIFICATE,
DEFAULT_PORT, DEFAULT_SCHEMA, DEFAULT_TIMEOUT,
DEFAULT_USERNAME, DOMAIN)
from .vimarlink.vimarlink import VimarApiError, VimarLink, VimarProject

_LOGGER = logging.getLogger(__name__)

CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_SCHEMA, default=DEFAULT_SCHEMA): cv.string,
vol.Optional(CONF_CERTIFICATE, default=DEFAULT_CERTIFICATE): vol.Any(cv.string, None),
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): vol.Range(min=2, max=60),
vol.Optional(CONF_GLOBAL_CHANNEL_ID): vol.Range(min=1, max=99999),
vol.Optional(CONF_IGNORE_PLATFORM, default=[]): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_OVERRIDE, default=[]): cv.ensure_list
})
}, extra=vol.ALLOW_EXTRA)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_SCHEMA, default=DEFAULT_SCHEMA): cv.string,
vol.Optional(CONF_CERTIFICATE, default=DEFAULT_CERTIFICATE): vol.Any(cv.string, None),
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): vol.Range(min=2, max=60),
vol.Optional(CONF_GLOBAL_CHANNEL_ID): vol.Range(min=1, max=99999),
vol.Optional(CONF_IGNORE_PLATFORM, default=[]): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(CONF_OVERRIDE, default=[]): cv.ensure_list,
}
)
},
extra=vol.ALLOW_EXTRA,
)


@asyncio.coroutine
Expand Down Expand Up @@ -111,14 +109,13 @@ async def async_api_update():
ignored_platforms = vimarconfig.get(CONF_IGNORE_PLATFORM)

for device_type, platform in AVAILABLE_PLATFORMS.items():
if (not ignored_platforms or platform not in ignored_platforms):
if not ignored_platforms or platform not in ignored_platforms:
device_count = vimarproject.platform_exists(device_type)
if device_count:
_LOGGER.debug("load platform %s with %d %s", platform, device_count, device_type)
hass.async_create_task(hass.helpers.discovery.async_load_platform(
platform, DOMAIN, {"hass_data_key": device_type}, config))
hass.async_create_task(hass.helpers.discovery.async_load_platform(platform, DOMAIN, {"hass_data_key": device_type}, config))
else:
_LOGGER.warning('ignore platform: %s', platform)
_LOGGER.warning("ignore platform: %s", platform)

# States are in the format DOMAIN.OBJECT_ID.
# hass.states.async_set("vimar.Hello_World", "Works!")
Expand All @@ -144,9 +141,8 @@ async def async_api_update():
# return True


async def _validate_vimar_credentials(hass: HomeAssistantType, vimarconfig: ConfigType) -> [VimarProject, VimarLink]:
async def _validate_vimar_credentials(hass: HomeAssistantType, vimarconfig: ConfigType) -> Tuple[VimarProject, VimarLink]:
"""Validate Vimar credential config."""

schema = vimarconfig.get(CONF_SCHEMA)
host = vimarconfig.get(CONF_HOST)
port = vimarconfig.get(CONF_PORT)
Expand All @@ -160,8 +156,7 @@ async def _validate_vimar_credentials(hass: HomeAssistantType, vimarconfig: Conf
device_overrides = vimarconfig.get(CONF_OVERRIDE, [])

# initialize a new VimarLink object
vimarconnection = VimarLink(
schema, host, port, username, password, certificate, timeout)
vimarconnection = VimarLink(schema, host, port, username, password, certificate, timeout)

# will hold all the devices and their states
vimarproject = VimarProject(vimarconnection, device_overrides)
Expand All @@ -181,8 +176,7 @@ async def _validate_vimar_credentials(hass: HomeAssistantType, vimarconfig: Conf
if not valid_certificate:
raise PlatformNotReady
else:
_LOGGER.info(
"Vimar CA Certificate is already in place: %s", certificate)
_LOGGER.info("Vimar CA Certificate is already in place: %s", certificate)

# Verify that passed in configuration works
# starting it outside MainThread
Expand Down
59 changes: 23 additions & 36 deletions custom_components/vimar/climate.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,30 @@
"""Platform for climate integration."""

import logging
from homeassistant.components.climate.const import (
CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_FAN_MODE,
SUPPORT_AUX_HEAT,
FAN_ON,
FAN_OFF,
FAN_LOW,
FAN_MEDIUM,
FAN_HIGH,
)

from homeassistant.components.climate.const import (CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF, FAN_HIGH,
FAN_LOW, FAN_MEDIUM,
FAN_OFF, FAN_ON,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_AUX_HEAT,
SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from .const import (
# DOMAIN,
VIMAR_CLIMATE_COOL,
VIMAR_CLIMATE_COOL_I,
VIMAR_CLIMATE_COOL_II,
VIMAR_CLIMATE_HEAT,
VIMAR_CLIMATE_HEAT_I,
VIMAR_CLIMATE_HEAT_II,
VIMAR_CLIMATE_AUTO,
VIMAR_CLIMATE_AUTO_I,
VIMAR_CLIMATE_AUTO_II,
VIMAR_CLIMATE_MANUAL,
VIMAR_CLIMATE_MANUAL_I,
VIMAR_CLIMATE_MANUAL_II,
VIMAR_CLIMATE_OFF,
VIMAR_CLIMATE_OFF_I,
VIMAR_CLIMATE_OFF_II,
)

from .const import (VIMAR_CLIMATE_AUTO, VIMAR_CLIMATE_AUTO_I, # DOMAIN,
VIMAR_CLIMATE_AUTO_II, VIMAR_CLIMATE_COOL,
VIMAR_CLIMATE_COOL_I, VIMAR_CLIMATE_COOL_II,
VIMAR_CLIMATE_HEAT, VIMAR_CLIMATE_HEAT_I,
VIMAR_CLIMATE_HEAT_II, VIMAR_CLIMATE_MANUAL,
VIMAR_CLIMATE_MANUAL_I, VIMAR_CLIMATE_MANUAL_II,
VIMAR_CLIMATE_OFF, VIMAR_CLIMATE_OFF_I,
VIMAR_CLIMATE_OFF_II)
from .vimar_entity import VimarEntity, vimar_setup_platform

try:
Expand Down
19 changes: 7 additions & 12 deletions custom_components/vimar/cover.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
"""Platform for cover integration."""

import logging
from homeassistant.components.cover import (
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_STOP,
SUPPORT_SET_POSITION,
SUPPORT_OPEN_TILT,
SUPPORT_CLOSE_TILT,
SUPPORT_STOP_TILT,
SUPPORT_SET_TILT_POSITION,
ATTR_POSITION,
ATTR_TILT_POSITION,
)

from homeassistant.components.cover import (ATTR_POSITION, ATTR_TILT_POSITION,
SUPPORT_CLOSE, SUPPORT_CLOSE_TILT,
SUPPORT_OPEN, SUPPORT_OPEN_TILT,
SUPPORT_SET_POSITION,
SUPPORT_SET_TILT_POSITION,
SUPPORT_STOP, SUPPORT_STOP_TILT)

from .vimar_entity import VimarEntity, vimar_setup_platform

Expand Down
4 changes: 3 additions & 1 deletion custom_components/vimar/light.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Platform for light integration."""

import logging
from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR

import homeassistant.util.color as color_util
from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR

from .vimar_entity import VimarEntity, vimar_setup_platform

try:
Expand Down
18 changes: 8 additions & 10 deletions custom_components/vimar/media_player.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
"""Platform for media player integration."""

import logging

from homeassistant.components.media_player.const import (
MEDIA_TYPE_MUSIC,
MEDIA_TYPE_CHANNEL,
MEDIA_TYPE_MUSIC,
SUPPORT_NEXT_TRACK,
SUPPORT_SELECT_SOURCE,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET,
SUPPORT_VOLUME_STEP,
SUPPORT_TURN_ON,
SUPPORT_TURN_OFF,
SUPPORT_SELECT_SOURCE,
SUPPORT_NEXT_TRACK,
)
from homeassistant.const import (
# STATE_IDLE,
STATE_OFF,
STATE_PLAYING,
)
from homeassistant.const import STATE_OFF, STATE_PLAYING # STATE_IDLE,

from .vimar_entity import VimarEntity, vimar_setup_platform

try:
Expand Down
2 changes: 2 additions & 0 deletions custom_components/vimar/scene.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Platform for scene integration."""

import logging

from homeassistant.components.scene import Scene

from .vimar_entity import VimarEntity, vimar_setup_platform

_LOGGER = logging.getLogger(__name__)
Expand Down
15 changes: 8 additions & 7 deletions custom_components/vimar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

# from datetime import timedelta
from homeassistant.const import (
POWER_KILO_WATT,
ENERGY_KILO_WATT_HOUR,
TEMP_CELSIUS,
SPEED_METERS_PER_SECOND,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_TIMESTAMP,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TIMESTAMP,
ENERGY_KILO_WATT_HOUR,
POWER_KILO_WATT,
SPEED_METERS_PER_SECOND,
TEMP_CELSIUS,
)

try:
Expand All @@ -23,6 +23,7 @@
from homeassistant.const import VOLT as ELECTRIC_POTENTIAL_VOLT

from homeassistant.helpers.entity import Entity

from .const import DOMAIN
from .vimar_entity import VimarEntity, vimar_setup_platform

Expand Down
2 changes: 2 additions & 0 deletions custom_components/vimar/switch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Platform for switch integration."""

import logging

from homeassistant.helpers.entity import ToggleEntity

from .vimar_entity import VimarEntity, vimar_setup_platform

_LOGGER = logging.getLogger(__name__)
Expand Down
5 changes: 3 additions & 2 deletions custom_components/vimar/vimar_entity.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Insteon base entity."""
import logging

from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.entity import Entity
from .vimarlink.vimarlink import (VimarLink, VimarProject)
from homeassistant.helpers.typing import HomeAssistantType

from .const import DOMAIN
from .vimarlink.vimarlink import VimarLink, VimarProject

_LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/vimar/vimarlink/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""VIMAR by-me link library"""
"""VIMAR by-me link library."""
18 changes: 6 additions & 12 deletions custom_components/vimar/vimarlink/vimarlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@

import logging
import sys

# for communicating with vimar webserver
import xml.etree.cElementTree as xmlTree
from xml.etree import ElementTree

import requests
from requests.exceptions import HTTPError

from .const import (
DEVICE_TYPE_LIGHTS,
DEVICE_TYPE_COVERS,
DEVICE_TYPE_SWITCHES,
DEVICE_TYPE_CLIMATES,
DEVICE_TYPE_MEDIA_PLAYERS,
DEVICE_TYPE_SCENES,
# DEVICE_TYPE_FANS,
DEVICE_TYPE_SENSORS,
DEVICE_TYPE_OTHERS,
)
from .const import (DEVICE_TYPE_CLIMATES, # DEVICE_TYPE_FANS,
DEVICE_TYPE_COVERS, DEVICE_TYPE_LIGHTS,
DEVICE_TYPE_MEDIA_PLAYERS, DEVICE_TYPE_OTHERS,
DEVICE_TYPE_SCENES, DEVICE_TYPE_SENSORS,
DEVICE_TYPE_SWITCHES)

_LOGGER = logging.getLogger(__name__)
MAX_ROWS_PER_REQUEST = 300
Expand Down
4 changes: 2 additions & 2 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Vimar Platform example without HA."""
# import async_timeout
import os
import configparser
import argparse
import configparser
import os

# those imports only work in that directory
# this will be easier to use, as soon as we have a separate python package
Expand Down

0 comments on commit 365a239

Please sign in to comment.