Google Home Foyer API Stubs
ghome-foyer-api provides generated protobuf stubs for interacting with the Google Home Foyer API. This library simplifies client-side development for devices that expose this gRPC interface. It currently supports protobuf v5 and v6, with releases often driven by updates to underlying gRPC and protobuf dependencies.
Common errors
-
grpc._channel._MultiThreadedRendezvous: <_Rendezvous of RPC ... code=UNAVAILABLE, details='failed to connect to all addresses'
cause The gRPC server you are trying to connect to is not running, is not accessible at the specified address, or a firewall is blocking the connection.fixVerify that the gRPC server is running and listening on the correct IP address and port (e.g., `localhost:50051`). Check network connectivity and firewall rules. Ensure `SERVER_ADDRESS` in your code is correct. -
TypeError: Parameter to MergeFrom() must be instance of same class: expected <your.message.Type> got <another.message.Type>
cause This error typically indicates a protobuf message type mismatch, often due to different versions of generated stubs (client vs. server) or an incompatibility with the installed `protobuf` library version.fixEnsure that the `ghome-foyer-api` library, `protobuf`, and `grpcio` are all up-to-date and compatible. If you are interacting with a server, ensure it was built with compatible protobuf definitions and versions. Re-installing `ghome-foyer-api --no-cache-dir` can sometimes resolve build-time dependency issues. -
ModuleNotFoundError: No module named 'ghome_foyer_api'
cause The `ghome-foyer-api` library has not been installed in the current Python environment or the environment is not active.fixInstall the package using `pip install ghome-foyer-api`. If using a virtual environment, ensure it is activated before running your script.
Warnings
- breaking Protobuf version compatibility is critical. This library is sensitive to the `protobuf` and `grpcio` versions installed. Mismatches can lead to serialization errors or runtime crashes. Check the `pyproject.toml` or `setup.py` for exact dependency ranges.
- gotcha This library provides only generated *stubs* for the Google Home Foyer API. It does not implement the API itself or provide a direct connection to public Google services. You must have access to a gRPC server (e.g., a local Google Home device or an emulator) that exposes the Foyer API for these stubs to be functional.
- deprecated Older versions (prior to v1.1.0) only supported Protobuf v4. Version v1.1.0 added support for Protobuf v5, and v1.2.0 added support for Protobuf v6. Using an older version of this library with newer Protobuf installations, or vice versa, can lead to incompatibility issues.
Install
-
pip install ghome-foyer-api
Imports
- foyer_v1_pb2
from ghome_foyer_api import foyer_v1_pb2
- foyer_v1_pb2_grpc
from ghome_foyer_api import foyer_v1_pb2_grpc
- device_pb2
from ghome_foyer_api import device_pb2
Quickstart
import grpc
from ghome_foyer_api import foyer_v1_pb2_grpc, foyer_v1_pb2
import os
# This library provides generated protobuf/gRPC stubs for the Google Home Foyer API.
# It requires a running gRPC server that implements this API (e.g., a Google Home device
# exposing the Foyer API on the local network) to be functional.
# Replace with the actual address of your Google Home Foyer API server.
# For local testing or development, 'localhost:50051' is a common placeholder.
SERVER_ADDRESS = os.environ.get('GHOME_FOYER_API_SERVER_ADDRESS', 'localhost:50051')
try:
# Establish an insecure gRPC channel to the server.
# For production environments, consider secure channels (e.g., `grpc.ssl_channel`).
with grpc.insecure_channel(SERVER_ADDRESS) as channel:
# Create a stub for the Foyer service.
# This object exposes the RPC methods defined in the Foyer API.
stub = foyer_v1_pb2_grpc.FoyerStub(channel)
print(f"Successfully created FoyerStub for server at {SERVER_ADDRESS}")
print("To interact, call specific RPC methods defined in the Foyer API using 'stub.'")
# Example (illustrative, actual method names and parameters vary per API):
# request = foyer_v1_pb2.GetDeviceInfoRequest(device_id='some_id')
# response = stub.GetDeviceInfo(request)
# print(f"Device Info: {response}")
except grpc.RpcError as e:
print(f"Error connecting or calling gRPC: {e.code().name} - {e.details()}")
print("Ensure the gRPC server is running and accessible at the specified address.")
except Exception as e:
print(f"An unexpected error occurred: {e}")