Skip to content

Commit

Permalink
Initial support for the whitelist option (so far only the option itse…
Browse files Browse the repository at this point in the history
…lf).

There should be a list of mac-addresses.
A list of addresses from the encryptors option is added automatically.
If there are no addresses other than those listed in the encryptors option,
then the whitelist option is enough to make True.
Default value - False.
  • Loading branch information
Magalex2x14 committed Apr 26, 2020
1 parent c3e1a82 commit e63d001
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions custom_components/mitemp_bt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
CONF_BATT_ENTITIES = "batt_entities"
CONF_ENCRYPTORS = "encryptors"
CONF_REPORT_UNKNOWN = "report_unknown"
CONF_WHITELIST = "whitelist"

# Default values for configuration options
DEFAULT_ROUNDING = True
Expand All @@ -22,6 +23,7 @@
DEFAULT_HCI_INTERFACE = 0
DEFAULT_BATT_ENTITIES = False
DEFAULT_REPORT_UNKNOWN = False
DEFAULT_WHITELIST = False


"""Fixed constants."""
Expand Down
18 changes: 18 additions & 0 deletions custom_components/mitemp_bt/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
DEFAULT_HCI_INTERFACE,
DEFAULT_BATT_ENTITIES,
DEFAULT_REPORT_UNKNOWN,
DEFAULT_WHITELIST,
CONF_ROUNDING,
CONF_DECIMALS,
CONF_PERIOD,
Expand All @@ -44,6 +45,7 @@
CONF_BATT_ENTITIES,
CONF_ENCRYPTORS,
CONF_REPORT_UNKNOWN,
CONF_WHITELIST,
CONF_TMIN,
CONF_TMAX,
CONF_HMIN,
Expand Down Expand Up @@ -78,6 +80,9 @@
vol.Optional(CONF_BATT_ENTITIES, default=DEFAULT_BATT_ENTITIES): cv.boolean,
vol.Optional(CONF_ENCRYPTORS, default={}): ENCRYPTORS_LIST_SCHEMA,
vol.Optional(CONF_REPORT_UNKNOWN, default=DEFAULT_REPORT_UNKNOWN): cv.boolean,
vol.Optional(
CONF_WHITELIST, default=DEFAULT_WHITELIST
): vol.Any(vol.All(cv.ensure_list, [cv.matches_regex(MAC_REGEX)]), cv.boolean),
}
)

Expand Down Expand Up @@ -417,6 +422,19 @@ def lpacket(mac, packet=None):
p_key = bytes.fromhex(config[CONF_ENCRYPTORS][mac].lower())
aeskeys[p_mac] = p_key
_LOGGER.debug("%s encryptors mac:key pairs loaded.", len(aeskeys))
whitelist = []
if isinstance(config[CONF_WHITELIST], bool):
if config[CONF_WHITELIST] is True:
for mac in config[CONF_ENCRYPTORS]:
whitelist.append(mac)
if isinstance(config[CONF_WHITELIST], list):
for mac in config[CONF_WHITELIST]:
whitelist.append(mac)
for mac in config[CONF_ENCRYPTORS]:
whitelist.append(mac)
for i, mac in enumerate(whitelist):
whitelist[i] = bytes.fromhex(reverse_mac(mac.replace(":", "")).lower())
_LOGGER.debug("%s whitelist item(s) loaded.", len(aeskeys))
lpacket.cntr = {}
sleep(1)

Expand Down

0 comments on commit e63d001

Please sign in to comment.