Beispiel #1
0
 def __init__(self, request_object, entity, scale):
   datetime_iso = little_helpers.get_iso_datetime_utc_tz_str()
   uncertainty_milliseconds = little_helpers.get_elapsed_in_milliseconds(entity["last_updated"])
   
   self.response_context = {
     "properties": [{
       "namespace": "Alexa.ThermostatController",
       "name": "targetSetpoint",
       "value": {
         "value": entity["attributes"]["temperature"],
         "scale": scale
       },
       "timeOfSample": datetime_iso,
       "uncertaintyInMilliseconds": uncertainty_milliseconds
     },
     {
       "namespace": "Alexa.ThermostatController",
       "name": "thermostatMode",
       "value": entity["state"].upper(),
       "timeOfSample": datetime_iso,
       "uncertaintyInMilliseconds": uncertainty_milliseconds
     }]
   }
   
   self.response_header = {
     "namespace": "Alexa",
     "name": "Response",
     "payloadVersion": "3",
     "messageId": little_helpers.get_uuid_str(),
     "correlationToken": request_object.correlationToken
   }
   
   self.response_endpoint = {
     "endpointId": little_helpers.entityId_to_endpointId(entity["entity_id"])
   }
Beispiel #2
0
 def __init__(self, request_object, entity):
   datetime_iso = little_helpers.get_iso_datetime_utc_tz_str()
   uncertainty_milliseconds = little_helpers.get_elapsed_in_milliseconds(entity["last_updated"])
   
   self.response_header = {
     "namespace": "Alexa",
     "name": "Response",
     "payloadVersion": "3",
     "messageId": little_helpers.get_uuid_str(),
     "correlationToken": request_object.correlationToken
   }
   
   self.response_endpoint = {
     "endpoint": {
       "scope": {
         "type": request_object.tokenType,
         "token": request_object.token
       },
       "endpointId": little_helpers.entityId_to_endpointId(entity["entity_id"])
     }
   }
   
   self.response_context = {
     "properties": [{
      "namespace": "Alexa.PowerController",
      "name": "powerState",
      "value": "OFF" if entity["state"].upper() == "OFF" else "ON",
      "timeOfSample": datetime_iso,
      "uncertaintyInMilliseconds": uncertainty_milliseconds
     }]
     
   }
Beispiel #3
0
    def __init__(
        self,
        request_object: Union[EndpointRequest, GenericRequest],
        error_type: str,
        error_message: str,
        namespace: str = "Alexa",
        **kwargs: Optional[Dict],
    ) -> None:
        """Initialize the object."""
        self.response_header = {
            "namespace": namespace,
            "name": "ErrorResponse",
            "messageId": little_helpers.get_uuid_str(),
            "payloadVersion": "3",
        }

        if isinstance(request_object, EndpointRequest):
            self.response_header[
                "correlationToken"] = request_object.correlationToken
            self.response_endpoint = {"endpointId": request_object.endpointId}
        else:
            self.response_header["correlationToken"] = ""
            self.response_endpoint = {"endpointId": ""}

        self.response_payload = {"type": error_type, "message": error_message}
        if kwargs:
            for key, value in kwargs.items():
                self.response_payload[str(key)] = str(value)
    def __init__(self, request_object: EndpointRequest, entity: Dict,
                 scale: str) -> None:
        """Initialize the object."""
        datetime_iso = little_helpers.get_iso_datetime_utc_tz_str()
        uncertainty_milliseconds = little_helpers.get_elapsed_in_milliseconds(
            entity["last_updated"])

        self.response_header = {
            "namespace": "Alexa",
            "name": "StateReport",
            "payloadVersion": "3",
            "messageId": little_helpers.get_uuid_str(),
            "correlationToken": request_object.correlationToken,
        }

        self.response_endpoint = {
            "endpointId":
            little_helpers.entityId_to_endpointId(entity["entity_id"])
        }

        self.response_context = {
            "properties": [
                {
                    "namespace": "Alexa.ThermostatController",
                    "name": "targetSetpoint",
                    "value": {
                        "value": entity["attributes"]["temperature"],
                        "scale": scale,
                    },
                    "timeOfSample": datetime_iso,
                    "uncertaintyInMilliseconds": uncertainty_milliseconds,
                },
                {
                    "namespace": "Alexa.ThermostatController",
                    "name": "thermostatMode",
                    "value": entity["state"].upper(),
                    "timeOfSample": datetime_iso,
                    "uncertaintyInMilliseconds": uncertainty_milliseconds,
                },
                {
                    "namespace": "Alexa.TemperatureSensor",
                    "name": "temperature",
                    "value": {
                        "value": entity["attributes"]["current_temperature"],
                        "scale": scale,
                    },
                    "timeOfSample": datetime_iso,
                    "uncertaintyInMilliseconds": uncertainty_milliseconds,
                },
                {
                    "namespace": "Alexa.PowerController",
                    "name": "powerState",
                    "value":
                    ("OFF" if entity["state"].upper() == "OFF" else "ON"),
                    "timeOfSample": datetime_iso,
                    "uncertaintyInMilliseconds": uncertainty_milliseconds,
                },
            ]
        }
    def __init__(self,
                 request_object,
                 error_type,
                 error_message,
                 namespace='Alexa',
                 **kwargs):
        self.response_header = {
            "namespace": namespace,
            "name": "ErrorResponse",
            "messageId": little_helpers.get_uuid_str(),
            "correlationToken": request_object.correlationToken,
            "payloadVersion": "3"
        }

        self.response_endpoint = {"endpointId": request_object.endpointId}

        self.response_payload = {"type": error_type, "message": error_message}

        if kwargs is not None:
            for key, value in kwargs.items():
                self.response_payload[str(key)] = value
Beispiel #6
0
  def __init__(self, request_object, entities):
    self.response_header = {
      "namespace": "Alexa.Discovery",
      "name": "Discover.Response",
      "messageId": little_helpers.get_uuid_str(),
      "payloadVersion": "3"
    }
  
    self.response_payload = {
      "endpoints": []
    }

    for entity in entities:
      supported_modes = []
      for mode in entity['attributes']['operation_list']:
        supported_modes.append(mode.upper())
      
      self.response_payload["endpoints"].append({
          "endpointId": little_helpers.entityId_to_endpointId(entity["entity_id"]),
          "friendlyName": entity['attributes']["friendly_name"],
          "description": "AC Custom Thermostat by TomerFi",
          "manufacturerName": "TomerFi",
          "displayCategories": ["THERMOSTAT", "TEMPERATURE_SENSOR"],
          "cookie": {
          },
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa.ThermostatController",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "targetSetpoint"
                  },
                  {
                    "name": "thermostatMode"
                  }
                  ],
                  "proactivelyReported": True,
                  "retrievable": True
              },
              "configuration": {
                "supportsScheduling": False,
                "supportedModes": supported_modes
              }
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.TemperatureSensor",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "temperature"
                  }
                  ],
                  "proactivelyReported": True,
                  "retrievable": True
              }
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.PowerController",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "powerState"
                  }
                  ],
                  "proactivelyReported": True,
                  "retrievable": True
              }
            }
            ]
        })