-
-
Save t3db0t/2f31e4bcb103a168563b657ea510ee1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from logpy import * | |
from logpy.core import lall | |
from logpy.arith import add, gt, sub | |
class Device(object): | |
def __init__(self, id): | |
self.id = id | |
def info(self): | |
return (self.id) | |
def __eq__(self, other): | |
return self.info() == other.info() | |
def __hash__(self): | |
return hash((type(self), self.info())) | |
class Controller(Device): | |
def __init__(self, id): | |
Device.__init__(self, id) | |
self._relay = 0 | |
self._dimLevel = 0 | |
def info(self): | |
return (self.id, self.relay, self.dimLevel) | |
@property | |
def relay(self): | |
if(self._relay == 0): | |
return "OFF" | |
if(self._relay == 1): | |
return "ON" | |
@relay.setter | |
def relay(self, value): | |
if(value == "ON") or (value == 1): | |
self._relay = 1 | |
else: | |
self._relay = 0 | |
@property | |
def dimLevel(self): | |
return self._dimLevel | |
def __str__(self): | |
s ="Controller:\n" | |
s += "\tId: 0x%X\n" | |
s += "\trelay: %s\n" | |
s += "\tdimLevel: %d\n" | |
return s % self.info() | |
unifiable(Controller) | |
devices = (Controller(0xABCD), Controller(0x1234)) | |
# print devices | |
dummyId = 0 | |
vars = {dummyId} | |
source = Controller(dummyId) | |
target = Controller(dummyId)#, dummyRelay, dummyDimLevel) | |
rules = lall( | |
(membero, source, devices), | |
(eq, 0xABCD, dummyId) | |
) | |
with variables(*vars): | |
results = run(0, target, rules) | |
for r in results: | |
print str(r) |
lucaswiman
commented
Sep 5, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment