Skip to content

Add ST218 (Zigbee Thermostat) support#10495

Closed
titilambert wants to merge 6 commits into
home-assistant:devfrom
titilambert:st218
Closed

Add ST218 (Zigbee Thermostat) support#10495
titilambert wants to merge 6 commits into
home-assistant:devfrom
titilambert:st218

Conversation

@titilambert
Copy link
Copy Markdown
Contributor

@titilambert titilambert commented Nov 9, 2017

Description:

Add ST218 (Zigbee Thermostat) support

Could be cleaned when zigpy/bellows#71 is merged

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#3971

Checklist:

If user exposed functionality or configuration variables are added/changed:

  • Documentation added/updated in home-assistant.github.io
  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

Comment thread homeassistant/components/zha/const.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

missing whitespace around operator

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (87 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

too many blank lines (2)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (90 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (93 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (87 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (87 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

closing bracket does not match visual indentation

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (87 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (87 > 79 characters)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

missing whitespace after ','

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You probably meant "climate device" here. ;)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These should be constants, preferrably taken from the STATE_* constants in climate/init.py

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you set this only to translate it later into TEMP_CELSIUS? Can't you directly set TEMP_CELSIUS here?

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As far as I can see, self._unit is set exactly once, on initialization, and always to "C". So this should always return TEMP_CELSIUS? Is self._unit still necessary then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to https://home-assistant.io/components/climate/ , this call can also be used to set operation mode and temperature in one go. Your method seems to ignore the operation mode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same typo as above

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

too many blank lines (2)

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 1 blank line before a nested definition, found 0
at least two spaces before inline comment

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'homeassistant.const.TEMP_FAHRENHEIT' imported but unused

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'homeassistant.components.climate.STATE_HEAT' imported but unused

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

at least two spaces before inline comment

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

We shouldn't merge this until the required PR in bellows is merged.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This dict could be moved to the module level as a constant.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above for this list.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you know that the key is in the dict, don't use dict.get(key), just access the key directly, dict[key].

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cache the operation mode to avoid two lookups.

operation_mode = kwargs.get(ATTR_OPERATION_MODE)
if operation_mode is not None:
    yield from...

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above. Also invert the check.

if temperature is None:
    return
yield from...

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd extract these magic bytes into constants.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You still set the operation, even if it is not a possible operation - is that intended? Have you tested what that does to the front end? I guess no operation mode will be shown in the front end in this case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better use dict.get here like it was before. Then it will return None if raw_mode is missing in OPERATIONS.

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This probably fails if there are multiple requests "in the queue": Say I call a service that requires communication three times simultaneously. The first one goes through and sets last_request to the current time. The next two requests both sleep for one second and then perform their request within the same second (if the machine is fast enough). I think you need to loop here, calling asyncio.sleep until time.time() - self.last_request >= CLEAN_TIME_ZONE becomes true.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe you could add a lock that is acquired before entering the sleep and released after the sleep?

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this should at least print an error message if a read fails.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Couldn't we also pinpoint the exception to eg OSError?

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This throws if raw_mode not in OPERATIONS. Is that intended? I don't think so, as that also causes the temperatures not to be updated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe just missing else statement

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How can self._target_temperature < 0 happen? Is that used as error indicator somewhere? I can't find it.

Copy link
Copy Markdown
Contributor

@tinloaf tinloaf left a comment

Choose a reason for hiding this comment

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

See inline code comments


SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE

@asyncio.coroutine
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

@rcloran rcloran mentioned this pull request Jan 15, 2018
9 tasks
"""
Climate on Zigbee Home Automation networks.

For more details on this platform, please refer to the documentation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add in this description the model and manufacturer supported.

# Clean data
for data in ('manufacturer', 'model'):
if isinstance(discovery_info.get(data), bytes):
discovery_info[data] = discovery_info[data]\
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a debug log with raw data. Useful if the manufacturer changes message format and you don't have a device at hand to debug.

discovery_info[data] = discovery_info[data]\
.split(b'\x00')[0].decode('utf-8')
elif isinstance(discovery_info.get(data), str):
discovery_info[data] = discovery_info[data].split('\x00')[0]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a debug log with raw data. Useful if the manufacturer changes message format and you don't have a device at hand to debug.

class ClimateST218(zha.Entity, ClimateDevice):
"""Climage Stelpro ST218."""

_domain = DOMAIN
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this used anywhere?

for result in res:
for subresult in result:
if subresult.status != NO_ERROR_ANSWER_CODE:
_LOGGER.error("Error setting operation mode: %s",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this message correct? Seems you're showing operation mode message for result of temperature set.

OPERATIONS = {0: STATE_OFF,
4: STATE_COMFORT,
5: STATE_ECO}
REVERSE_OPERATIONS = dict((v, k) for k, v in OPERATIONS.items())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is REVERSE_OPERATIONS used?

Comment thread homeassistant/components/climate/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe just missing else statement

if operation_mode is not None:
yield from self.async_set_operation_mode(operation_mode)

temperature = kwargs.get(ATTR_TEMPERATURE)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe name this raw_temp to be consistent before applying transformation

@balloob
Copy link
Copy Markdown
Member

balloob commented Feb 18, 2018

Bellows PR has been merged. What is the status of this PR?

@titilambert
Copy link
Copy Markdown
Contributor Author

@balloob The PR was closed, the bellows devs are currently refactoring it.
So I'm closing it, and I will reopen it when it's ready.

BTW, Thanks for your work !

@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants