Move elv integration to component and bump pypca (#26552)
* fixing elv integration * black formatting * linting * rebase * removed logger warning for failed conf * rebase; coverage
This commit is contained in:
parent
1d60cccc21
commit
930dadb722
5 changed files with 53 additions and 27 deletions
|
@ -165,7 +165,7 @@ omit =
|
|||
homeassistant/components/eight_sleep/*
|
||||
homeassistant/components/eliqonline/sensor.py
|
||||
homeassistant/components/elkm1/*
|
||||
homeassistant/components/elv/switch.py
|
||||
homeassistant/components/elv/*
|
||||
homeassistant/components/emby/media_player.py
|
||||
homeassistant/components/emoncms/sensor.py
|
||||
homeassistant/components/emoncms_history/*
|
||||
|
|
|
@ -1 +1,37 @@
|
|||
"""The Elv integration."""
|
||||
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.const import CONF_DEVICE
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "elv"
|
||||
|
||||
DEFAULT_DEVICE = "/dev/ttyUSB0"
|
||||
|
||||
ELV_PLATFORMS = ["switch"]
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{vol.Optional(CONF_DEVICE, default=DEFAULT_DEVICE): cv.string}
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the PCA switch platform."""
|
||||
|
||||
for platform in ELV_PLATFORMS:
|
||||
discovery.load_platform(
|
||||
hass, platform, DOMAIN, {"device": config[DOMAIN][CONF_DEVICE]}, config
|
||||
)
|
||||
|
||||
return True
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
"documentation": "https://www.home-assistant.io/components/pca",
|
||||
"dependencies": [],
|
||||
"codeowners": ["@majuss"],
|
||||
"requirements": ["pypca==0.0.4"]
|
||||
}
|
||||
"requirements": ["pypca==0.0.5"]
|
||||
}
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
"""Support for PCA 301 smart switch."""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
import pypca
|
||||
from serial import SerialException
|
||||
|
||||
from homeassistant.components.switch import (
|
||||
SwitchDevice,
|
||||
PLATFORM_SCHEMA,
|
||||
ATTR_CURRENT_POWER_W,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, CONF_DEVICE, EVENT_HOMEASSISTANT_STOP
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.switch import SwitchDevice, ATTR_CURRENT_POWER_W
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -17,26 +13,20 @@ ATTR_TOTAL_ENERGY_KWH = "total_energy_kwh"
|
|||
|
||||
DEFAULT_NAME = "PCA 301"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Required(CONF_DEVICE): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the PCA switch platform."""
|
||||
import pypca
|
||||
from serial import SerialException
|
||||
|
||||
name = config[CONF_NAME]
|
||||
usb_device = config[CONF_DEVICE]
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
serial_device = discovery_info["device"]
|
||||
|
||||
try:
|
||||
pca = pypca.PCA(usb_device)
|
||||
pca = pypca.PCA(serial_device)
|
||||
pca.open()
|
||||
entities = [SmartPlugSwitch(pca, device, name) for device in pca.get_devices()]
|
||||
|
||||
entities = [SmartPlugSwitch(pca, device) for device in pca.get_devices()]
|
||||
add_entities(entities, True)
|
||||
|
||||
except SerialException as exc:
|
||||
|
@ -51,10 +41,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
class SmartPlugSwitch(SwitchDevice):
|
||||
"""Representation of a PCA Smart Plug switch."""
|
||||
|
||||
def __init__(self, pca, device_id, name):
|
||||
def __init__(self, pca, device_id):
|
||||
"""Initialize the switch."""
|
||||
self._device_id = device_id
|
||||
self._name = name
|
||||
self._name = "PCA 301"
|
||||
self._state = None
|
||||
self._available = True
|
||||
self._emeter_params = {}
|
||||
|
|
|
@ -1375,7 +1375,7 @@ pyowlet==1.0.2
|
|||
pyowm==2.10.0
|
||||
|
||||
# homeassistant.components.elv
|
||||
pypca==0.0.4
|
||||
pypca==0.0.5
|
||||
|
||||
# homeassistant.components.lcn
|
||||
pypck==0.6.3
|
||||
|
|
Loading…
Add table
Reference in a new issue