Homey-api Typings are not working with local API

Hey,

I’d like to build a next.js App as a local Dashboard for my Raspberry. For this, I’d like to use the Web API of the Homey Pro (early 2023).

I was hoping for some typings and found the homey-api package on npm. I’ve set up my api client like this:

However, everything I do get from calling this function is a Promise with any as a generic Type. This is pretty useless in my opinion, as IntelliSense won’t be of much help. Using any is never good.

Am I missing something or are there simply no typings for a local connection? I’d rather not implement my own Typings…

Nico

Homey’s typings aren’t very well maintained.

1 Like

Thanks. I already thought that this would be the problem. Are there any community-projects maintaining those?

Not that I’m aware of, no.

Check how HomeyScript does it?
Because in it, intellisence works pretty okay i would say, beter then nothing.

I actually just extended the API types as it seems that all those “Manager”-Classes are actually just props on the API client object.

This should be done by Athom in the first place (as it’s easier to maintain types when you control the sources) but if it helps someone, here’s the homey-api.d.ts file I’m now using:

import { HomeyAPIV3Local } from 'homey-api';

declare module 'homey-api' {
  export class HomeyAPIV3LocalPatched extends HomeyAPIV3Local {
    manager: HomeyAPIV3Local.Manager;
    alarms: HomeyAPIV3Local.ManagerAlarms;
    api: HomeyAPIV3Local.ManagerApi;
    apps: HomeyAPIV3Local.ManagerApps;
    arp: HomeyAPIV3Local.ManagerArp;
    ble: HomeyAPIV3Local.ManagerBLE;
    backup: HomeyAPIV3Local.ManagerBackup;
    clock: HomeyAPIV3Local.ManagerClock;
    cloud: HomeyAPIV3Local.ManagerCloud;
    coprocessor: HomeyAPIV3Local.ManagerCoprocessor;
    cron: HomeyAPIV3Local.ManagerCron;
    database: HomeyAPIV3Local.ManagerDatabase;
    devices: HomeyAPIV3Local.ManagerDevices;
    devkit: HomeyAPIV3Local.ManagerDevkit;
    discovery: HomeyAPIV3Local.ManagerDiscovery;
    drivers: HomeyAPIV3Local.ManagerDrivers;
    energy: HomeyAPIV3Local.ManagerEnergy;
    experiments: HomeyAPIV3Local.ManagerExperiments;
    flow: HomeyAPIV3Local.ManagerFlow;
    flowToken: HomeyAPIV3Local.ManagerFlowToken;
    geolocation: HomeyAPIV3Local.ManagerGeolocation;
    googleAssistant: HomeyAPIV3Local.ManagerGoogleAssistant;
    i18n: HomeyAPIV3Local.ManagerI18n;
    icons: HomeyAPIV3Local.ManagerIcons;
    images: HomeyAPIV3Local.ManagerImages;
    insights: HomeyAPIV3Local.ManagerInsights;
    ledring: HomeyAPIV3Local.ManagerLedring;
    logic: HomeyAPIV3Local.ManagerLogic;
    matter: HomeyAPIV3Local.ManagerMatter;
    mobile: HomeyAPIV3Local.ManagerMobile;
    notifications: HomeyAPIV3Local.ManagerNotifications;
    presence: HomeyAPIV3Local.ManagerPresence;
    rf: HomeyAPIV3Local.ManagerRF;
    safety: HomeyAPIV3Local.ManagerSafety;
    satellites: HomeyAPIV3Local.ManagerSatellites;
    security: HomeyAPIV3Local.ManagerSecurity;
    sessions: HomeyAPIV3Local.ManagerSessions;
    system: HomeyAPIV3Local.ManagerSystem;
    thread: HomeyAPIV3Local.ManagerThread;
    update: HomeyAPIV3Local.ManagerUpdates;
    users: HomeyAPIV3Local.ManagerUsers;
    virtualDevice: HomeyAPIV3Local.ManagerVirtualDevice;
    weather: HomeyAPIV3Local.ManagerWeather;
    webserver: HomeyAPIV3Local.ManagerWebserver;
    zigbee: HomeyAPIV3Local.ManagerZigbee;
    zones: HomeyAPIV3Local.ManagerZones;
    zwave: HomeyAPIV3Local.ManagerZwave
  }
}

Then use it with:

import { HomeyAPIV3, HomeyAPIV3LocalPatched } from 'homey-api';

const homeyApi = await HomeyAPIV3.createLocalAPI({
    address: 'http://ip-address',
    token: 'token',
    debug: null,
}) as HomeyAPIV3LocalPatched;

And don’t forget to include your homey-api.d.ts file in your tsconfig.json.

This seems to work pretty well though I haven’t checked all “Managers” for their functionality (just created these props according to the web api reference).


1 Like

Homeyscript doesn’t use Typescript but Javascript, so it’s weakly typed and doesn’t have to deal with return types, etc.

1 Like

Indeed, i totally agree that its weak. However, much beter than absolutely nothing :wink: