Pebble.Companion.Phone
Watch AppMessage protocol wiring and per-API platform incoming ports.
Use the typed Pebble.Companion.* modules for phone platform APIs such as weather, storage, and battery. Each platform API registers its own incoming port so apps can compose listeners with plain Sub.batch.
This module is for typed watch ↔ phone AppMessage traffic and platform bridge ports only.
Message constructors such as WatchToPhone and PhoneToWatch come from your project's protocol definition in protocol/src/Companion/Types.elm.
import Companion.Types exposing (PhoneToWatch(..), WatchToPhone(..))
import Pebble.Companion.Battery as Battery
import Pebble.Companion.Locale as Locale
import Pebble.Companion.Phone as Phone
type Msg
= FromWatch (Result String WatchToPhone)
| GotBattery (Result String Battery.BatteryInfo)
| GotLocale (Result String Locale.LocaleInfo)
subscriptions _ =
Sub.batch
[ Phone.onWatchToPhone FromWatch
, Battery.onBattery GotBattery
, Locale.onLocale GotLocale
]Watch protocol
decodeWatchToPhone
decodeWatchToPhone : Decode.Value -> Result String WatchToPhoneDecode a watch-originated request payload into a typed message.
onWatchToPhone
onWatchToPhone : (Result String WatchToPhone -> msg) -> Sub msgSubscribe to watch-originated AppMessage payloads as typed protocol messages.
sendPhoneToWatch
sendPhoneToWatch : PhoneToWatch -> Cmd msgEncode and send a typed phone-to-watch response.
Platform bridge
request
request : String -> String -> String -> (Decode.Value -> Result String a) -> Request aBuild a typed platform bridge request from an API id, operation, and response decoder.
requestWithPayload
requestWithPayload : String
-> String
-> String
-> Encode.Value
-> (Decode.Value -> Result String a)
-> Request aBuild a platform bridge request that includes a JSON payload.
send
send : (Result String a -> msg) -> Request a -> Cmd msgSend a typed platform bridge request and decode the response into msg.
sendBridgeCommand
sendBridgeCommand : CommandEnvelope -> Cmd msgSend a raw platform bridge command envelope to the companion runtime.
registerHandler
registerHandler : String -> Encode.Value -> Cmd msgRegister interest in a platform handler with the companion bridge.
Platform ports
platformIncomingFor
platformIncomingFor : String -> (Decode.Value -> msg) -> Sub msgRoute a platform handler id to its dedicated incoming port.