from sirius.coding import bitshuffle
from sirius.models.db import db
-
class Bridge(db.Model):
"""Bridges are not really interesting for users other than that they
are connected so we don't store ownership for them.
return printer.used_claim_code
+ @property
+ def is_online(self):
+ from sirius.protocol import protocol_loop
+ return protocol_loop.device_is_online(self.device_address)
+
class ClaimCode(db.Model):
"""Printer and claim codes are joined over the hardware xor. Claim
return local_data['next_command_id']
+def device_is_online(device_address):
+ for bridge_state in bridge_by_address.values():
+ if device_address in bridge_state.connected_devices:
+ return True
+ return False
+
+
def send_message(device_address, message):
"""Sends a single message to a connected device.
<ul>
{% for p in my_printers %}
- <li>{{ p.name }} (owned by you)
+ <li>
+ {% if p.is_online %}
+ <span class="label label-success">Online</span>
+ {% else %}
+ <span class="label label-default">Offline</span>
+ {% endif %}
+ {{ p.name }} (owned by you)
<a class="btn btn-default btn-xs" href="{{
url_for('printer_overview.printer_overview',
printer_id=p.id) }}">Overview</a>
{% endfor %}
{% for p in friends_printers %}
- <li>{{ p.name }} (owned by @{{ p.owner.username }})
+ <li>
+ {% if p.is_online %}
+ <span class="label label-success">Online</span>
+ {% else %}
+ <span class="label label-default">Offline</span>
+ {% endif %}
+ {{ p.name }} (owned by @{{ p.owner.username }})
<a class="btn btn-default btn-xs" href="{{
url_for('printer_print.printer_print',
printer_id=p.id) }}">Send message</a>