mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-24 07:58:11 +01:00
disable sorting of elements by default
This commit is contained in:
parent
da975f92b2
commit
1b85eefad2
5 changed files with 15 additions and 11 deletions
|
@ -1,3 +1,3 @@
|
||||||
__version__ = "4.0.5.a10"
|
__version__ = "4.0.5.a11"
|
||||||
__codename__ = "Spring Break"
|
__codename__ = "Spring Break"
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ class ActorController(BasicController):
|
||||||
def __init__(self, cbpi):
|
def __init__(self, cbpi):
|
||||||
super(ActorController, self).__init__(cbpi, Actor,"actor.json")
|
super(ActorController, self).__init__(cbpi, Actor,"actor.json")
|
||||||
self.update_key = "actorupdate"
|
self.update_key = "actorupdate"
|
||||||
|
self.sorting=True
|
||||||
|
|
||||||
async def on(self, id, power=None):
|
async def on(self, id, power=None):
|
||||||
try:
|
try:
|
||||||
|
@ -20,7 +21,7 @@ class ActorController(BasicController):
|
||||||
if item.instance.state is False:
|
if item.instance.state is False:
|
||||||
await item.instance.on(power)
|
await item.instance.on(power)
|
||||||
#await self.push_udpate()
|
#await self.push_udpate()
|
||||||
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting)
|
||||||
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict(), True)
|
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict(), True)
|
||||||
else:
|
else:
|
||||||
await self.set_power(id, power)
|
await self.set_power(id, power)
|
||||||
|
@ -34,7 +35,7 @@ class ActorController(BasicController):
|
||||||
if item.instance.state is True:
|
if item.instance.state is True:
|
||||||
await item.instance.off()
|
await item.instance.off()
|
||||||
#await self.push_udpate()
|
#await self.push_udpate()
|
||||||
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting)
|
||||||
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
|
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Failed to switch on Actor {} {}".format(id, e), True)
|
logging.error("Failed to switch on Actor {} {}".format(id, e), True)
|
||||||
|
@ -44,7 +45,7 @@ class ActorController(BasicController):
|
||||||
item = self.find_by_id(id)
|
item = self.find_by_id(id)
|
||||||
instance = item.get("instance")
|
instance = item.get("instance")
|
||||||
await instance.toggle()
|
await instance.toggle()
|
||||||
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting)
|
||||||
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
|
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Failed to toggle Actor {} {}".format(id, e))
|
logging.error("Failed to toggle Actor {} {}".format(id, e))
|
||||||
|
@ -61,7 +62,7 @@ class ActorController(BasicController):
|
||||||
item = self.find_by_id(id)
|
item = self.find_by_id(id)
|
||||||
item.power = round(power)
|
item.power = round(power)
|
||||||
#await self.push_udpate()
|
#await self.push_udpate()
|
||||||
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting)
|
||||||
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
|
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Failed to update Actor {} {}".format(id, e))
|
logging.error("Failed to update Actor {} {}".format(id, e))
|
||||||
|
|
|
@ -14,6 +14,7 @@ class BasicController:
|
||||||
def __init__(self, cbpi, resource, file):
|
def __init__(self, cbpi, resource, file):
|
||||||
self.resource = resource
|
self.resource = resource
|
||||||
self.update_key = ""
|
self.update_key = ""
|
||||||
|
self.sorting = False
|
||||||
self.name = self.__class__.__name__
|
self.name = self.__class__.__name__
|
||||||
self.cbpi = cbpi
|
self.cbpi = cbpi
|
||||||
self.cbpi.register(self)
|
self.cbpi.register(self)
|
||||||
|
@ -55,7 +56,7 @@ class BasicController:
|
||||||
await self.push_udpate()
|
await self.push_udpate()
|
||||||
|
|
||||||
async def push_udpate(self):
|
async def push_udpate(self):
|
||||||
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))),self.sorting)
|
||||||
#self.cbpi.push_update("cbpi/{}".format(self.update_key), list(map(lambda item: item.to_dict(), self.data)))
|
#self.cbpi.push_update("cbpi/{}".format(self.update_key), list(map(lambda item: item.to_dict(), self.data)))
|
||||||
for item in self.data:
|
for item in self.data:
|
||||||
self.cbpi.push_update("cbpi/{}/{}".format(self.update_key,item.id), item.to_dict())
|
self.cbpi.push_update("cbpi/{}/{}".format(self.update_key,item.id), item.to_dict())
|
||||||
|
|
|
@ -6,6 +6,7 @@ class SensorController(BasicController):
|
||||||
def __init__(self, cbpi):
|
def __init__(self, cbpi):
|
||||||
super(SensorController, self).__init__(cbpi, Sensor, "sensor.json")
|
super(SensorController, self).__init__(cbpi, Sensor, "sensor.json")
|
||||||
self.update_key = "sensorupdate"
|
self.update_key = "sensorupdate"
|
||||||
|
self.sorting = True
|
||||||
|
|
||||||
def create_dict(self, data):
|
def create_dict(self, data):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -28,15 +28,16 @@ class CBPiWebSocket:
|
||||||
self.send(data)
|
self.send(data)
|
||||||
|
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data, sorting=False):
|
||||||
self.logger.debug("broadcast to ws clients. Data: %s" % data)
|
self.logger.debug("broadcast to ws clients. Data: %s" % data)
|
||||||
for ws in self._clients:
|
for ws in self._clients:
|
||||||
async def send_data(ws, data):
|
async def send_data(ws, data):
|
||||||
try:
|
try:
|
||||||
try:
|
if sorting:
|
||||||
data['data'].sort(key=lambda x: x.get('name').upper())
|
try:
|
||||||
except:
|
data['data'].sort(key=lambda x: x.get('name').upper())
|
||||||
pass
|
except:
|
||||||
|
pass
|
||||||
await ws.send_json(data=data, dumps=json_dumps)
|
await ws.send_json(data=data, dumps=json_dumps)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("Error with client %s: %s" % (ws, str(e)))
|
self.logger.error("Error with client %s: %s" % (ws, str(e)))
|
||||||
|
|
Loading…
Reference in a new issue