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

Release Lazy.2 #258

Merged
merged 41 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0006c0f
remove strict recorder dependency
krahabb Feb 8, 2023
2faca51
fix with timeout() deprecation
krahabb Feb 9, 2023
f7d79f4
remove unused platform callbacks
krahabb Feb 9, 2023
7dd5079
streamline mqtt calls to be more pytest friendly
krahabb Feb 9, 2023
cd94b39
improve environment settings to support testing
krahabb Feb 9, 2023
188bc1f
support enable-disable debug log from HA UI
krahabb Feb 9, 2023
742a07d
refactor to support testing
krahabb Feb 9, 2023
1aff549
implement a working basic suite of tests
krahabb Feb 9, 2023
b7a43e7
upate git workflows to python 3.10
krahabb Feb 9, 2023
e086dbe
upload traces to repository to allow testing
krahabb Feb 9, 2023
0a05430
add missing dependency for recorder as optional
krahabb Feb 9, 2023
410d259
update github actions
krahabb Feb 10, 2023
21068ef
add missing import annotations
krahabb Feb 10, 2023
4ffc17a
remove aiohttp.web dependency from Emulator class
krahabb Feb 10, 2023
4410c1b
update emulator calls interface
krahabb Feb 10, 2023
b797bff
minor typing
krahabb Feb 12, 2023
01d0504
fix mqtt discovery flow unique_id
krahabb Feb 12, 2023
9adfa88
refactor to ease code coverage in tests
krahabb Feb 12, 2023
8107163
tz safety check (for testing with freezetime)
krahabb Feb 12, 2023
9f6a570
more testing traces
krahabb Feb 12, 2023
8ee436d
add comment to clarify coding choice
krahabb Feb 12, 2023
bc4594b
fix relative imports
krahabb Feb 12, 2023
392fc28
prevent linter complaints
krahabb Feb 12, 2023
c52f27d
parametrize tracing abilities delay
krahabb Feb 12, 2023
b0d9cbe
more tests on config_flow, diagnostics, other
krahabb Feb 12, 2023
c185a17
set justMyCode to false in test debugging
krahabb Feb 12, 2023
b4dbee6
add missing dependencies for CI host
krahabb Feb 12, 2023
6c224d6
add missing dependencies for CI host
krahabb Feb 12, 2023
8e76a55
add service response as a persistent_notification
krahabb Feb 12, 2023
f9b458a
add more context to http error logging
krahabb Feb 12, 2023
9f2b228
fix missing refresh after reconnection (#257)
krahabb Feb 12, 2023
705ee3f
try prevent md5 failure (#256)
krahabb Feb 12, 2023
b5cbe50
move mqtt requests to async
krahabb Feb 12, 2023
8e3d36e
add service response test
krahabb Feb 12, 2023
a66ed35
refine async migration for tests
krahabb Feb 12, 2023
df3b7d8
add missing error key for OptionFlow
krahabb Feb 16, 2023
aa73ece
relax callback typing
krahabb Feb 16, 2023
d3afa9b
manage garage open/close timeouts (#82)
krahabb Feb 16, 2023
68822ac
improve msg100 emulation
krahabb Feb 16, 2023
8b66cf3
add msg100 trace
krahabb Feb 16, 2023
67b2294
update readme for 3.0.2
krahabb Feb 16, 2023
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
Prev Previous commit
Next Next commit
refactor to support testing
  • Loading branch information
krahabb committed Feb 9, 2023
commit 742a07d017fe7d4b63a17e8f26d470fc4a5dd3da
66 changes: 42 additions & 24 deletions custom_components/meross_lan/emulator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@


def build_emulator(tracefile, uuid, key) -> MerossEmulator:

"""
Given a supported 'tracefile' (either a legacy trace .csv or a diagnostic .json)
parse it and build the appropriate emulator instance with the give 'uuid' and 'key'
"""
descriptor = MerossEmulatorDescriptor(tracefile, uuid)

mixin_classes = []
Expand All @@ -28,6 +31,41 @@ def build_emulator(tracefile, uuid, key) -> MerossEmulator:
return class_type(descriptor, key)


def generate_emulators(tracespath: str, defaultuuid: str, defaultkey: str):
"""
This function is a generator.
Scans the directory for supported files and build all the emulators
the filename, if correctly formatted, should contain the device uuid
and key to use for the emulator. If not, we'll use the 'defaultuuid' and/or
'defaultkey' when instantiating the emulator. This allows for supporting
basic plain filenames which don't contain any info but also, will make
it difficult to understand which device is which
"""
uuidsub = 0
for f in os.listdir(tracespath):
fullpath = os.path.join(tracespath, f)
#expect only valid csv or json files
f = f.split('.')
if f[-1] not in ('csv','txt','json'):
continue

# filename could be formatted to carry device definitions parameters:
# format the filename like 'xxxwhatever-Kdevice_key-Udevice_id'
# this way, parameters will be 'binded' to that trace in an easy way
key = defaultkey
uuid = None
for _f in f[0].split('-'):
if _f.startswith('K'):
key = _f[1:].strip()
elif _f.startswith('U'):
uuid = _f[1:].strip()
if uuid is None:
uuidsub = uuidsub + 1
_uuidsub = str(uuidsub)
uuid = defaultuuid[:-len(_uuidsub)] + _uuidsub
yield build_emulator(fullpath, uuid, key)


def run(argv):
"""
self running python app entry point
Expand All @@ -36,6 +74,7 @@ def run(argv):
"""
key = ''
uuid = '01234567890123456789001122334455'
tracefilepath = '.'
for arg in argv:
arg: str
if arg.startswith('-K'):
Expand All @@ -48,30 +87,9 @@ def run(argv):
app = web.Application()

if os.path.isdir(tracefilepath):
uuidsub = 0
for f in os.listdir(tracefilepath):
fullpath = os.path.join(tracefilepath, f)
#expect only valid csv files
f = f.split('.')
if f[-1] not in ('csv','txt','json'):
continue

# filename could be formatted to carry device definitions parameters:
# format the filename like 'xxxwhatever-Kdevice_key-Udevice_id'
# this way, parameters will be 'binded' to that trace in an easy way
_key = key
uuidsub = uuidsub + 1
_uuidsub = str(uuidsub)
_uuid = uuid[:-len(_uuidsub)] + _uuidsub
for _f in f[0].split('-'):
if _f.startswith('K'):
_key = _f[1:].strip()
elif _f.startswith('U'):
_uuid = _f[1:].strip()
emulator = build_emulator(fullpath, _uuid, _key)
app.router.add_post(f"/{_uuid}/config", emulator.post_config)
for emulator in generate_emulators(tracefilepath, uuid, key):
app.router.add_post(f"/{emulator.descriptor.uuid}/config", emulator.post_config)
else:
#device = MerossDevice("custom_components/meross_lan/traces/msh300-1638110082.csv")
emulator = build_emulator(tracefilepath, uuid, key)
app.router.add_post("/config", emulator.post_config)

Expand Down
11 changes: 10 additions & 1 deletion custom_components/meross_lan/merossclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,17 @@ class MerossDeviceDescriptor:
all = {}
ability: dict
digest: dict
time: dict | None
system: dict
hardware: dict
firmware: dict
type: str
uuid: str
macAddress: str
innerIp: str | None
time: dict
timezone: str | None
productname: str
productmodel: str

_dynamicattrs = {
mc.KEY_SYSTEM: lambda _self: _self.all.get(mc.KEY_SYSTEM, {}),
Expand Down