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

Added component named switcher_kis switcher water heater integration. #22325

Merged
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fbbbced
Added component named switcher_kis switcher water heater integration.
TomerFi Mar 23, 2019
5d2044f
Fixed conflicts.
TomerFi Apr 6, 2019
4820ba6
Updated requirements.
TomerFi Apr 6, 2019
17cef18
Added manifest.json file and updated CODEOWNERS.
TomerFi Apr 6, 2019
cb00473
Fixed requirements_all.txt.
TomerFi Apr 6, 2019
8aaa421
Better component tests.
TomerFi Apr 10, 2019
bb21856
Removed unnecessary parameter from fixture function.
TomerFi Apr 10, 2019
6ee2968
Removed tests section from mypy.ini.
TomerFi Apr 11, 2019
d0391d7
Remove unused ENTITY_ID_FORMAT.
TomerFi Apr 11, 2019
c9f28a5
Stop udp bridge when failed to setup the component.
TomerFi Apr 11, 2019
e70407e
Replace DISCOVERY_ constants prefix with DATA_.
TomerFi Apr 11, 2019
d65ed8f
Various change requests.
TomerFi Apr 11, 2019
0736cf1
Fixed constant name change remifications.
TomerFi Apr 11, 2019
26815c8
Added explicit name to fixture.
TomerFi Apr 11, 2019
d62f99f
Various change requests.
TomerFi Apr 11, 2019
38619e8
More various change requests.
TomerFi Apr 11, 2019
011dd16
Added EventType for homeassistant.core.Event.
TomerFi Apr 12, 2019
f778981
Switched from event driven data distribution to dispatcher type plus …
TomerFi Apr 12, 2019
6a50f3f
Removed name and icon keys from the component configuration.
TomerFi Apr 12, 2019
3495e05
Various change requests.
TomerFi Apr 13, 2019
0bd8b08
Various change reqeusts and clean-ups.
TomerFi Apr 13, 2019
e7b2330
Removed unnecessary DEPENDENCIES constant from swith platform.
TomerFi Apr 13, 2019
c4441c8
Replaced configuration data guard with assert.
TomerFi Apr 13, 2019
8babc45
Removed unused constants.
TomerFi Apr 13, 2019
de6a41f
Removed confusing type casting for mypy sake.
TomerFi Apr 13, 2019
105df9f
Refactor property device_name to name.
TomerFi Apr 13, 2019
b1c68d9
Removed None guard effecting mypy only.
TomerFi Apr 13, 2019
dccbe44
Removed unnecessary function from switch entity.
TomerFi Apr 13, 2019
6709f09
Removed None guard in use by mypy only.
TomerFi Apr 13, 2019
77458d1
Removed unused constant.
TomerFi Apr 13, 2019
5237b97
Removed unnecessary context manager.
TomerFi Apr 13, 2019
a53ee0d
Stopped messing around with mypy.ini.
TomerFi Apr 13, 2019
f3812d3
Referring to typing.TYPE_CHECKING for non-runtime imports.
TomerFi Apr 13, 2019
c18e742
Added test requierment correctyly.
TomerFi Apr 13, 2019
c518dc4
Replaced queue.get() with queue.get_nowait() to avoid backing up inte…
TomerFi Apr 13, 2019
cb7ab11
Revert changes in mypy.ini.
TomerFi Apr 14, 2019
02704fb
Changed attributes content to device properties instead of entity pro…
TomerFi Apr 15, 2019
f63e694
Fixed typo in constant name.
TomerFi Apr 15, 2019
5b30d84
Remove unnecessary async keyword from callable.
TomerFi Apr 15, 2019
0557f5a
Waiting for tasks on event loop to end.
TomerFi Apr 15, 2019
e26245e
Added callback decorator to callable.
TomerFi Apr 19, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Referring to typing.TYPE_CHECKING for non-runtime imports.

  • Loading branch information...
TomerFi committed Apr 13, 2019
commit f3812d35cc017301d4702c33a0809f913585959f
@@ -1,7 +1,7 @@
"""Home Assistant Switcher Component Switch platform."""

from logging import getLogger
from typing import Any, Callable, Dict
from typing import Callable, Dict, TYPE_CHECKING

from homeassistant.components.switch import ATTR_CURRENT_POWER_W, SwitchDevice
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@@ -11,6 +11,11 @@
ATTR_AUTO_OFF_SET, ATTR_ELECTRIC_CURRNET, ATTR_REMAINING_TIME,
DATA_DEVICE, DOMAIN, SIGNAL_SWITCHER_DEVICE_UPDATE)

if TYPE_CHECKING:
from aioswitcher.devices import SwitcherV2Device
from aioswitcher.api.messages import SwitcherV2ControlResponseMSG


_LOGGER = getLogger(__name__)

PROPERTIES_TO_DEVICE_ATTRIBUTES = {
@@ -32,13 +37,10 @@
class SwitcherControl(SwitchDevice):
"""Home Assistant switch entity."""

def __init__(self, device_data: Any) -> None:
def __init__(self, device_data: 'SwitcherV2Device') -> None:
"""Initialize the entity."""
# pylint: disable=unused-import
from aioswitcher.devices import SwitcherV2Device
# pylint: enable=unused-import
self._self_initiated = False
self._device_data = device_data # type: SwitcherV2Device
self._device_data = device_data
self._state = device_data.state

@property
@@ -109,17 +111,13 @@ def available(self) -> bool:
async_dispatcher_connect(
self.hass, SIGNAL_SWITCHER_DEVICE_UPDATE, self.async_update_data)

async def async_update_data(self, device_data: Any) -> None:
async def async_update_data(self, device_data: 'SwitcherV2Device') -> None:
"""Update the entity data."""
# pylint: disable=unused-import
from aioswitcher.devices import SwitcherV2Device
# pylint: enable=unused-import
temp_device = device_data # type: SwitcherV2Device
if temp_device:
if device_data:
if self._self_initiated:
This conversation was marked as resolved by andrewsayre

This comment has been minimized.

Copy link
@awarecan

awarecan Apr 13, 2019

Contributor

I have a little confuse about this, is _self_initiated really means as it's name?

This comment has been minimized.

Copy link
@TomerFi

TomerFi Apr 13, 2019

Author Contributor

@awarecan
First of all, thank you for your much appreciated review, I've already started working on your change requests.

In regards to your question:
The data updates from the device comes via a UDP connection approximately every 4 seconds.
The commands send to device, for example turn on/off are manual TCP requests.

When a TCP request for turning on the device is sent just before or whilst the UDP data update is being transmitted, we end up with a false outcome because according to the data update, the device is off but in HA it just been marked on.
The result is the entity being turned on and almost immediately being turned off (although the device is actually turned on) and in about 4 seconds it'll get the correct data update and get turned on again.

To resolve this, the _self_initiated==True marks the the turn on/off request was sent by HA entity, in which case the update process will skip the current data update and re-set _self_initiated=False so that the next update go on correctly.

Maybe the name _self_initiated is confusing.
Would you recommend changing it perhaps?

This comment has been minimized.

Copy link
@andrewsayre

andrewsayre Apr 14, 2019

Member

I initially read it as initialized -- wonder if you did too @awarecan. I think initiated is fine in this case. Ideally, this would be logic handled by the library -- not inside HASS, but you can address that in the future.

This comment has been minimized.

Copy link
@awarecan

awarecan Apr 14, 2019

Contributor

@andrewsayre, you are exactly right, I have read it as initialized 😄

self._self_initiated = False
else:
self._device_data = temp_device
self._device_data = device_data
self._state = self._device_data.state
self.async_schedule_update_ha_state()

@@ -140,9 +138,6 @@ def available(self) -> bool:
async def _control_device(self, send_on: bool) -> None:
"""Turn the entity on or off."""
from aioswitcher.api import SwitcherV2Api
# pylint: disable=unused-import
from aioswitcher.api.messages import SwitcherV2ControlResponseMSG
# pylint: enable=unused-import
from aioswitcher.consts import (COMMAND_OFF, COMMAND_ON,
STATE_OFF as SWITCHER_STATE_OFF,
STATE_ON as SWITCHER_STATE_ON)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.