Add bumper plugin to mqtt
This commit is contained in:
parent
134d698eeb
commit
b184e1c2c6
2 changed files with 36 additions and 7 deletions
|
|
@ -45,7 +45,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||||
body = {
|
body = {
|
||||||
"devices": [
|
"devices": [
|
||||||
{
|
{
|
||||||
"class": "tmpClass",
|
"class": "ls1ok3",
|
||||||
"company": "eco-ng",
|
"company": "eco-ng",
|
||||||
"did": "tmpDeviceID",
|
"did": "tmpDeviceID",
|
||||||
"name": "tmpName",
|
"name": "tmpName",
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,24 @@ import asyncio
|
||||||
import os
|
import os
|
||||||
from hbmqtt.broker import Broker
|
from hbmqtt.broker import Broker
|
||||||
import hbmqtt
|
import hbmqtt
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
|
|
||||||
|
class BumperMQTTPlugin:
|
||||||
|
def __init__(self, context):
|
||||||
|
self.context = context
|
||||||
|
logging.debug('Bumper Plugin Initialized')
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def on_broker_client_connected(self, client_id):
|
||||||
|
logging.debug('Bumper Connection: %s connected' % client_id)
|
||||||
|
#yield from self.context.broadcast_message('location/%s' % client_id, b'home')
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def on_broker_client_disconnected(self, client_id):
|
||||||
|
logging.debug('Bumper Connection: %s disconnected' % client_id)
|
||||||
|
#yield from self.context.broadcast_message('location/%s' % client_id, b'not_home')
|
||||||
|
|
||||||
|
|
||||||
class MQTTServer():
|
class MQTTServer():
|
||||||
clients = []
|
clients = []
|
||||||
|
|
@ -13,11 +31,17 @@ class MQTTServer():
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def broker_coro(self):
|
def broker_coro(self):
|
||||||
broker = hbmqtt.broker.Broker(config=self.default_config, plugin_namespace=".")
|
broker = hbmqtt.broker.Broker(config=self.default_config)
|
||||||
|
|
||||||
yield from broker.start()
|
yield from broker.start()
|
||||||
|
|
||||||
def __init__(self, address, run_async=False):
|
def __init__(self, address, run_async=False):
|
||||||
|
#The below adds a plugin to the hbmqtt.broker.plugins without having to futz with setup.py
|
||||||
|
distribution = pkg_resources.Distribution("hbmqtt.broker.plugins")
|
||||||
|
bumper_plugin = pkg_resources.EntryPoint.parse('bumper = bumper.mqttserver:BumperMQTTPlugin', dist=distribution)
|
||||||
|
distribution._ep_map = {"hbmqtt.broker.plugins": {"bumper": bumper_plugin}}
|
||||||
|
pkg_resources.working_set.add(distribution)
|
||||||
|
#for entry_point in pkg_resources.iter_entry_points("hbmqtt.broker.plugins"):
|
||||||
|
# print(entry_point)
|
||||||
try:
|
try:
|
||||||
# Initialize bot server
|
# Initialize bot server
|
||||||
self.default_config = {
|
self.default_config = {
|
||||||
|
|
@ -37,7 +61,12 @@ class MQTTServer():
|
||||||
'allow-anonymous': True,
|
'allow-anonymous': True,
|
||||||
'password-file': os.path.join(os.path.dirname(os.path.realpath(__file__)), "passwd"),
|
'password-file': os.path.join(os.path.dirname(os.path.realpath(__file__)), "passwd"),
|
||||||
'plugins': [
|
'plugins': [
|
||||||
'VacBotAuth'
|
'' #No plugins == no auth
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'broker': {
|
||||||
|
'plugins': [
|
||||||
|
'bumper'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'topic-check': {
|
'topic-check': {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue