Skip to content

Commit ea7e462

Browse files
committed
Modular Architektur
1 parent e4ed8f3 commit ea7e462

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1587
-27
lines changed

.vscode/.ropeproject/objectdb

101 Bytes
Binary file not shown.
626 Bytes
Binary file not shown.
339 Bytes
Binary file not shown.
248 Bytes
Binary file not shown.
Binary file not shown.
2.89 KB
Binary file not shown.

hue_getBridgeHttpAddress.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
3+
#pip install validators
4+
5+
import discoverhue
6+
import validators
7+
8+
http_address='http://192.168.0.164/' #HUE Bridge IP-Adress incl. http
9+
10+
def GetBridgeHttpAddress():
11+
global http_address
12+
try:
13+
if validators.url(http_address):
14+
return http_address
15+
else:
16+
found = discoverhue.find_bridges()
17+
for bridge in found:
18+
print('Bridge ID {br} at {ip}'.format(br=bridge, ip=found[bridge]))
19+
http_address=found[bridge]
20+
return http_address #Return the first found Bridge
21+
except:
22+
print("Keine Bridge gefunden!")
23+
return -1
24+
25+
26+
if __name__ == '__main__':
27+
GetBridgeHttpAddress()

hue_light.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,16 @@
55

66
import requests
77
import json
8-
import discoverhue
8+
import hue_getBridgeHttpAddress
9+
import hue_userKey
910

10-
http_adress='http://192.168.0.164/' #HUE Bridge IP-Adress incl. http
11-
hue_user='abc' #Hue Benutzerschlüssel
12-
light_id=1
1311

14-
auto_detect_bridge=False
12+
light_id=1
13+
hue_user= hue_userKey.GetHueUserKey() #Hue Benutzerschlüssel
1514

16-
try:
17-
if bool(auto_detect_bridge):
18-
found = discoverhue.find_bridges()
19-
for bridge in found:
20-
print('Bridge ID {br} at {ip}'.format(br=bridge, ip=found[bridge]))
21-
http_adress=found[bridge]
22-
except:
23-
print("Keine Bridge gefunden!")
15+
http_address=hue_getBridgeHttpAddress.GetBridgeHttpAddress()
2416

25-
light = http_adress+'api/'+hue_user+'/lights/'+str(light_id)
17+
light = http_address+'api/'+hue_user+'/lights/'+str(light_id)
2618

2719
try:
2820
r = requests.get(light)

hue_motion.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,17 @@
55

66
import requests
77
import json
8-
import discoverhue
8+
import hue_getBridgeHttpAddress
9+
import hue_userKey
10+
911

10-
http_adress='http://192.168.0.164/' #HUE Bridge IP-Adress incl. http
11-
hue_user='abc' #Hue Benutzerschlüssel
1212
motion_sensor_id=15
1313

14-
auto_detect_bridge=False
14+
hue_user=hue_userKey.GetHueUserKey() #Hue Benutzerschlüssel
1515

16-
try:
17-
if bool(auto_detect_bridge):
18-
found = discoverhue.find_bridges()
19-
for bridge in found:
20-
print('Bridge ID {br} at {ip}'.format(br=bridge, ip=found[bridge]))
21-
http_adress=found[bridge]
22-
except:
23-
print("Keine Bridge gefunden!")
16+
http_address=hue_getBridgeHttpAddress.GetBridgeHttpAddress()
2417

25-
sensor = http_adress+'api/'+hue_user+'/sensors/'+str(motion_sensor_id)
18+
sensor = http_address+'api/'+hue_user+'/sensors/'+str(motion_sensor_id)
2619

2720
try:
2821
r = requests.get(sensor)

hue_userKey.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
3+
UserKey='xyzxyzxyzxyz' #Hue Benutzerschlüssel
4+
5+
def GetHueUserKey():
6+
return UserKey
7+
8+
9+
if __name__ == '__main__':
10+
GetHueUserKey()

validators/__init__.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from .between import between
2+
from .btc_address import btc_address
3+
from .card import (
4+
amex,
5+
card_number,
6+
diners,
7+
discover,
8+
jcb,
9+
mastercard,
10+
unionpay,
11+
visa
12+
)
13+
from .domain import domain
14+
from .email import email
15+
from .extremes import Max, Min
16+
from .hashes import md5, sha1, sha224, sha256, sha512
17+
from .i18n import fi_business_id, fi_ssn
18+
from .iban import iban
19+
from .ip_address import ipv4, ipv4_cidr, ipv6, ipv6_cidr
20+
from .length import length
21+
from .mac_address import mac_address
22+
from .slug import slug
23+
from .truthy import truthy
24+
from .url import url
25+
from .utils import ValidationFailure, validator
26+
from .uuid import uuid
27+
28+
__all__ = ('between', 'domain', 'email', 'Max', 'Min', 'md5', 'sha1', 'sha224',
29+
'sha256', 'sha512', 'fi_business_id', 'fi_ssn', 'iban', 'ipv4',
30+
'ipv4_cidr', 'ipv6', 'ipv6_cidr', 'length', 'mac_address', 'slug',
31+
'truthy', 'url', 'ValidationFailure', 'validator', 'uuid',
32+
'card_number', 'visa', 'mastercard', 'amex', 'unionpay', 'diners',
33+
'jcb', 'discover', 'btc_address')
34+
35+
__version__ = '0.18.1'
1.19 KB
Binary file not shown.
1.62 KB
Binary file not shown.
758 Bytes
Binary file not shown.
4.81 KB
Binary file not shown.
1.45 KB
Binary file not shown.
1.68 KB
Binary file not shown.
1.41 KB
Binary file not shown.
2.73 KB
Binary file not shown.
1.51 KB
Binary file not shown.
Binary file not shown.
1.1 KB
Binary file not shown.
Binary file not shown.
745 Bytes
Binary file not shown.
1.06 KB
Binary file not shown.
3.34 KB
Binary file not shown.
2.81 KB
Binary file not shown.
1.15 KB
Binary file not shown.

validators/between.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from .extremes import Max, Min
2+
from .utils import validator
3+
4+
5+
@validator
6+
def between(value, min=None, max=None):
7+
"""
8+
Validate that a number is between minimum and/or maximum value.
9+
10+
This will work with any comparable type, such as floats, decimals and dates
11+
not just integers.
12+
13+
This validator is originally based on `WTForms NumberRange validator`_.
14+
15+
.. _WTForms NumberRange validator:
16+
https://github.com/wtforms/wtforms/blob/master/wtforms/validators.py
17+
18+
Examples::
19+
20+
>>> from datetime import datetime
21+
22+
>>> between(5, min=2)
23+
True
24+
25+
>>> between(13.2, min=13, max=14)
26+
True
27+
28+
>>> between(500, max=400)
29+
ValidationFailure(func=between, args=...)
30+
31+
>>> between(
32+
... datetime(2000, 11, 11),
33+
... min=datetime(1999, 11, 11)
34+
... )
35+
True
36+
37+
:param min:
38+
The minimum required value of the number. If not provided, minimum
39+
value will not be checked.
40+
:param max:
41+
The maximum value of the number. If not provided, maximum value
42+
will not be checked.
43+
44+
.. versionadded:: 0.2
45+
"""
46+
if min is None and max is None:
47+
raise AssertionError(
48+
'At least one of `min` or `max` must be specified.'
49+
)
50+
if min is None:
51+
min = Min
52+
if max is None:
53+
max = Max
54+
try:
55+
min_gt_max = min > max
56+
except TypeError:
57+
min_gt_max = max < min
58+
if min_gt_max:
59+
raise AssertionError('`min` cannot be more than `max`.')
60+
61+
return min <= value and max >= value

validators/btc_address.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import re
2+
3+
from .utils import validator
4+
5+
pattern = re.compile(r"^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$")
6+
7+
8+
@validator
9+
def btc_address(value):
10+
"""
11+
Return whether or not given value is a valid bitcoin address.
12+
13+
If the value is valid bitcoin address this function returns ``True``,
14+
otherwise :class:`~validators.utils.ValidationFailure`.
15+
16+
Examples::
17+
18+
>>> btc_address('3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69')
19+
True
20+
21+
:param value: Bitcoin address string to validate
22+
"""
23+
return pattern.match(value)

0 commit comments

Comments
 (0)