-
Notifications
You must be signed in to change notification settings - Fork 0
/
zeroconfhandler.py
36 lines (28 loc) · 1.04 KB
/
zeroconfhandler.py
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
import socket
import zeroconf as zc
class ZeroConfHandler:
SERVICE_TYPE = "_ultimaker._tcp.local."
def __init__(self, module):
self.module = module
self.zeroconf = zc.Zeroconf()
self.prop_dict = {
# Necessary to be noticed by Cura
b'type': b'printer',
b'name': self.module.NAME.encode(),
# BOM-number, for now we disguise as an Ultimaker 3
b'machine': b'213482',
b'firmware_version': self.module.VERSION.encode(),
}
self.info = zc.ServiceInfo(
type_=self.SERVICE_TYPE,
name=self.module.NAME + "." + self.SERVICE_TYPE,
addresses=[socket.inet_aton(self.module.ADDRESS)],
port=80, # Default HTTP port, this is where Cura sends to
properties=self.prop_dict,
)
def start(self):
"""Start the zeroconf service"""
self.zeroconf.register_service(self.info)
def stop(self):
"""Stop the zeroconf service"""
self.zeroconf.close()