Skip to content

Commit 52e250e

Browse files
author
AndyEveritt
committed
allow keys to be used for DSF get_model
1 parent d987eb0 commit 52e250e

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

duetwebapi/api/dsf_api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import logging
22
import os
33
from typing import Dict, List, Union
4-
from io import StringIO, TextIOWrapper
4+
from io import StringIO, TextIOWrapper, BytesIO
5+
from functools import reduce
56

7+
import operator
68
import requests
79

810
from .base import DuetAPI
@@ -17,10 +19,13 @@ class DSFAPI(DuetAPI):
1719
"""
1820
api_name = 'DSF_REST'
1921

20-
def get_model(self, **_ignored) -> Dict:
22+
def get_model(self, key: str = None) -> Dict:
2123
url = f'{self.base_url}/machine/status'
2224
r = requests.get(url)
2325
j = r.json()
26+
if key is not None:
27+
keys = key.split('.')
28+
return reduce(operator.getitem, keys, j)
2429
return j
2530

2631
def send_code(self, code: str) -> Dict:

duetwebapi/api/dwc_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import os
33
from typing import Dict, List, Union
4-
from io import StringIO, TextIOWrapper
4+
from io import StringIO, TextIOWrapper, BytesIO
55

66
import requests
77

0 commit comments

Comments
 (0)