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

Modified to work on 0.91.2 and added functionality #1

Merged
merged 6 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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 custom_components/anna/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REQUIREMENTS = ['haanna==0.6.2']
CoMPaTech marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,62 @@
port: 80
scan_interval: 10
"""
REQUIREMENTS = ['haanna==0.6.1']

import voluptuous as vol
import logging

from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA, SUPPORT_TARGET_TEMPERATURE)
from homeassistant.const import (CONF_NAME, CONF_HOST, CONF_PORT, CONF_USERNAME, CONF_PASSWORD, TEMP_CELSIUS, ATTR_TEMPERATURE)
import xml.etree.cElementTree as Etree

import haanna

from homeassistant.components.climate import (
ClimateDevice,
PLATFORM_SCHEMA)

from homeassistant.components.climate.const import (
DOMAIN,
SUPPORT_HOLD_MODE,
SUPPORT_AWAY_MODE,
SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE,
STATE_AUTO,
STATE_IDLE,
SERVICE_SET_HOLD_MODE)

from homeassistant.const import (
CONF_NAME,
CONF_HOST,
CONF_PORT,
CONF_USERNAME,
CONF_PASSWORD,
TEMP_CELSIUS,
ATTR_TEMPERATURE,
STATE_ON,
STATE_OFF)
import homeassistant.helpers.config_validation as cv

SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE
SUPPORT_FLAGS = ( SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE | SUPPORT_HOLD_MODE | SUPPORT_AWAY_MODE )
Copy link
Owner

@laetificat laetificat Apr 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operation mode and away mode have no implementation. Using any of these options returns errors.

I'm not sure what operation mode is supposed to do, the HASS docs say "Operation mode to set temperature to. This defaults to current_operation mode if not set, or set incorrectly.", but isn't this already achieved by using the hold mode?

I'm also not able to set the hold mode at the moment, there is no option to select "home", "vacation", etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operation mode I was looking into to switch schedules, but it's a little more difficult (I know how to activate them again, but there is your custom (or more?) schedule and the learning schedule. Not sure though like you state if using operation mode for that is the best.

Hold mode can be set but the way hass-climate seems to have this done is using service climate.set_hold_mode.

On changing the support flags, good call - I shouldn't have left the partials in - but not sure either on the implementation.

Hold-mode - seems legit for home/vacation etc. - works using the service call
Operation-mode - was looking into (ab)using this for schedule on/of
Away-mode - the device supports it, but I recon me only having it put up it still needs to 'learn', the way the docs of plugwise state it they use geofencing on their app for this? (Not sure if I particularly like it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented these out until we have a decision on how to go from here (code is still in, but not advertising them)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way could be to use 'presets' as 'operation_mode' so users can adjust it from the UI directly and either not bother about the schedules or move those as 'hold_mode'. The way I read the code-comments, code-issues and some on the forum is that hold_mode is about retaining temperature at a set (i.e. hold) point, therefor our presets of Anna would align on hold_mode, right? Question would (or can) be, how (or if) we want to bother with being on schedule or not.


_LOGGER = logging.getLogger(__name__)

ICON = "mdi:thermometer"

DEFAULT_NAME = 'Anna Thermostat'
DEFAULT_USERNAME = 'smile'
DEFAULT_TIMEOUT = 10
BASE_URL = 'http://{0}:{1}{2}'

# Hold modes
MODE_HOME = "home"
MODE_VACATION = "vacation"
MODE_NO_FROST = "no_frost"
MODE_SLEEP = "asleep"
MODE_AWAY = "away"

# Change defaults to match Anna
DEFAULT_MIN_TEMP = 4
DEFAULT_MAX_TEMP = 30

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_HOST): cv.string,
Expand All @@ -55,6 +93,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ThermostatDevice(ClimateDevice):
"""Representation of an Anna thermostat"""
def __init__(self, name, username, password, host, port):
_LOGGER.debug("Init called")
self._name = name
self._username = username
self._password = password
Expand All @@ -63,31 +102,65 @@ def __init__(self, name, username, password, host, port):
self._temperature = None
self._current_temperature = None
self._outdoor_temperature = None
self._target_min_temperature = 4
self._target_max_temperature = 30
self._state = None
self._hold_mode = None
self._away_mode = False
_LOGGER.debug("Init called")
self._operation_list = [ STATE_AUTO, STATE_IDLE ]
_LOGGER.debug("Initializing API")
self.update()

@property
def should_poll(self):
"""Polling is needed"""
return True

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

def update(self):
"""Update the data from the thermostat"""
import haanna
api = haanna.Haanna(self._username, self._password, self._host)
domain_objects = api.get_domain_objects()
self._current_temperature = api.get_temperature(domain_objects)
self._outdoor_temperature = api.get_outdoor_temperature(domain_objects)
self._temperature = api.get_target_temperature(domain_objects)
self._hold_mode = api.get_current_preset(domain_objects)
if api.get_mode(domain_objects) == True:
self._operation_mode=STATE_AUTO
else:
self._operation_mode=STATE_IDLE
if api.get_heating_status(domain_objects) == True:
self._state=STATE_ON
else:
self._state=STATE_OFF
_LOGGER.debug("Update called")

@property
def name(self):
return self._name

@property
def current_hold_mode(self):
"""Return the current hold mode, e.g., home, away, temp."""
return self._hold_mode

@property
def operation_list(self):
"""Return the operation modes list."""
return self._operation_list

@property
def current_operation(self):
"""Return current operation ie. auto, idle."""
return self._operation_mode

@property
def icon(self):
"""Return the icon to use in the frontend."""
return ICON

@property
def current_temperature(self):
return self._current_temperature
Expand All @@ -96,6 +169,7 @@ def current_temperature(self):
def target_temperature(self):
return self._temperature

@property
def outdoor_temperature(self):
return self._outdoor_temperature

Expand All @@ -113,9 +187,20 @@ def set_temperature(self, **kwargs):
import haanna
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is not None:
self._temperature = temperature
api = haanna.Haanna(self._username, self._password, self._host)
self._temperature = temperature
domain_objects = api.get_domain_objects()
api.set_temperature(domain_objects, temperature)
self.schedule_update_ha_state()

def set_hold_mode(self, hold_mode):
"""Set the hold mode."""
if hold_mode is not None:
api = haanna.Haanna(self._username, self._password, self._host)
domain_objects = api.get_domain_objects()
self._hold_mode = hold_mode
api.set_preset(domain_objects, hold_mode)
_LOGGER.info('Changing hold mode/preset')
else:
_LOGGER.error('Failed to change hold mode (invalid preset)')

8 changes: 8 additions & 0 deletions custom_components/anna/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"domain": "anna",
"name": "Plugwise_Anna",
"documentation": "https://github.com/laetificat/anna-ha",
"dependencies": ["climate"],
CoMPaTech marked this conversation as resolved.
Show resolved Hide resolved
"codeowners": ["@laetificat","CoMPaTech"],
"requirements": ["haanna==0.6.2"]
}