Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ATEN PE component for ATEN eco PDUs #27960

Merged
merged 10 commits into from
Dec 1, 2019
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ omit =
homeassistant/components/asterisk_cdr/mailbox.py
homeassistant/components/asterisk_mbox/*
homeassistant/components/asuswrt/device_tracker.py
homeassistant/components/aten_pe/*
homeassistant/components/atome/*
homeassistant/components/august/*
homeassistant/components/aurora_abb_powerone/sensor.py
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ homeassistant/components/arcam_fmj/* @elupus
homeassistant/components/arduino/* @fabaff
homeassistant/components/arest/* @fabaff
homeassistant/components/asuswrt/* @kennedyshead
homeassistant/components/aten_pe/* @mtdcr
homeassistant/components/atome/* @baqs
homeassistant/components/aurora_abb_powerone/* @davet2001
homeassistant/components/auth/* @home-assistant/core
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/aten_pe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The ATEN PE component."""
12 changes: 12 additions & 0 deletions homeassistant/components/aten_pe/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"domain": "aten_pe",
"name": "ATEN eco PDUs",
"documentation": "https://www.home-assistant.io/components/aten_pe",
mtdcr marked this conversation as resolved.
Show resolved Hide resolved
"requirements": [
"atenpdu==0.1.2"
],
"dependencies": [],
"codeowners": [
"@mtdcr"
]
}
110 changes: 110 additions & 0 deletions homeassistant/components/aten_pe/switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""The ATEN PE switch component."""

import logging

from atenpdu import AtenPE
import voluptuous as vol

from homeassistant.components.switch import (
DEVICE_CLASS_OUTLET,
PLATFORM_SCHEMA,
SwitchDevice,
)
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_USERNAME
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

CONF_AUTH_KEY = "auth_key"
CONF_COMMUNITY = "community"
CONF_PRIV_KEY = "priv_key"
DEFAULT_COMMUNITY = "private"
DEFAULT_PORT = "161"
DEFAULT_USERNAME = "administrator"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_COMMUNITY, default=DEFAULT_COMMUNITY): cv.string,
vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
vol.Optional(CONF_AUTH_KEY): cv.string,
vol.Optional(CONF_PRIV_KEY): cv.string,
}
)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the ATEN PE switch."""
dev = AtenPE(
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
node=config[CONF_HOST],
serv=config[CONF_PORT],
community=config[CONF_COMMUNITY],
username=config[CONF_USERNAME],
authkey=config.get(CONF_AUTH_KEY),
privkey=config.get(CONF_PRIV_KEY),
)

switches = []
for outlet in dev.outlets:
switches.append(AtenSwitch(dev, outlet.id, outlet.name))

async_add_entities(switches)
return True
mtdcr marked this conversation as resolved.
Show resolved Hide resolved


class AtenSwitch(SwitchDevice):
"""Represents an ATEN PE switch."""

def __init__(self, device, outlet, name):
"""Initialize an ATEN PE switch."""
self._device = device
self._outlet = outlet
self._name = name or f"Outlet {outlet}"
self._enabled = False
self._outlet_power = 0.0

@property
def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self._device.deviceMAC}-{self._outlet}"

@property
def name(self) -> str:
"""Return the name of the entity."""
return self._name

@property
def device_class(self) -> str:
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_OUTLET

@property
def is_on(self) -> bool:
"""Return True if entity is on."""
return self._enabled

@property
def current_power_w(self) -> float:
"""Return the current power usage in W."""
return self._outlet_power

def turn_on(self, **kwargs):
"""Turn the switch on."""
self._device.setOutletStatus(self._outlet, "on")
self._enabled = True
frenck marked this conversation as resolved.
Show resolved Hide resolved

def turn_off(self, **kwargs):
"""Turn the switch off."""
self._device.setOutletStatus(self._outlet, "off")
self._enabled = False

def update(self):
"""Process update from entity."""
status = self._device.displayOutletStatus(self._outlet)
if status == "on":
self._enabled = True
self._outlet_power = self._device.outletPower(self._outlet)
elif status == "off":
self._enabled = False
self._outlet_power = 0.0
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ asterisk_mbox==0.5.0
# homeassistant.components.upnp
async-upnp-client==0.14.11

# homeassistant.components.aten_pe
atenpdu==0.1.2

# homeassistant.components.aurora_abb_powerone
aurorapy==0.2.6

Expand Down