Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion homeassistant/components/dynalite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def validate_area(config: Dict[str, Any]) -> Dict[str, Any]:
vol.All(
{
vol.Required(CONF_NAME): cv.string,
vol.Optional(CONF_TEMPLATE): cv.string,
vol.Optional(CONF_TEMPLATE): vol.In(DEFAULT_TEMPLATES),
vol.Optional(CONF_FADE): vol.Coerce(float),
vol.Optional(CONF_NO_DEFAULT): cv.boolean,
vol.Optional(CONF_CHANNEL): CHANNEL_SCHEMA,
Expand Down
19 changes: 7 additions & 12 deletions homeassistant/components/dynalite/bridge.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
"""Code to handle a Dynalite bridge."""

from typing import TYPE_CHECKING, Any, Callable, Dict, List
from typing import Any, Callable, Dict, List, Optional

from dynalite_devices_lib.dynalite_devices import DynaliteDevices
from dynalite_devices_lib.dynalite_devices import DynaliteBaseDevice, DynaliteDevices

from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_send

from .const import CONF_ALL, ENTITY_PLATFORMS, LOGGER
from .const import ENTITY_PLATFORMS, LOGGER
from .convert_config import convert_config

if TYPE_CHECKING: # pragma: no cover
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 needs to remain there or else the type checking won't work. (you can test it with mypy <path to file>)

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.

that is exactly the weird behavior i had. when i moved it from DynaliteBaseDevice to Optional, flake8 didn't let me commit because it said it is unused. When I removed it, flake8 worked and mypy had no problem (see checks below). Weird.
Perhaps I can remove the Optional[] here? Since we don't define the flag '--no-implicit-optional", if it is defined with a default value of NULL, mypy understands its Optional by default?

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.

in any case, i figured out that i don't need "if TYPE_CHECKING" since there is no circular dependency, so while I still don't understnad why it happened, the problem is no longer relevant

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.

Oh I missed that you import it now from the package directly. ok 👍

from dynalite_devices_lib.dynalite_devices import ( # pylint: disable=ungrouped-imports
DynaliteBaseDevice,
)


class DynaliteBridge:
"""Manages a single Dynalite bridge."""
Expand Down Expand Up @@ -45,7 +40,7 @@ def reload_config(self, config: Dict[str, Any]) -> None:
LOGGER.debug("Reloading bridge - host %s, config %s", self.host, config)
self.dynalite_devices.configure(convert_config(config))

def update_signal(self, device: "DynaliteBaseDevice" = None) -> str:
def update_signal(self, device: Optional[DynaliteBaseDevice] = None) -> str:
"""Create signal to use to trigger entity update."""
if device:
signal = f"dynalite-update-{self.host}-{device.unique_id}"
Expand All @@ -54,9 +49,9 @@ def update_signal(self, device: "DynaliteBaseDevice" = None) -> str:
return signal

@callback
def update_device(self, device: "DynaliteBaseDevice") -> None:
def update_device(self, device: Optional[DynaliteBaseDevice] = None) -> None:
"""Call when a device or all devices should be updated."""
if device == CONF_ALL:
if not device:
# This is used to signal connection or disconnection, so all devices may become available or not.
log_string = (
"Connected" if self.dynalite_devices.connected else "Disconnected"
Expand All @@ -73,7 +68,7 @@ def register_add_devices(self, platform: str, async_add_devices: Callable) -> No
if platform in self.waiting_devices:
self.async_add_devices[platform](self.waiting_devices[platform])

def add_devices_when_registered(self, devices: List["DynaliteBaseDevice"]) -> None:
def add_devices_when_registered(self, devices: List[DynaliteBaseDevice]) -> None:
"""Add the devices to HA if the add devices callback was registered, otherwise queue until it is."""
for platform in ENTITY_PLATFORMS:
platform_devices = [
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/dynalite/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
ACTIVE_INIT = "init"
ACTIVE_OFF = "off"
ACTIVE_ON = "on"
CONF_ALL = "ALL"
CONF_AREA = "area"
CONF_AUTO_DISCOVER = "autodiscover"
CONF_BRIDGES = "bridges"
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/dynalite/convert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

CONF_MAP = {
CONF_ACTIVE: dyn_const.CONF_ACTIVE,
ACTIVE_INIT: dyn_const.CONF_ACTIVE_INIT,
ACTIVE_OFF: dyn_const.CONF_ACTIVE_OFF,
ACTIVE_ON: dyn_const.CONF_ACTIVE_ON,
ACTIVE_INIT: dyn_const.ACTIVE_INIT,
ACTIVE_OFF: dyn_const.ACTIVE_OFF,
ACTIVE_ON: dyn_const.ACTIVE_ON,
CONF_AREA: dyn_const.CONF_AREA,
CONF_AUTO_DISCOVER: dyn_const.CONF_AUTO_DISCOVER,
CONF_CHANNEL: dyn_const.CONF_CHANNEL,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/dynalite/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/dynalite",
"codeowners": ["@ziv1234"],
"requirements": ["dynalite_devices==0.1.39"]
"requirements": ["dynalite_devices==0.1.40"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ dsmr_parser==0.18
dweepy==0.3.0

# homeassistant.components.dynalite
dynalite_devices==0.1.39
dynalite_devices==0.1.40

# homeassistant.components.rainforest_eagle
eagle200_reader==0.2.4
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ doorbirdpy==2.0.8
dsmr_parser==0.18

# homeassistant.components.dynalite
dynalite_devices==0.1.39
dynalite_devices==0.1.40

# homeassistant.components.ee_brightbox
eebrightbox==0.0.4
Expand Down
3 changes: 1 addition & 2 deletions tests/components/dynalite/test_bridge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test Dynalite bridge."""

from asynctest import CoroutineMock, Mock, patch
from dynalite_devices_lib.const import CONF_ALL

from homeassistant.components import dynalite
from homeassistant.helpers.dispatcher import async_dispatcher_connect
Expand Down Expand Up @@ -29,7 +28,7 @@ async def test_update_device(hass):
async_dispatcher_connect(
hass, f"dynalite-update-{host}-{device.unique_id}", specific_func
)
update_device_func(CONF_ALL)
update_device_func()
await hass.async_block_till_done()
wide_func.assert_called_once()
specific_func.assert_not_called()
Expand Down