Compare commits

...

10 Commits

Author SHA1 Message Date
Fabio Manganiello 99de5318ff
Merge pull request #313 from BlackLight/snyk-upgrade-58f5a7acf019c661bec911d06f0bf10a
[Snyk] Upgrade core-js from 3.21.1 to 3.23.4
2022-08-05 13:26:25 +02:00
Fabio Manganiello b3bab9b1d8
Merge pull request #314 from BlackLight/snyk-upgrade-9823d0f9eee2d94f4547598322ba6a48
[Snyk] Upgrade vue-router from 4.0.14 to 4.1.2
2022-08-05 13:26:07 +02:00
Fabio Manganiello 7e4877c793
Merge pull request #315 from BlackLight/snyk-upgrade-30cde2b595c9da96da481c691c0964d5
[Snyk] Upgrade sass from 1.49.9 to 1.53.0
2022-08-05 13:23:38 +02:00
Fabio Manganiello 55602cc282
Merge branch 'master' into snyk-upgrade-30cde2b595c9da96da481c691c0964d5 2022-08-05 13:05:25 +02:00
Fabio Manganiello d2053a012a
Merge pull request #316 from BlackLight/snyk-upgrade-ba00badb7e42a7b25417256efb18f67b
[Snyk] Upgrade sass-loader from 10.2.1 to 10.3.1
2022-08-05 13:03:46 +02:00
snyk-bot 3d5fc9a10b
fix: upgrade sass-loader from 10.2.1 to 10.3.1
Snyk has created this PR to upgrade sass-loader from 10.2.1 to 10.3.1.

See this package in npm:
https://www.npmjs.com/package/sass-loader

See this project in Snyk:
https://app.snyk.io/org/blacklight/project/96bfd125-5816-4d9e-83c6-94d1569ab0f1?utm_source=github&utm_medium=referral&page=upgrade-pr
2022-08-04 20:31:51 +00:00
snyk-bot be4dd48d76
fix: upgrade sass from 1.49.9 to 1.53.0
Snyk has created this PR to upgrade sass from 1.49.9 to 1.53.0.

See this package in npm:
https://www.npmjs.com/package/sass

See this project in Snyk:
https://app.snyk.io/org/blacklight/project/96bfd125-5816-4d9e-83c6-94d1569ab0f1?utm_source=github&utm_medium=referral&page=upgrade-pr
2022-08-04 20:31:45 +00:00
snyk-bot bd21779a17
fix: upgrade vue-router from 4.0.14 to 4.1.2
Snyk has created this PR to upgrade vue-router from 4.0.14 to 4.1.2.

See this package in npm:
https://www.npmjs.com/package/vue-router

See this project in Snyk:
https://app.snyk.io/org/blacklight/project/96bfd125-5816-4d9e-83c6-94d1569ab0f1?utm_source=github&utm_medium=referral&page=upgrade-pr
2022-08-04 20:31:33 +00:00
snyk-bot 58afc1090c
fix: upgrade core-js from 3.21.1 to 3.23.4
Snyk has created this PR to upgrade core-js from 3.21.1 to 3.23.4.

See this package in npm:
https://www.npmjs.com/package/core-js

See this project in Snyk:
https://app.snyk.io/org/blacklight/project/96bfd125-5816-4d9e-83c6-94d1569ab0f1?utm_source=github&utm_medium=referral&page=upgrade-pr
2022-08-04 20:31:28 +00:00
Fabio Manganiello 7c87238fec
match_condition should return immediately (no score-based fuzzy search) if an event condition is an exact match 2022-08-04 01:04:00 +02:00
3 changed files with 97 additions and 72 deletions

View File

@ -10,13 +10,13 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.15.4", "@fortawesome/fontawesome-free": "^5.15.4",
"axios": "^0.21.4", "axios": "^0.21.4",
"core-js": "^3.21.1", "core-js": "^3.23.4",
"lato-font": "^3.0.0", "lato-font": "^3.0.0",
"mitt": "^2.1.0", "mitt": "^2.1.0",
"sass": "^1.49.9", "sass": "^1.53.0",
"sass-loader": "^10.2.1", "sass-loader": "^10.3.1",
"vue": "^3.2.13", "vue": "^3.2.13",
"vue-router": "^4.0.14", "vue-router": "^4.1.2",
"vue-skycons": "^4.2.0", "vue-skycons": "^4.2.0",
"w3css": "^2.7.0" "w3css": "^2.7.0"
}, },
@ -2768,9 +2768,9 @@
"dev": true "dev": true
}, },
"node_modules/@vue/devtools-api": { "node_modules/@vue/devtools-api": {
"version": "6.1.3", "version": "6.2.1",
"resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-6.1.3.tgz", "resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-6.2.1.tgz",
"integrity": "sha512-79InfO2xHv+WHIrH1bHXQUiQD/wMls9qBk6WVwGCbdwP7/3zINtvqPNMtmSHXsIKjvUAHc8L0ouOj6ZQQRmcXg==" "integrity": "sha512-OEgAMeQXvCoJ+1x8WyQuVZzFo0wcyCmUR3baRVLmKBo1LmYZWMlRiXlux5jd0fqVJu6PfDbOrZItVqUEzLobeQ=="
}, },
"node_modules/@vue/reactivity": { "node_modules/@vue/reactivity": {
"version": "3.2.31", "version": "3.2.31",
@ -4205,9 +4205,9 @@
} }
}, },
"node_modules/core-js": { "node_modules/core-js": {
"version": "3.21.1", "version": "3.23.4",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.1.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.23.4.tgz",
"integrity": "sha512-FRq5b/VMrWlrmCzwRrpDYNxyHP9BcAZC+xHJaqTgIE5091ZV1NTmyh0sGOg5XqpnHvR0svdy0sv1gWA1zmhxig==", "integrity": "sha512-vjsKqRc1RyAJC3Ye2kYqgfdThb3zYnx9CrqoCcjMOENMtQPC7ZViBvlDxwYU/2z2NI/IPuiXw5mT4hWhddqjzQ==",
"hasInstallScript": true, "hasInstallScript": true,
"funding": { "funding": {
"type": "opencollective", "type": "opencollective",
@ -9402,9 +9402,9 @@
"dev": true "dev": true
}, },
"node_modules/sass": { "node_modules/sass": {
"version": "1.49.9", "version": "1.53.0",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.49.9.tgz", "resolved": "https://registry.npmjs.org/sass/-/sass-1.53.0.tgz",
"integrity": "sha512-YlYWkkHP9fbwaFRZQRXgDi3mXZShslVmmo+FVK3kHLUELHHEYrCmL1x6IUjC7wLS6VuJSAFXRQS/DxdsC4xL1A==", "integrity": "sha512-zb/oMirbKhUgRQ0/GFz8TSAwRq2IlR29vOUJZOx0l8sV+CkHUfHa4u5nqrG+1VceZp7Jfj59SVW9ogdhTvJDcQ==",
"dependencies": { "dependencies": {
"chokidar": ">=3.0.0 <4.0.0", "chokidar": ">=3.0.0 <4.0.0",
"immutable": "^4.0.0", "immutable": "^4.0.0",
@ -9418,9 +9418,9 @@
} }
}, },
"node_modules/sass-loader": { "node_modules/sass-loader": {
"version": "10.2.1", "version": "10.3.1",
"resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-10.2.1.tgz", "resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-10.3.1.tgz",
"integrity": "sha512-RRvWl+3K2LSMezIsd008ErK4rk6CulIMSwrcc2aZvjymUgKo/vjXGp1rSWmfTUX7bblEOz8tst4wBwWtCGBqKA==", "integrity": "sha512-y2aBdtYkbqorVavkC3fcJIUDGIegzDWPn3/LAFhsf3G+MzPKTJx37sROf5pXtUeggSVbNbmfj8TgRaSLMelXRA==",
"dependencies": { "dependencies": {
"klona": "^2.0.4", "klona": "^2.0.4",
"loader-utils": "^2.0.0", "loader-utils": "^2.0.0",
@ -9437,7 +9437,7 @@
}, },
"peerDependencies": { "peerDependencies": {
"fibers": ">= 3.1.0", "fibers": ">= 3.1.0",
"node-sass": "^4.0.0 || ^5.0.0 || ^6.0.0", "node-sass": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
"sass": "^1.3.0", "sass": "^1.3.0",
"webpack": "^4.36.0 || ^5.0.0" "webpack": "^4.36.0 || ^5.0.0"
}, },
@ -10825,11 +10825,11 @@
} }
}, },
"node_modules/vue-router": { "node_modules/vue-router": {
"version": "4.0.14", "version": "4.1.2",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.0.14.tgz", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.1.2.tgz",
"integrity": "sha512-wAO6zF9zxA3u+7AkMPqw9LjoUCjSxfFvINQj3E/DceTt6uEz1XZLraDhdg2EYmvVwTBSGlLYsUw8bDmx0754Mw==", "integrity": "sha512-5BP1qXFncVRwgV/XnqzsKApdMjQPqWIpoUBdL1ynz8HyLxIX/UDAx7Ql2BjmA5CXT/p61JfZvkpiFWFpaqcfag==",
"dependencies": { "dependencies": {
"@vue/devtools-api": "^6.0.0" "@vue/devtools-api": "^6.1.4"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/posva" "url": "https://github.com/sponsors/posva"
@ -13770,9 +13770,9 @@
} }
}, },
"@vue/devtools-api": { "@vue/devtools-api": {
"version": "6.1.3", "version": "6.2.1",
"resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-6.1.3.tgz", "resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-6.2.1.tgz",
"integrity": "sha512-79InfO2xHv+WHIrH1bHXQUiQD/wMls9qBk6WVwGCbdwP7/3zINtvqPNMtmSHXsIKjvUAHc8L0ouOj6ZQQRmcXg==" "integrity": "sha512-OEgAMeQXvCoJ+1x8WyQuVZzFo0wcyCmUR3baRVLmKBo1LmYZWMlRiXlux5jd0fqVJu6PfDbOrZItVqUEzLobeQ=="
}, },
"@vue/reactivity": { "@vue/reactivity": {
"version": "3.2.31", "version": "3.2.31",
@ -14868,9 +14868,9 @@
} }
}, },
"core-js": { "core-js": {
"version": "3.21.1", "version": "3.23.4",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.1.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.23.4.tgz",
"integrity": "sha512-FRq5b/VMrWlrmCzwRrpDYNxyHP9BcAZC+xHJaqTgIE5091ZV1NTmyh0sGOg5XqpnHvR0svdy0sv1gWA1zmhxig==" "integrity": "sha512-vjsKqRc1RyAJC3Ye2kYqgfdThb3zYnx9CrqoCcjMOENMtQPC7ZViBvlDxwYU/2z2NI/IPuiXw5mT4hWhddqjzQ=="
}, },
"core-js-compat": { "core-js-compat": {
"version": "3.21.1", "version": "3.21.1",
@ -18676,9 +18676,9 @@
"dev": true "dev": true
}, },
"sass": { "sass": {
"version": "1.49.9", "version": "1.53.0",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.49.9.tgz", "resolved": "https://registry.npmjs.org/sass/-/sass-1.53.0.tgz",
"integrity": "sha512-YlYWkkHP9fbwaFRZQRXgDi3mXZShslVmmo+FVK3kHLUELHHEYrCmL1x6IUjC7wLS6VuJSAFXRQS/DxdsC4xL1A==", "integrity": "sha512-zb/oMirbKhUgRQ0/GFz8TSAwRq2IlR29vOUJZOx0l8sV+CkHUfHa4u5nqrG+1VceZp7Jfj59SVW9ogdhTvJDcQ==",
"requires": { "requires": {
"chokidar": ">=3.0.0 <4.0.0", "chokidar": ">=3.0.0 <4.0.0",
"immutable": "^4.0.0", "immutable": "^4.0.0",
@ -18686,9 +18686,9 @@
} }
}, },
"sass-loader": { "sass-loader": {
"version": "10.2.1", "version": "10.3.1",
"resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-10.2.1.tgz", "resolved": "https://registry.npmjs.org/sass-loader/-/sass-loader-10.3.1.tgz",
"integrity": "sha512-RRvWl+3K2LSMezIsd008ErK4rk6CulIMSwrcc2aZvjymUgKo/vjXGp1rSWmfTUX7bblEOz8tst4wBwWtCGBqKA==", "integrity": "sha512-y2aBdtYkbqorVavkC3fcJIUDGIegzDWPn3/LAFhsf3G+MzPKTJx37sROf5pXtUeggSVbNbmfj8TgRaSLMelXRA==",
"requires": { "requires": {
"klona": "^2.0.4", "klona": "^2.0.4",
"loader-utils": "^2.0.0", "loader-utils": "^2.0.0",
@ -19746,11 +19746,11 @@
} }
}, },
"vue-router": { "vue-router": {
"version": "4.0.14", "version": "4.1.2",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.0.14.tgz", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.1.2.tgz",
"integrity": "sha512-wAO6zF9zxA3u+7AkMPqw9LjoUCjSxfFvINQj3E/DceTt6uEz1XZLraDhdg2EYmvVwTBSGlLYsUw8bDmx0754Mw==", "integrity": "sha512-5BP1qXFncVRwgV/XnqzsKApdMjQPqWIpoUBdL1ynz8HyLxIX/UDAx7Ql2BjmA5CXT/p61JfZvkpiFWFpaqcfag==",
"requires": { "requires": {
"@vue/devtools-api": "^6.0.0" "@vue/devtools-api": "^6.1.4"
} }
}, },
"vue-skycons": { "vue-skycons": {

View File

@ -10,13 +10,13 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^5.15.4", "@fortawesome/fontawesome-free": "^5.15.4",
"axios": "^0.21.4", "axios": "^0.21.4",
"core-js": "^3.21.1", "core-js": "^3.23.4",
"lato-font": "^3.0.0", "lato-font": "^3.0.0",
"mitt": "^2.1.0", "mitt": "^2.1.0",
"sass": "^1.49.9", "sass": "^1.53.0",
"sass-loader": "^10.2.1", "sass-loader": "^10.3.1",
"vue": "^3.2.13", "vue": "^3.2.13",
"vue-router": "^4.0.14", "vue-router": "^4.1.2",
"vue-skycons": "^4.2.0", "vue-skycons": "^4.2.0",
"w3css": "^2.7.0" "w3css": "^2.7.0"
}, },

View File

@ -2,6 +2,7 @@ import copy
import hashlib import hashlib
import json import json
import re import re
import sys
import time import time
import uuid import uuid
@ -13,15 +14,23 @@ from platypush.utils import get_event_class_by_type
class Event(Message): class Event(Message):
""" Event message class """ """Event message class"""
# If this class property is set to false then the logging of these events # If this class property is set to false then the logging of these events
# will be disabled. Logging is usually disabled for events with a very # will be disabled. Logging is usually disabled for events with a very
# high frequency that would otherwise pollute the logs e.g. camera capture # high frequency that would otherwise pollute the logs e.g. camera capture
# events # events
# pylint: disable=redefined-builtin # pylint: disable=redefined-builtin
def __init__(self, target=None, origin=None, id=None, timestamp=None, def __init__(
disable_logging=False, disable_web_clients_notification=False, **kwargs): self,
target=None,
origin=None,
id=None,
timestamp=None,
disable_logging=False,
disable_web_clients_notification=False,
**kwargs
):
""" """
Params: Params:
target -- Target node [String] target -- Target node [String]
@ -34,22 +43,27 @@ class Event(Message):
self.id = id if id else self._generate_id() self.id = id if id else self._generate_id()
self.target = target if target else Config.get('device_id') self.target = target if target else Config.get('device_id')
self.origin = origin if origin else Config.get('device_id') self.origin = origin if origin else Config.get('device_id')
self.type = '{}.{}'.format(self.__class__.__module__, self.type = '{}.{}'.format(self.__class__.__module__, self.__class__.__name__)
self.__class__.__name__)
self.args = kwargs self.args = kwargs
self.disable_logging = disable_logging self.disable_logging = disable_logging
self.disable_web_clients_notification = disable_web_clients_notification self.disable_web_clients_notification = disable_web_clients_notification
for arg, value in self.args.items(): for arg, value in self.args.items():
if arg not in [ if arg not in [
'id', 'args', 'origin', 'target', 'type', 'timestamp', 'disable_logging' 'id',
'args',
'origin',
'target',
'type',
'timestamp',
'disable_logging',
] and not arg.startswith('_'): ] and not arg.startswith('_'):
self.__setattr__(arg, value) self.__setattr__(arg, value)
@classmethod @classmethod
def build(cls, msg): def build(cls, msg):
""" Builds an event message from a JSON UTF-8 string/bytearray, a """Builds an event message from a JSON UTF-8 string/bytearray, a
dictionary, or another Event """ dictionary, or another Event"""
msg = super().parse(msg) msg = super().parse(msg)
event_type = msg['args'].pop('type') event_type = msg['args'].pop('type')
@ -64,8 +78,10 @@ class Event(Message):
@staticmethod @staticmethod
def _generate_id(): def _generate_id():
""" Generate a unique event ID """ """Generate a unique event ID"""
return hashlib.md5(str(uuid.uuid1()).encode()).hexdigest() # lgtm [py/weak-sensitive-data-hashing] return hashlib.md5(
str(uuid.uuid1()).encode()
).hexdigest() # lgtm [py/weak-sensitive-data-hashing]
def matches_condition(self, condition): def matches_condition(self, condition):
""" """
@ -120,7 +136,13 @@ class Event(Message):
""" """
result = EventMatchResult(is_match=False) result = EventMatchResult(is_match=False)
event_tokens = re.split(r'\s+', self.args[argname].strip().lower()) if self.args.get(argname) == condition_value:
# In case of an exact match, return immediately
result.is_match = True
result.score = sys.maxsize
return result
event_tokens = re.split(r'\s+', self.args.get(argname, '').strip().lower())
condition_tokens = re.split(r'\s+', condition_value.strip().lower()) condition_tokens = re.split(r'\s+', condition_value.strip().lower())
while event_tokens and condition_tokens: while event_tokens and condition_tokens:
@ -148,9 +170,11 @@ class Event(Message):
else: else:
result.parsed_args[argname] += ' ' + event_token result.parsed_args[argname] += ' ' + event_token
if (len(condition_tokens) == 1 and len(event_tokens) == 1) \ if (len(condition_tokens) == 1 and len(event_tokens) == 1) or (
or (len(event_tokens) > 1 and len(condition_tokens) > 1 len(event_tokens) > 1
and event_tokens[1] == condition_tokens[1]): and len(condition_tokens) > 1
and event_tokens[1] == condition_tokens[1]
):
# Stop appending tokens to this argument, as the next # Stop appending tokens to this argument, as the next
# condition will be satisfied as well # condition will be satisfied as well
condition_tokens.pop(0) condition_tokens.pop(0)
@ -173,30 +197,30 @@ class Event(Message):
args = copy.deepcopy(self.args) args = copy.deepcopy(self.args)
flatten(args) flatten(args)
return json.dumps({ return json.dumps(
'type': 'event', {
'target': self.target, 'type': 'event',
'origin': self.origin if hasattr(self, 'origin') else None, 'target': self.target,
'id': self.id if hasattr(self, 'id') else None, 'origin': self.origin if hasattr(self, 'origin') else None,
'_timestamp': self.timestamp, 'id': self.id if hasattr(self, 'id') else None,
'args': { '_timestamp': self.timestamp,
'type': self.type, 'args': {'type': self.type, **args},
**args
}, },
}, cls=self.Encoder) cls=self.Encoder,
)
class EventMatchResult(object): class EventMatchResult:
""" When comparing an event against an event condition, you want to """When comparing an event against an event condition, you want to
return this object. It contains the match status (True or False), return this object. It contains the match status (True or False),
any parsed arguments, and a match_score that identifies how "strong" any parsed arguments, and a match_score that identifies how "strong"
the match is - in case of multiple event matches, the ones with the the match is - in case of multiple event matches, the ones with the
highest score will win """ highest score will win"""
def __init__(self, is_match, score=0, parsed_args=None): def __init__(self, is_match, score=0, parsed_args=None):
self.is_match = is_match self.is_match = is_match
self.score = score self.score = score
self.parsed_args = {} if not parsed_args else parsed_args self.parsed_args = parsed_args or {}
def flatten(args): def flatten(args):
@ -213,4 +237,5 @@ def flatten(args):
elif isinstance(arg, (dict, list)): elif isinstance(arg, (dict, list)):
flatten(args[i]) flatten(args[i])
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et: