diff --git a/doc/changelog.rst b/doc/changelog.rst index 2248aca..110eece 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -1,6 +1,10 @@ Changelog ========= +Version 0.0.6 +------------- +* Flask-MQTT now supports Python 2.7 + Version 0.0.5 ------------- * fixed unsupported type annotations for older Python 3 versions diff --git a/doc/index.rst b/doc/index.rst index f6c3037..3548126 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -25,7 +25,8 @@ or monitor and control these devices from one or multiple clients. Support ======= -This package uses type annotations so it needs Python 3 and the `typing package `_ installed. Since Python 3.6 the typing package is a builtin package. Python 2 is not supported. +This package uses type annotations so it needs Python 3.6 or Python 2.7/3.x +with the `typing package `_ installed. Indices and tables ================== diff --git a/flask_mqtt/__init__.py b/flask_mqtt/__init__.py index e544c0a..f91e41a 100644 --- a/flask_mqtt/__init__.py +++ b/flask_mqtt/__init__.py @@ -11,23 +11,25 @@ MQTT_LOG_WARNING -__version__ = '0.0.5' +__version__ = '0.0.6' class Mqtt(): - def __init__(self, app: Flask=None) -> None: + def __init__(self, app): + # type: (Flask) -> None self.app = app self.client = Client() self.client.on_connect = self._handle_connect self.client.on_disconnect = self._handle_disconnect - self.topics = [] #: type: List + self.topics = [] # type: List[str] self.connected = False if app is not None: self.init_app(app) - def init_app(self, app: Flask) -> None: + def init_app(self, app): + # type: (Flask) -> None self.username = app.config.get('MQTT_USERNAME') self.password = app.config.get('MQTT_PASSWORD') self.broker_url = app.config.get('MQTT_BROKER_URL', 'localhost') @@ -46,7 +48,8 @@ def init_app(self, app: Flask) -> None: self._connect() - def _connect(self) -> None: + def _connect(self): + # type: () -> None if self.username is not None: self.client.username_pw_set(self.username, self.password) @@ -71,20 +74,23 @@ def _connect(self) -> None: keepalive=self.keepalive ) - def _disconnect(self) -> None: + def _disconnect(self): + # type: () -> None self.client.disconnect() - def _handle_connect(self, client: Client, userdata: Any, flags: Dict, - rc: int) -> None: + def _handle_connect(self, client, userdata, flags, rc): + # type: (Client, Any, Dict, int) -> None if rc == MQTT_ERR_SUCCESS: self.connected = True for topic in self.topics: self.client.subscribe(topic) - def _handle_disconnect(self, client: str, userdata: Any, rc: int) -> None: + def _handle_disconnect(self, client, userdata, rc): + # type: (str, Any, int) -> None self.connected = False - def on_topic(self, topic: str) -> Callable: + def on_topic(self, topic): + # type: (str) -> Callable """ Decorator to add a callback function that is called when a certain topic has been published. The callback function is expected to have the @@ -102,12 +108,14 @@ def handle_mytopic(client, userdata, message): .format(message.topic, message.payload.decode())) """ - def decorator(handler: Callable[[str], None]) -> Callable[[str], None]: + def decorator(handler): + # type: (Callable[[str], None]) -> Callable[[str], None] self.client.message_callback_add(topic, handler) return handler return decorator - def subscribe(self, topic: str, qos: int=0) -> None: + def subscribe(self, topic, qos=0): + # type: (str, int) -> None """ Subscribe to a certain topic. @@ -137,7 +145,8 @@ def subscribe(self, topic: str, qos: int=0) -> None: return result - def unsubscribe(self, topic: str) -> None: + def unsubscribe(self, topic): + # type: (str) -> None """ Unsubscribe from a single topic. @@ -157,7 +166,8 @@ def unsubscribe(self, topic: str) -> None: return result - def unsubscribe_all(self) -> None: + def unsubscribe_all(self): + # type: () -> None """ Unsubscribe from all topics. @@ -166,8 +176,8 @@ def unsubscribe_all(self) -> None: for topic in topics: self.unsubscribe(topic) - def publish(self, topic: str, payload: bytes=None, qos: int=0, - retain: bool=False) -> Tuple[int, int]: + def publish(self, topic, payload=None, qos=0, retain=False): + # type: (str, bytes, int, bool) -> Tuple[int, int] """ Send a message to the broker. @@ -192,7 +202,8 @@ def publish(self, topic: str, payload: bytes=None, qos: int=0, self.client.reconnect() return self.client.publish(topic, payload, qos, retain) - def on_message(self) -> Callable: + def on_message(self): + # type: () -> Callable """ Decorator to handle all messages that have been subscribed. @@ -206,12 +217,14 @@ def handle_messages(client, userdata, message): .format(message.topic, message.payload.decode())) """ - def decorator(handler: Callable) -> Callable: + def decorator(handler): + # type: (Callable) -> Callable self.client.on_message = handler return handler return decorator - def on_log(self) -> Callable: + def on_log(self): + # type: () -> Callable """ Decorator to handle MQTT logging. @@ -224,7 +237,8 @@ def handle_logging(client, userdata, level, buf): print(client, userdata, level, buf) """ - def decorator(handler: Callable) -> Callable: + def decorator(handler): + # type: (Callable) -> Callable self.client.on_log = handler return handler return decorator diff --git a/requirements/develop.in b/requirements/develop.in index 918e111..09e771a 100644 --- a/requirements/develop.in +++ b/requirements/develop.in @@ -1,3 +1,4 @@ -r base.txt +coverage mypy sphinx diff --git a/requirements/develop.txt b/requirements/develop.txt index 27220ea..761fed5 100644 --- a/requirements/develop.txt +++ b/requirements/develop.txt @@ -9,6 +9,7 @@ babel==2.4.0 # via sphinx certifi==2017.4.17 # via requests chardet==3.0.4 # via requests click==6.7 +coverage==4.4.1 docutils==0.13.1 # via sphinx flask==0.12.2 idna==2.5 # via requests diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..abf6846 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[mypy] +ignore_missing_imports = True +disallow_untyped_calls = True +disallow_untyped_defs = True diff --git a/setup.py b/setup.py index cfa6e1e..b5e6b1a 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ else: setup( name='Flask-MQTT', - version='0.0.5', + version='0.0.6', url='https://github.com/MrLeeh/Flask-MQTT', license='MIT', author='Stefan Lehmann',