import json

class Device:
    def __init__(self, name, deviceType, offUrl, onUrl, httpVerb, contentType, contentBody):
        self.name = name
        self.deviceType = deviceType
        self.offUrl = offUrl
        self.onUrl = onUrl
        self.httpVerb = httpVerb
        self.contentBody = contentBody
        self.contentType = contentType

    def encode(self):
        return {
            '__type__': 'Device',
            'name': self.name,
            'devicetype': self.deviceType,
            'offurl': self.offUrl,
            'onurl': self.onUrl,
            'httpverb': self.httpVerb,
            'contentbody': self.contentBody,
            'contenttype': self.contentType
        }

def decodeDevice(jsonObj):
    if '__type__' in jsonObj and jsonObj['__type__'] == 'Device':
        return Device(jsonObj['name'], jsonObj['devicetype'], jsonObj['offurl'], jsonObj['onurl'], jsonObj['httpverb'], jsonObj['contentbody'], jsonObj['contenttype'])
    return jsonObj

