Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ omit =
homeassistant/components/asterisk_cdr/mailbox.py
homeassistant/components/asterisk_mbox/*
homeassistant/components/asuswrt/device_tracker.py
homeassistant/components/atome/*
homeassistant/components/august/*
homeassistant/components/aurora_abb_powerone/sensor.py
homeassistant/components/automatic/device_tracker.py
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ homeassistant/components/arcam_fmj/* @elupus
homeassistant/components/arduino/* @fabaff
homeassistant/components/arest/* @fabaff
homeassistant/components/asuswrt/* @kennedyshead
homeassistant/components/atome/* @baqs
homeassistant/components/aurora_abb_powerone/* @davet2001
homeassistant/components/auth/* @home-assistant/core
homeassistant/components/automatic/* @armills
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/atome/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Support for Atome devices connected to a Linky Energy Meter."""
8 changes: 8 additions & 0 deletions homeassistant/components/atome/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"domain": "atome",
"name": "Atome",
"documentation": "https://www.home-assistant.io/components/atome",
"dependencies": [],
"codeowners": ["@baqs"],
"requirements": ["pyatome==0.0.15"]
}
106 changes: 106 additions & 0 deletions homeassistant/components/atome/sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""Linky Atome."""
import logging
import voluptuous as vol
Comment thread
BaQs marked this conversation as resolved.
Outdated

from datetime import timedelta
Comment thread
BaQs marked this conversation as resolved.
from pyatome.client import AtomeClient
from pyatome.client import PyAtomeError

from homeassistant.const import (
CONF_PASSWORD,
CONF_USERNAME,
CONF_NAME,
DEVICE_CLASS_POWER,
POWER_WATT,
)

Comment thread
BaQs marked this conversation as resolved.
from homeassistant.components.sensor import PLATFORM_SCHEMA

Comment thread
BaQs marked this conversation as resolved.
Outdated
from homeassistant.helpers.entity import Entity

from homeassistant.util import Throttle

import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = "atome"

SCAN_INTERVAL = timedelta(seconds=30)
SESSION_RENEW_INTERVAL = timedelta(minutes=55)
Comment thread
BaQs marked this conversation as resolved.
Outdated

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}
)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the sensor."""
name = config[CONF_NAME]
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]

try:
client = AtomeClient(username, password)
except PyAtomeError as exp:
_LOGGER.error(exp)
return

client.login()

add_entities([AtomeSensor(name, client)], True)


class AtomeSensor(Entity):
"""Representation of a sensor entity for Atome."""

def __init__(self, name, client: AtomeClient):
"""Initialize the sensor."""
self._name = name
self._client = client
self._state = None

@property
def name(self):
"""Return the name of the sensor."""
return self._name or DEFAULT_NAME
Comment thread
BaQs marked this conversation as resolved.
Outdated

@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return POWER_WATT

@property
def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_POWER

@property
def state(self):
"""Return the state of the sensor."""
return self._state

@Throttle(SESSION_RENEW_INTERVAL)
def _login(self):
Comment thread
BaQs marked this conversation as resolved.
Outdated
"""Login to Atome API, create session."""
self._client.login()

def _get_data(self):
"""Retrieve live data."""
return self._client.get_live()

@Throttle(SCAN_INTERVAL)
Comment thread
BaQs marked this conversation as resolved.
Outdated
def update(self):
"""Update device state."""

try:
values = self._get_data()
self._state = values["last"]
_LOGGER.debug("Updating atome data. Got: %d", self._state)

except KeyError as error:
_LOGGER.error("Missing last value in values: %s: %s", values, error)
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,9 @@ pyarlo==0.2.3
# homeassistant.components.netatmo
pyatmo==2.2.1

# homeassistant.components.atome
pyatome==0.0.15

# homeassistant.components.apple_tv
pyatv==0.3.12

Expand Down