def __init__(self, default_name, path): Thing.__init__(self, default_name, path) self.open = False self.set_description( 'strong roots', 'These roots look very strong. You wish you could move them.') self.add_adjectives('strong') self.actions.append(Action(self.move_roots, ['move'], True, False))
def __init__(self, name, char, col, control, time_to_act, is_immobile): Thing.__init__(self, name, char, col, is_immobile) self.control = control self.time_to_act = time_to_act self.field_of_view_radius = 10
def __init__(self, width, height, mass, speedlimit=.5): Thing.__init__(self, width, height, mass, speedlimit=.5) self.gravity = True self.jump_power = 15 self.jump_power2 = 15 self.doublejump_delay = 0 self.walljump_power_right = False self.walljump_power_left = False
def __init__(self, default_name, path, bonus, unwieldiness, pref_id=None): Thing.__init__(self, default_name, path, pref_id) self.bonus = bonus self.unwieldiness = unwieldiness self.actions.append(Action(self.wear, ['wear', 'use'], True, False)) self.actions.append( Action(self.unwear, ['unwear', 'remove'], True, False)) # overwrite default drop action: for a in self.actions: if 'drop' in a.verblist: a.func = self.armor_drop
def __init__(self): Thing.__init__(self, 'urn:dev:ops:my-pycom-pysense', 'My Pycom', ['RGBLed', 'memory'], 'A web connected Pycom') self.color = 0 #0 is no light, 20 is very light blue #0xff00 #green self.updateLeds() self.mempycom = Value(0.0) self.seconds = 0 self.__alarm = Timer.Alarm(self._seconds_handler, s=10, periodic=True) #self._alarm = Timer.Alarm(updateMemPycom, 1, arg=None, periodic=True) self.add_property( Property(self, 'mempycom', self.mempycom, metadata={ '@type': 'SystemParameter', 'title': 'Memory', 'type': 'number', 'description': 'The free RAM of the system', })) self.add_property( Property(self, 'color', Value(self.color, self.setcolor), metadata={ '@type': 'ColorProperty', 'title': 'Color', 'type': 'integar', 'description': 'The color of the LED', })) self.add_available_action( 'setrgbcolor', { 'title': 'Change Color', 'description': 'Change the color of LED', 'input': { 'type': 'object', 'required': [ 'color', ], 'properties': { 'color': { 'type': 'integer', 'minimum': 0, 'maximum': 0xFFFFFF, #'unit': 'percent', }, }, }, }, SetRGBColor)
def __init__(self, ID, path, hidden_room): Thing.__init__(self, ID, path) self.set_description('bookcase full of books', \ 'This bookcase is a hodgepodge of books; some are newer, but a lot of old ones are scattered around them.') # we want this to trigger if they type, for example, "take old book" self.add_names("book") self.add_adjectives("old", "new") self.fix_in_place("The bookcase appears to be fixed to the wall.") self.actions.append( Action(self.handle_book, ["take", "get", "pull"], True, False)) self.hidden_room = hidden_room
def __init__(self, default_name, path, pref_id=None): Thing.__init__(self, default_name, path, pref_id) self.contents = [] self.see_inside = True # can contents of container be seen? self.closed = False # can't remove items from closed container self.closed_err = "" # custom "container is closed" error msg self.closable = False # can this container be opened and closed? self.liquid = False # can this container carry liquid? self.max_weight_carried = 1 self.max_volume_carried = 1 self.insert_prepositions = ["in", "into", "inside"] self.actions.append(Action(self.put, ["put", "insert"], True, False)) self.actions.append(Action(self.remove, ["remove"], True, False)) self.actions.append(Action(self.open, ["open"], True, False)) self.actions.append(Action(self.close_action, ["close"], True, False))
def __init__(self, pin): Thing.__init__(self, 'Button 0', ['BinarySensor'], 'Button 0 on SparkFun ESP32 Thing') self.pin = machine.Pin(pin, machine.Pin.IN) self.button = Value(False) self.add_property( Property(self, 'on', self.button, metadata={ 'type': 'boolean', 'description': 'Button 0 pressed', 'readOnly': True, })) self.prev_pressed = self.is_pressed()
def __init__(self, rPin, gPin, bPin): Thing.__init__( self, "urn:dev:ops:esp32-rgb-led-1234", "ESP32-RGB-LED", ["OnOffSwitch", "Light", "ColorControl"], "RGB LED on ESP-Wrover-Kit", ) self.pinRed = machine.Pin(rPin, machine.Pin.OUT) self.pinGreen = machine.Pin(gPin, machine.Pin.OUT) self.pinBlue = machine.Pin(bPin, machine.Pin.OUT) self.pwmRed = machine.PWM(self.pinRed) self.pwmGreen = machine.PWM(self.pinGreen) self.pwmBlue = machine.PWM(self.pinBlue) self.redLevel = 50 self.greenLevel = 50 self.blueLevel = 50 self.on = False self.updateLeds() self.add_property( Property( self, "on", Value(True, self.setOnOff), metadata={ "@type": "OnOffProperty", "title": "On/Off", "type": "boolean", "description": "Whether the LED is turned on", }, ) ) self.add_property( Property( self, "color", Value("#808080", self.setRGBColor), metadata={ "@type": "ColorProperty", "title": "Color", "type": "string", "description": "The color of the LED", }, ) )
def __init__(self, default_name, path, damage, accuracy, unwieldiness, pref_id=None): Thing.__init__(self, default_name, path, pref_id) self.damage = damage self.accuracy = accuracy self.unwieldiness = unwieldiness self.actions.append(Action(self.wield, ['wield', 'use'], True, False)) self.actions.append(Action(self.unwield, ['unwield'], True, False)) # overwrite default drop action: for a in self.actions: if 'drop' in a.verblist: a.func = self.weapon_drop
def __init__(self, rPin, gPin, bPin): Thing.__init__( self, 'urn:dev:ops:esp32-rgb-led-1234', 'ESP32-RGB-LED', ['OnOffSwitch', 'Light', 'ColorControl'], 'RGB LED on ESP-Wrover-Kit' ) self.pinRed = machine.Pin(rPin, machine.Pin.OUT) self.pinGreen = machine.Pin(gPin, machine.Pin.OUT) self.pinBlue = machine.Pin(bPin, machine.Pin.OUT) self.pwmRed = machine.PWM(self.pinRed) self.pwmGreen = machine.PWM(self.pinGreen) self.pwmBlue = machine.PWM(self.pinBlue) self.redLevel = 50 self.greenLevel = 50 self.blueLevel = 50 self.on = False self.updateLeds() self.add_property( Property(self, 'on', Value(True, self.setOnOff), metadata={ '@type': 'OnOffProperty', 'title': 'On/Off', 'type': 'boolean', 'description': 'Whether the LED is turned on', })) self.add_property( Property(self, 'color', Value('#808080', self.setRGBColor), metadata={ '@type': 'ColorProperty', 'title': 'Color', 'type': 'string', 'description': 'The color of the LED', }))
def __init__(self): Thing.__init__(self, 'urn:dev:ops:my-pysense', 'My PySense', [ 'Temperature', 'Humidity', 'Pressure', 'Luminance', 'Accelerometer' ], 'A Sensor Shield') self.seconds = 0 self.temperature = Value(0.0) self.humidity = Value(0.0) self.light = lt.light()[0] self.accelaration_0 = li.acceleration()[0] self.accelaration_1 = li.acceleration()[1] self.accelaration_2 = li.acceleration()[2] self.roll = li.roll() self.pitch = li.pitch() self.__alarm = Timer.Alarm(self._seconds_handler, s=10, periodic=True) #self._alarm = Timer.Alarm(updateMemPycom, 1, arg=None, periodic=True) self.add_property( Property( self, 'temperature', self.temperature, #, self.updateTemperature), metadata={ '@type': 'Temperature', 'title': 'Temperature', 'type': 'number', 'description': 'The temperature sensor value', })) self.add_property( Property(self, 'humidity', self.humidity, metadata={ '@type': 'Humidity', 'title': 'Humidity', 'type': 'number', 'description': 'The humidity sensor value', }))
def __init__(self): Thing.__init__(self, 'My Humidity Sensor', ['MultiLevelSensor'], 'A web connected humidity sensor') self.level = Value(0.0) self.add_property( Property(self, 'level', self.level, metadata={ '@type': 'LevelProperty', 'label': 'Humidity', 'type': 'number', 'description': 'The current humidity in %', 'minimum': 0, 'maximum': 100, 'unit': 'percent', })) log.debug('starting the sensor update looping task')
def __init__(self): Thing.__init__(self, 'My Lamp', 'dimmableLight', 'A web connected lamp') self.add_available_action( 'fade', { 'description': 'Fade the lamp to a given level', 'input': { 'type': 'object', 'required': [ 'level', 'duration', ], 'properties': { 'level': { 'type': 'number', 'minimum': 0, 'maximum': 100, }, 'duration': { 'type': 'number', 'unit': 'milliseconds', }, }, } }, FadeAction) self.add_available_event( 'overheated', { 'description': 'The lamp has exceeded its safe operating temperature', 'type': 'number', 'unit': 'celsius' }) self.add_property(self.get_on_property()) self.add_property(self.get_level_property())
def __init__(self, rPin, gPin, bPin): Thing.__init__(self, 'ESP32-RGB-LED', 'dimmableColorLight', 'RGB LED on ESP-Wrover-Kit') self.red = machine.Pin(rPin, machine.Pin.OUT) self.green = machine.Pin(gPin, machine.Pin.OUT) self.blue = machine.Pin(bPin, machine.Pin.OUT) self.add_property( Property(self, 'on', Value(True, self.setOnOff), metadata={ 'type': 'boolean', 'description': 'Whether the LED is turned on', })) self.add_property( Property(self, 'level', Value(50, self.setRGBLevel), metadata={ 'type': 'number', 'description': 'The level of light from 0-100', 'minimum': 0, 'maximum': 100, })) self.add_property( Property(self, 'color', Value('#808080', self.setRGBColor), metadata={ 'type': 'string', 'description': 'The color of the LED', }))
def __init__(self, default_name, path): Thing.__init__(self, default_name, path) self.light = 0 self.actions.append( Action(self.activate, ["activate", "turn"], True, True)) self.actions.append(Action(self.put_away, ["hide"], True, True))
def __init__(self, ledPin, buttonPin): Thing.__init__( self, "dev:blue-led-1234", "Blue LED", ["OnOffSwitch", "Light"], "Blue LED on SparkFun ESP32 Thing", ) # LED setup self.pinLed = machine.Pin(ledPin, machine.Pin.OUT) self.pwmLed = machine.PWM(self.pinLed) self.ledBrightness = 50 self.on = False self.updateLed() # Button setup self.pinButton = machine.Pin(buttonPin, machine.Pin.IN) self.add_property( Property( self, "on", readproperty=self.getOnOff, writeproperty=self.setOnOff, metadata={ "@type": "OnOffProperty", "title": "On/Off", "type": "boolean", "description": "Whether the LED is turned on", }, )) self.add_property( Property( self, "brightness", readproperty=self.getBrightness, writeproperty=self.setBrightness, metadata={ "@type": "BrightnessProperty", "title": "Brightness", "type": "number", "minimum": 0, "maximum": 100, "unit": "percent", "description": "The brightness of the LED", }, )) self.add_property( Property( self, "pressed", readproperty=self.getPressed, metadata={ "type": "boolean", "description": "Button 0 pressed", "readOnly": True, }, )) self.add_action( Action( self, "fade", invokeaction=fadeBrightness, metadata={ "title": "Fade", "description": "Fade the lamp to a given level", "input": { "type": "object", "required": [ "brightness", "duration", ], "properties": { "brightness": { "type": "integer", "minimum": 0, "maximum": 100, "unit": "percent", }, "duration": { "type": "integer", "minimum": 1, "unit": "milliseconds", }, }, }, }, ))
def __init__(self, name, use, location=None, pin=0): Thing.__init__(self, name, use, location, pin)
def __init__(self, x, y): self.awareness = Awareness() self.land = None Thing.__init__(self, x, y)
def __init__(self, name, use, mac, location=None): Thing.__init__(self, name, use, location=location) self.mac = mac # SensorTag MAC address
def __init__(self): Thing.__init__(self) self.at = {} self.df = Dexterity self.dm = Strength
def __init__(self): Thing.__init__(self) self.style = "O"
def __init__(self, ID, path): Thing.__init__(self, ID, path) self.set_description('metal sink', "This is an old metal sink, probably from the 1960's, and nothing seems wrong with it.") self.fix_in_place("You can't take the sink!") self.actions.append(Action(self.fill_container, ["fill"], True, False)) self.actions.append(Action(self.pour_out_in_sink, ['pour'], True, False))
def __init__(self, x, y): Thing.__init__(self, x, y)
def __init__(self, width, height, mass, surface=pygame.Surface((0,0)), speedlimit=2): Thing.__init__(self, width, height, mass, speedlimit=2) self.surface.fill((127,127,127)) self.mass = 2 self.gravity = False
def __init__(self, default_name, short_desc, long_desc, pref_id=None): Thing.__init__(self, default_name, None) self.fix_in_place("You can't move the %s!" % (default_name)) self.set_description(short_desc, long_desc) # response tuple is (verblist, result_str, transitive, intransitive) self.responses = [] # list of response tuples
def __init__(self): Thing.__init__(self, 'My Lamp', ['OnOffSwitch', 'Light'], 'A web connected lamp') self.add_property( Property(self, 'on', Value(True, lambda v: print('On-State is now', v)), metadata={ '@type': 'OnOffProperty', 'title': 'On/Off', 'type': 'boolean', 'description': 'Whether the lamp is turned on', })) self.add_property( Property(self, 'brightness', Value(50, lambda v: print('Brightness is now', v)), metadata={ '@type': 'BrightnessProperty', 'title': 'Brightness', 'type': 'integer', 'description': 'The level of light from 0-100', 'minimum': 0, 'maximum': 100, 'unit': 'percent', })) self.add_available_action( 'fade', { 'title': 'Fade', 'description': 'Fade the lamp to a given level', 'input': { 'type': 'object', 'required': [ 'brightness', 'duration', ], 'properties': { 'brightness': { 'type': 'integer', 'minimum': 0, 'maximum': 100, 'unit': 'percent', }, 'duration': { 'type': 'integer', 'minimum': 1, 'unit': 'milliseconds', }, }, }, }, FadeAction) self.add_available_event( 'overheated', { 'description': 'The lamp has exceeded its safe operating temperature', 'type': 'number', 'unit': 'degree celsius', })