Skip to content

Commit 7c93054

Browse files
authored
feat: expose globals edit (#73)
Co-authored-by: Tom Allpress <[email protected]>
1 parent 9674667 commit 7c93054

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ __* This SDK is currently in beta__
1111
- [Detail Instructions](#detail-instructions)
1212
- [Examples](#examples)
1313
- [Eva](#eva)
14-
- [evasdk.eva_http and evasdk.eva_ws](#evasdkevahttp-and-evasdkevaws)
14+
- [evasdk.eva_http and evasdk.eva_ws](#evasdkeva_http-and-evasdkeva_ws)
1515
- [Versioning](#versioning)
1616
- [Logging](#logging)
1717
- [Bugs and feature requests](#bugs-and-feature-requests)
@@ -166,11 +166,11 @@ $ pipenv run test
166166
$ pipenv shell
167167
$ pipenv run testd tests/<test-name>_test.py
168168

169-
# some test require supplying ip and token via the `--ip` and `--token` arguements:
170-
$ pipenv run test --ip 172.16.16.2 --token abc-123-def-456
169+
# some test require testing against a real robot. Therefore you will be required to supply a ip and token via the `--ip` and `--token` arguments as well as pass the --runrobot flag to notify pytest that you wish to run the robot tests:
170+
$ pipenv run test --runrobot --ip 172.16.16.2 --token abc-123-def-456
171171

172172
# Tests requiring the robot or long amounts of time will not run by default,
173-
# these require flags to be enabled, a full list of flags is availble with the help flag:
173+
# these require flags to be enabled, a full list of flags is available with the help flag:
174174
$ pipenv run test -h
175175
```
176176

evasdk/Eva.py

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def gpio_get(self, pin, pin_type):
114114
self.__logger.debug('Eva.gpio_get called')
115115
return self.__http_client.gpio_get(pin, pin_type)
116116

117+
def globals_edit(self, keys, values):
118+
self.__logger.debug('Eva.globals_edit called')
119+
return self.__http_client.globals_edit(keys, values)
117120

118121
# Toolpaths
119122
def toolpaths_list(self):

evasdk/eva_http_client.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def config_update(self, update):
176176

177177
# GPIO
178178
def gpio_set(self, pin, status):
179-
r = self.__globals_editing(keys='outputs.' + pin, values=status)
179+
r = self._globals_edit(keys='outputs.' + pin, values=status)
180180
if r.status_code != 200:
181181
eva_error('gpio_set error', r)
182182

@@ -189,16 +189,21 @@ def gpio_get(self, pin, pin_type):
189189
return self.data_snapshot_property('global.{}s'.format(pin_type))[pin]
190190

191191

192-
# GPIO helper function
193-
def __globals_editing(self, keys, values):
192+
def _globals_edit(self, keys, values):
194193
data = {'changes': []}
195194
if (isinstance(keys, list) and isinstance(values, list)):
196195
data['changes'] = [{'key': k, 'value': v} for k, v in zip(keys, values)]
197196
else:
198197
data['changes'].append({'key': keys, 'value': values})
199198
data = json.dumps(data)
200-
r = self.api_call_with_auth('POST', 'data/globals', data)
201-
return r
199+
return self.api_call_with_auth('POST', 'data/globals', data)
200+
201+
202+
def globals_edit(self, keys, values):
203+
r = self._globals_edit(keys, values)
204+
if r.status_code != 200:
205+
eva_error('globals_edit error', r)
206+
return r.json()
202207

203208

204209
# TOOLPATHS

tests/Eva_api_test.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from evasdk import Eva
2+
import requests_mock
23

34

45
class TestEva_API:
5-
def test_user_agent(self, requests_mock):
6+
@requests_mock.Mocker(kw='mock')
7+
def test_user_agent(self, **kwargs):
68
eva = Eva("example.com", "NONE")
7-
8-
requests_mock.register_uri(
9+
kwargs['mock'].register_uri(
910
'GET', 'http://example.com/api/versions',
1011
request_headers={
1112
'User-Agent': 'Automata EvaSDK/0.0.dev0 (Python)',

tests/Eva_gpio_test.py

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
@pytest.mark.robot_required
1111
class TestEva_GPIO:
12+
# TODO: currently fail on d1 inputs, requires fix
1213
def test_get(self, eva):
1314
# For all io variations, if the key is not present an exception
1415
# will be thrown so no assertions are required
@@ -27,6 +28,15 @@ def test_set(self, locked_eva):
2728
locked_eva.gpio_set(pin_name, False)
2829

2930

31+
def test_globals_edit(self, locked_eva):
32+
# For all io variations, if an error is encountered, an exception
33+
# will be thrown so no assertions are required
34+
locked_eva.globals_edit('outputs.ee_d0', True)
35+
locked_eva.globals_edit('outputs.d3', True)
36+
locked_eva.globals_edit(['outputs.ee_d0', 'outputs.d3'], [True, False])
37+
locked_eva.globals_edit(['outputs.ee_d0', 'outputs.d3'], [False, True])
38+
39+
3040
@pytest.mark.io_loopback_required
3141
def test_set_get(self, locked_eva):
3242
digital_states = [True, False]

0 commit comments

Comments
 (0)