mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
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
@ -165,7 +165,7 @@ omit =
|
|||||||
homeassistant/components/eight_sleep/*
|
homeassistant/components/eight_sleep/*
|
||||||
homeassistant/components/eliqonline/sensor.py
|
homeassistant/components/eliqonline/sensor.py
|
||||||
homeassistant/components/elkm1/*
|
homeassistant/components/elkm1/*
|
||||||
homeassistant/components/elv/switch.py
|
homeassistant/components/elv/*
|
||||||
homeassistant/components/emby/media_player.py
|
homeassistant/components/emby/media_player.py
|
||||||
homeassistant/components/emoncms/sensor.py
|
homeassistant/components/emoncms/sensor.py
|
||||||
homeassistant/components/emoncms_history/*
|
homeassistant/components/emoncms_history/*
|
||||||
|
@ -1 +1,37 @@
|
|||||||
"""The Elv integration."""
|
"""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",
|
"documentation": "https://www.home-assistant.io/components/pca",
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@majuss"],
|
"codeowners": ["@majuss"],
|
||||||
"requirements": ["pypca==0.0.4"]
|
"requirements": ["pypca==0.0.5"]
|
||||||
}
|
}
|
@ -1,15 +1,11 @@
|
|||||||
"""Support for PCA 301 smart switch."""
|
"""Support for PCA 301 smart switch."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import pypca
|
||||||
|
from serial import SerialException
|
||||||
|
|
||||||
from homeassistant.components.switch import (
|
from homeassistant.components.switch import SwitchDevice, ATTR_CURRENT_POWER_W
|
||||||
SwitchDevice,
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
PLATFORM_SCHEMA,
|
|
||||||
ATTR_CURRENT_POWER_W,
|
|
||||||
)
|
|
||||||
from homeassistant.const import CONF_NAME, CONF_DEVICE, EVENT_HOMEASSISTANT_STOP
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -17,26 +13,20 @@ ATTR_TOTAL_ENERGY_KWH = "total_energy_kwh"
|
|||||||
|
|
||||||
DEFAULT_NAME = "PCA 301"
|
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):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the PCA switch platform."""
|
"""Set up the PCA switch platform."""
|
||||||
import pypca
|
|
||||||
from serial import SerialException
|
|
||||||
|
|
||||||
name = config[CONF_NAME]
|
if discovery_info is None:
|
||||||
usb_device = config[CONF_DEVICE]
|
return
|
||||||
|
|
||||||
|
serial_device = discovery_info["device"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pca = pypca.PCA(usb_device)
|
pca = pypca.PCA(serial_device)
|
||||||
pca.open()
|
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)
|
add_entities(entities, True)
|
||||||
|
|
||||||
except SerialException as exc:
|
except SerialException as exc:
|
||||||
@ -51,10 +41,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class SmartPlugSwitch(SwitchDevice):
|
class SmartPlugSwitch(SwitchDevice):
|
||||||
"""Representation of a PCA Smart Plug switch."""
|
"""Representation of a PCA Smart Plug switch."""
|
||||||
|
|
||||||
def __init__(self, pca, device_id, name):
|
def __init__(self, pca, device_id):
|
||||||
"""Initialize the switch."""
|
"""Initialize the switch."""
|
||||||
self._device_id = device_id
|
self._device_id = device_id
|
||||||
self._name = name
|
self._name = "PCA 301"
|
||||||
self._state = None
|
self._state = None
|
||||||
self._available = True
|
self._available = True
|
||||||
self._emeter_params = {}
|
self._emeter_params = {}
|
||||||
|
@ -1375,7 +1375,7 @@ pyowlet==1.0.2
|
|||||||
pyowm==2.10.0
|
pyowm==2.10.0
|
||||||
|
|
||||||
# homeassistant.components.elv
|
# homeassistant.components.elv
|
||||||
pypca==0.0.4
|
pypca==0.0.5
|
||||||
|
|
||||||
# homeassistant.components.lcn
|
# homeassistant.components.lcn
|
||||||
pypck==0.6.3
|
pypck==0.6.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user