FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
webthing-python/webthing/value.py at master · WebThingsIO/webthing-python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
WebThingsIO
/
webthing-python
Public
Notifications
You must be signed in to change notification settings
Fork
36
Star
175
Code
Issues
2
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
webthing-python
/
webthing
/
value.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (40 loc) · 1.45 KB
Breadcrumbs
webthing-python
/
webthing
/
value.py
Copy path
File metadata and controls
53 lines (40 loc) · 1.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""An observable, settable value interface."""
from
pyee
import
EventEmitter
class
Value
(
EventEmitter
):
"""
A property value.
This is used for communicating between the Thing representation and the
actual physical thing implementation.
Notifies all observers when the underlying value changes through an
external update (command to turn the light off) or if the underlying sensor
reports a new value.
"""
def
__init__
(
self
,
initial_value
,
value_forwarder
=
None
):
"""
Initialize the object.
initial_value -- the initial value
value_forwarder -- the method that updates the actual value on the
thing
"""
EventEmitter
.
__init__
(
self
)
self
.
last_value
=
initial_value
self
.
value_forwarder
=
value_forwarder
def
set
(
self
,
value
):
"""
Set a new value for this thing.
value -- value to set
"""
if
self
.
value_forwarder
is
not
None
:
self
.
value_forwarder
(
value
)
self
.
notify_of_external_update
(
value
)
def
get
(
self
):
"""Return the last known value from the underlying thing."""
return
self
.
last_value
def
notify_of_external_update
(
self
,
value
):
"""
Notify observers of a new value.
value -- new value
"""
if
value
is
not
None
and
value
!=
self
.
last_value
:
self
.
last_value
=
value
self
.
emit
(
'update'
,
value
)
Back
|
FazBrowse Home
|
New Git URL