Skip to content

Commit

Permalink
Fixed blueprint interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Apr 20, 2020
1 parent cd71fc4 commit b7150ee
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions labthings/server/sockets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def property_notify(self, viewcls):
else:
property_value = None

property_name = str(getattr(viewcls, "endpoint", "unknown"))
property_name = getattr(viewcls, "endpoint", None) or getattr(
viewcls, "__name__", "unknown"
)

response = encode_json(
{"messageType": "propertyStatus", "data": {property_name: property_value}}
Expand Down Expand Up @@ -54,18 +56,18 @@ def __init__(self, app=None):

@abstractmethod
def init_app(self, app):
pass
"Registers Flask middleware"

def route(self, rule, **options):
def decorator(view_func):
options.pop("endpoint", None)
self.add_url_rule(rule, view_func, **options)
return view_func
def decorator(f):
endpoint = options.pop("endpoint", None)
self.add_url_rule(rule, endpoint, f, **options)
return f

return decorator

def add_url_rule(self, rule, view_func, **options):
self.url_map.add(Rule(rule, endpoint=view_func))
def add_url_rule(self, rule, _, f, **options):
self.url_map.add(Rule(rule, endpoint=f))

def register_blueprint(self, blueprint, **options):
"""
Expand Down

0 comments on commit b7150ee

Please sign in to comment.