Skip to content

Commit

Permalink
fix: hide "disabled" switch
Browse files Browse the repository at this point in the history
  • Loading branch information
rxwen committed Mar 21, 2021
1 parent fb7d867 commit 442aff8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
7 changes: 7 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity_platform import async_get_platforms

from .utils import get_attr_value
from .const import (
DOMAIN,
HA_CLIENT_ID,
Expand Down Expand Up @@ -212,6 +213,12 @@ async def update_or_create_entity(dev, tern):
return []

devid = svc["id"]

disableRelay = get_attr_value(svc["attributes"], "disableRelay")
if disableRelay != None and disableRelay == 1:
_LOGGER.info("%s is disabled, skip it", devid)
return []

name = svc["name"]
if name == "":
name = devid
Expand Down
9 changes: 1 addition & 8 deletions binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)

from .const import DOMAIN, TERNCY_MANU_NAME
from .utils import get_attr_value

_LOGGER = logging.getLogger(__name__)

Expand All @@ -25,14 +26,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
_LOGGER.info(" terncy curtain async_setup_platform")


def get_attr_value(attrs, key):
"""Read attr value from terncy attributes."""
for att in attrs:
if "attr" in att and att["attr"] == key:
return att["value"]
return None


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Terncy curtain from a config entry."""
_LOGGER.info("setup terncy curtain platform")
Expand Down
9 changes: 1 addition & 8 deletions cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)

from .const import DOMAIN, TERNCY_MANU_NAME
from .utils import get_attr_value

_LOGGER = logging.getLogger(__name__)

Expand All @@ -27,14 +28,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
_LOGGER.info(" terncy curtain async_setup_platform")


def get_attr_value(attrs, key):
"""Read attr value from terncy attributes."""
for att in attrs:
if "attr" in att and att["attr"] == key:
return att["value"]
return None


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Terncy curtain from a config entry."""
_LOGGER.info("setup terncy curtain platform")
Expand Down
9 changes: 1 addition & 8 deletions light.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)

from .const import DOMAIN, TERNCY_MANU_NAME
from .utils import get_attr_value

_LOGGER = logging.getLogger(__name__)

Expand All @@ -33,14 +34,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
_LOGGER.info(" terncy light async_setup_platform")


def get_attr_value(attrs, key):
"""Read attr value from terncy attributes."""
for att in attrs:
if "attr" in att and att["attr"] == key:
return att["value"]
return None


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Terncy lights from a config entry."""
_LOGGER.info("setup terncy light platform")
Expand Down
9 changes: 1 addition & 8 deletions switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)

from .const import DOMAIN, TERNCY_MANU_NAME
from .utils import get_attr_value

_LOGGER = logging.getLogger(__name__)

Expand All @@ -23,14 +24,6 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
_LOGGER.info(" terncy smart plug async_setup_platform")


def get_attr_value(attrs, key):
"""Read attr value from terncy attributes."""
for att in attrs:
if "attr" in att and att["attr"] == key:
return att["value"]
return None


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Terncy smart plugs from a config entry."""
_LOGGER.info("setup terncy smart plug platform")
Expand Down
9 changes: 9 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""The Terncy utils."""

def get_attr_value(attrs, key):
"""Read attr value from terncy attributes."""
for att in attrs:
if "attr" in att and att["attr"] == key:
return att["value"]
return None

0 comments on commit 442aff8

Please sign in to comment.