Skip to content

Commit 93ca6fa

Browse files
committed
straighten out most parts after ruff
1 parent 84295cd commit 93ca6fa

9 files changed

Lines changed: 53 additions & 196 deletions

File tree

docs/beginners-guide/articles/actions.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Only methods decorated with `action()` are exposed to clients.
77
```py title="Actions" linenums="1" hl_lines="5 10 15 16 21 25"
88
--8<-- "docs/beginners-guide/code/thing_example_2.py:195:198"
99
--8<-- "docs/beginners-guide/code/thing_example_2.py:448:462"
10-
--8<-- "docs/beginners-guide/code/thing_example_2.py:683:685"
10+
--8<-- "docs/beginners-guide/code/thing_example_2.py:682:685"
1111
--8<-- "docs/beginners-guide/code/thing_example_2.py:563:567"
1212
```
1313

@@ -403,7 +403,8 @@ client side, there is no difference between invoking a normal action and an acti
403403

404404
## Threaded & Async Actions
405405

406-
Actions can be made asynchronous or threaded by setting the `synchronous` flag to `False`. For methods that are **not** `async`:
406+
Actions can be made asynchronous or threaded by setting the `synchronous` flag to `False`. For methods that are **not** `async`,
407+
they will run in a separate thread:
407408

408409
```py title="Threaded Actions" linenums="3"
409410
class ServoMotor(Thing):
@@ -426,6 +427,7 @@ The return value is fetched and returned to the client. One could also start lon
426427
class DCPowerSupply(Thing):
427428
"""A DC Power Supply from 0-30V"""
428429

430+
# The suitability of this example in a realistic use case is untested
429431
@action(threaded=True)
430432
def monitor_over_voltage(self, period: float = 5):
431433
"""background voltage monitor loop"""
@@ -440,16 +442,15 @@ class DCPowerSupply(Thing):
440442
)
441443
)
442444
time.sleep(period)
443-
# The suitability of this example in a realistic use case is untested
444445
```
445446

446-
For `async` actions:
447+
For `async` actions, they are scheduled in the running event loop as a task:
447448

448449
```py title="Async Actions" linenums="3"
449450
class DCPowerSupply(Thing):
450451

451-
@action(create_task=True)
452-
# @action(synchronous=False) # exactly the same effect for async methods
452+
@action(synchronous=False)
453+
# @action(create_task=True) # exactly the same effect for async methods
453454
async def monitor_over_voltage(self, period: float = 5):
454455
"""background monitor loop"""
455456
while True:

docs/beginners-guide/articles/clients.md

Lines changed: 0 additions & 154 deletions
This file was deleted.

docs/beginners-guide/articles/events.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Events are pushed to the client through a publish-subscribe mechanism through al
1010

1111
## Subscription
1212

13+
[API Reference](../../api-reference/clients/object-proxy.md#hololinked.client.proxy.ObjectProxy.subscribe_event)
14+
1315
One can subscribe to the event using the attribute name:
1416

1517
=== "threaded"
@@ -48,7 +50,9 @@ One can subscribe to the event using the attribute name:
4850
)
4951
```
5052

51-
The callback function(s) must accept a single argument which is the event data payload, an instance of `SSE` object. The payload can be accessed as using the `data` attribute:
53+
---
54+
55+
The callback function(s) must accept a single argument - an instance of `SSE` object. The payload can be accessed as using the `data` attribute:
5256

5357
```py title="Event Data" linenums="1" hl_lines="9"
5458
def event_cb(event):
@@ -57,7 +61,9 @@ def event_cb(event):
5761

5862
> The `SSE` object also contains metadata like `id`, `event` name and `retry` interval, but these are currently not well supported. Improvements in the future are expected.
5963
60-
Each subscription creates a new event stream. One can also supply multiple callbacks which may called in series or concurrently:
64+
---
65+
66+
Each subscription creates a new event stream. One can also supply multiple callbacks which may be called in series or concurrently:
6167

6268
=== "sequential"
6369

@@ -130,7 +136,7 @@ All subscriptions to the same event are removed.
130136

131137
## Payload Schema
132138

133-
Schema may be supplied for the validation of the event data on the client using pydantic or JSON schema:
139+
Schema for the payload may be supplied using pydantic or JSON schema:
134140

135141
```py title="Payload Schema" linenums="1" hl_lines="13"
136142
class GentecMaestroEnergyMeter(Thing):
@@ -151,8 +157,6 @@ class GentecMaestroEnergyMeter(Thing):
151157
)
152158
```
153159

154-
There is no separate validation on the server side.
155-
156160
> There is no validation on the client side currently implemented in `hololinked.client`. This will be added in future releases.
157161
158162
???+ "Schema as seen in Thing Description"

docs/beginners-guide/articles/security.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Authentication Schemes
22

3-
Security schemes restrict access to the Thing instance, and are currently available only for HTTP.
3+
Security schemes are currently available only for HTTP.
44

55
### Basic Security Scheme
66

@@ -27,11 +27,14 @@ HTTP Basic authentication with username and password is supported with bcrypt an
2727

2828
```py title="Usage" linenums="1"
2929
import requests
30+
from base64 import b64encode
3031
from requests.auth import HTTPBasicAuth
3132

3233
response = requests.get(
33-
"http://localhost:9000/properties/some_property",
34-
auth=HTTPBasicAuth("admin", "adminpass")
34+
"http://localhost:9000/secure-thing/some-property",
35+
headers=dict(
36+
Authorization=f"Basic {b64encode(b'someuser:somepassword').decode('utf-8')}"
37+
),
3538
)
3639
print(response.json())
3740
```
@@ -43,7 +46,7 @@ HTTP Basic authentication with username and password is supported with bcrypt an
4346
from hololinked.client.security import HTTPBasicSecurityScheme
4447

4548
client = ClientFactory.http(
46-
"http://localhost:9000/my-thing/resources/wot-td",
49+
url="http://localhost:9000/my-thing/resources/wot-td",
4750
security_scheme=HTTPBasicSecurityScheme(
4851
username="admin",
4952
password="adminpass",

docs/beginners-guide/articles/serialization.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and large nested objects.
99
Based on application requirements, it is possible to change the serialization format on an individual basis by using the `Serializers` singleton.
1010
Set the desired serialization on the specific property, action or event on the `Thing` subclass:
1111

12-
```python
12+
```py linenums="1"
1313
from hololinked.serializers import Serializers
1414

1515
# Using a pickle serializer for a list property
@@ -31,9 +31,9 @@ OceanOpticsSpectrometer(id="spectro1").run_with_http_server()
3131

3232
Other properties, actions or events will still use the default JSON serialization.
3333

34-
To overload the content type per thing instance:
34+
To overload the content type for an object per thing instance:
3535

36-
```python
36+
```py linenums="1"
3737
from hololinked.serializers import Serializers
3838

3939
spectrometer = OceanOpticsSpectrometer(id='spectro1')
@@ -56,7 +56,7 @@ spectrometer.run(...)
5656

5757
To overload the default serializer for a `Thing` **instance**:
5858

59-
```python
59+
```py linenums="1"
6060
from hololinked.serializers import Serializers
6161

6262
spectrometer = OceanOpticsSpectrometer(id='spectro1')
@@ -77,7 +77,8 @@ Serializers.register_for_object_per_thing_instance(
7777
spectrometer.run(...)
7878
```
7979

80-
per-instance overloads have higher priority than the per-thing-object registrations.
80+
per-instance overloads have higher priority than the per-thing-object registrations. The singleton behaviour of `Serializers`
81+
ensures that all registrations are available across all protocol servers within the same process.
8182

8283
### Built-in Serializers
8384

@@ -90,7 +91,7 @@ The following serializers are supported out of the box:
9091

9192
### Custom Serializers
9293

93-
One can create custom serializers by subclassing the `BaseSerializer` class and implementing `dumps`, `loads`, and `content_type` methods.
94+
One can create custom serializers by subclassing the `BaseSerializer` and implementing `dumps`, `loads`, and `content_type` methods.
9495
Then, register the custom serializer for a specific property, action or event using the `Serializers` singleton as shown above.
9596

9697
```python

docs/beginners-guide/articles/state-machine.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[API Reference](../../api-reference/state-machine/state-machine.md)
22

33
Often, certain operations are not allowed during certain conditions, for example,
4-
one cannot turn ON a motor twice in a row, or a measurement device cannot modify a setting change if a measurement is ongoing.
4+
one cannot turn ON a motor twice in a row, or a measurement device cannot modify a setting if a measurement is ongoing.
55

66
To implement these contraints, a state machine may be used to prevent property writes or
7-
action invokations in certain states (events are not supported). A `StateMachine` is a class-level
8-
attribute which accepts a finite list of states and the allowed properties and actions
7+
action invokations when a `Thing` is said to be in a certain state (events are not supported).
8+
A `StateMachine` is a class-level attribute which accepts a finite list of states and the allowed properties and actions
99
in these states:
1010

1111
```py title="Definition" linenums="1"
@@ -60,8 +60,6 @@ def state_change_cb(event):
6060
client.observe_property(name="state", callbacks=state_change_cb)
6161
```
6262

63-
> One can supply multiple callbacks which may called in series or concurrently - see [Events](events.md#subscription).
64-
6563
## State Change Callbacks
6664

6765
One can also supply callbacks which are executed when entering and exiting certain states,

docs/beginners-guide/articles/thing/index.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ thing = Thing(id="test-thing", logger=logger)
2020
thing.run_with_http_server(port=9000)
2121
```
2222

23-
<!-- #### Remote Access to Logger
23+
#### Remote Access to Logger
24+
25+
To be updated after integration with opentelemetry & EFK stack. See [issues](https://github.com/hololinked-dev/hololinked/issues?q=is%3Aissue%20state%3Aopen%20milestone%3A%22logging%2C%20metrics%20and%20traces%22).
26+
27+
<!--
2428
2529
To stream the logs remotely, specify `remote_access_handler=True` while instantiating the `Thing`.
2630
@@ -58,8 +62,10 @@ class MyThing(Thing):
5862
self.logger.info("Thing initialized with properties from DB")
5963
```
6064

61-
### Schema Validator
62-
6365
### Meta
6466

67+
To be updated with use cases of modifying Thing metaclass.
68+
6569
### Composition
70+
71+
To be updated with using sub-things within a Thing.

docs/introduction/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ For good first issues, visit repository wise:
2828
- [website](https://github.com/hololinked-dev/website/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22)
2929
- [kubernetes](https://github.com/hololinked-dev/vps-kubernetes-cluster/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22)
3030

31-
Our [contribution guidelines](https://github.com/hololinked-dev/hololinked/blob/main/CONTRIBUTING.md) may also help. There are also [weekly office hours](https://github.com/hololinked-dev#monthly-meetings) & [discord group](https://discord.com/invite/kEz87zqQXh) (currently no participants).
31+
Our [contribution guidelines](https://github.com/hololinked-dev/hololinked/blob/main/CONTRIBUTING.md) may also help, especially for new contributors & setting up development environments. There are also [weekly office hours](https://github.com/hololinked-dev#monthly-meetings) & [discord group](https://discord.com/invite/kEz87zqQXh) (currently no participants).

0 commit comments

Comments
 (0)