Skip to content

Commit

Permalink
Bump prettier from 2.8.8 to 3.0.0 (#396)
Browse files Browse the repository at this point in the history
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Paulus Schoutsen <[email protected]>
  • Loading branch information
dependabot[bot] and balloob authored Jul 11, 2023
1 parent af2ba6e commit cc738c4
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 80 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function connect() {
if (err === ERR_HASS_HOST_REQUIRED) {
const hassUrl = prompt(
"What host to connect to?",
"http://localhost:8123"
"http://localhost:8123",
);
// Redirect user to log in on their instance
auth = await getAuth({ hassUrl });
Expand Down Expand Up @@ -137,7 +137,7 @@ connection.suspendReconnectUntil(
new Promise((resolve) => {
// When you want to try to reconnect again, resolve the promise.
resolve();
})
}),
);
```

Expand All @@ -154,7 +154,7 @@ connection.suspendReconnectUntil(
new Promise((resolve) => {
// When you want to try to reconnect again, resolve the promise.
resolve();
})
}),
);
connection.suspend();
```
Expand All @@ -166,7 +166,7 @@ connection.suspend(
new Promise((resolve) => {
// When you want to try to reconnect again, resolve the promise.
resolve();
})
}),
);
```

Expand Down Expand Up @@ -435,7 +435,7 @@ import {
(async () => {
const auth = createLongLivedTokenAuth(
"http://localhost:8123",
"YOUR ACCESS TOKEN"
"YOUR ACCESS TOKEN",
);

const connection = await createConnection({ auth });
Expand Down
8 changes: 4 additions & 4 deletions example.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<!-- To try locally, run: `yarn build` and then `npx http-server -o` -->

Expand Down Expand Up @@ -41,7 +41,7 @@
if (err === ERR_HASS_HOST_REQUIRED) {
authOptions.hassUrl = prompt(
"What host to connect to?",
"http://localhost:8123"
"http://localhost:8123",
);
if (!authOptions.hassUrl) return;
auth = await getAuth(authOptions);
Expand Down Expand Up @@ -80,7 +80,7 @@
await new Promise((resolve) => setTimeout(resolve, 4000));
}
unsubEntities = subscribeEntities(connection, (entities) =>
renderEntities(connection, entities)
renderEntities(connection, entities),
);
};

Expand All @@ -104,7 +104,7 @@

if (
["switch", "light", "input_boolean"].includes(
entId.split(".", 1)[0]
entId.split(".", 1)[0],
)
) {
const button = document.createElement("button");
Expand Down
14 changes: 7 additions & 7 deletions lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ function genAuthorizeUrl(
hassUrl: string,
clientId: string | null,
redirectUrl: string,
state: string
state: string,
) {
let authorizeUrl = `${hassUrl}/auth/authorize?response_type=code&redirect_uri=${encodeURIComponent(
redirectUrl
redirectUrl,
)}`;

if (clientId !== null) {
Expand All @@ -88,7 +88,7 @@ function redirectAuthorize(
hassUrl: string,
clientId: string | null,
redirectUrl: string,
state: string
state: string,
) {
// Add either ?auth_callback=1 or &auth_callback=1
redirectUrl += (redirectUrl.includes("?") ? "&" : "?") + "auth_callback=1";
Expand All @@ -97,14 +97,14 @@ function redirectAuthorize(
hassUrl,
clientId,
redirectUrl,
state
state,
);
}

async function tokenRequest(
hassUrl: string,
clientId: string | null,
data: AuthorizationCodeRequest | RefreshTokenRequest
data: AuthorizationCodeRequest | RefreshTokenRequest,
) {
// Browsers don't allow fetching tokens from https -> http.
// Throw an error because it's a pain to debug this.
Expand Down Expand Up @@ -224,7 +224,7 @@ export class Auth {

export function createLongLivedTokenAuth(
hassUrl: string,
access_token: string
access_token: string,
) {
return new Auth({
hassUrl,
Expand Down Expand Up @@ -300,7 +300,7 @@ export async function getAuth(options: getAuthOptions = {}): Promise<Auth> {
encodeOAuthState({
hassUrl,
clientId,
})
}),
);
// Just don't resolve while we navigate to next page
return new Promise<Auth>(() => {});
Expand Down
8 changes: 4 additions & 4 deletions lib/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const getCollection = <State>(
fetchCollection: ((conn: Connection) => Promise<State>) | undefined,
subscribeUpdates?: (
conn: Connection,
store: Store<State>
store: Store<State>,
) => Promise<UnsubscribeFunc>,
options: { unsubGrace: boolean } = { unsubGrace: true }
options: { unsubGrace: boolean } = { unsubGrace: true },
): Collection<State> => {
if (conn[key]) {
return conn[key];
Expand Down Expand Up @@ -170,8 +170,8 @@ export const createCollection = <State>(
| ((conn: Connection, store: Store<State>) => Promise<UnsubscribeFunc>)
| undefined,
conn: Connection,
onChange: (state: State) => void
onChange: (state: State) => void,
): UnsubscribeFunc =>
getCollection(conn, key, fetchCollection, subscribeUpdates).subscribe(
onChange
onChange,
);
4 changes: 2 additions & 2 deletions lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const callService = (
domain: string,
service: string,
serviceData?: object,
target?: HassServiceTarget
target?: HassServiceTarget,
) =>
connection.sendMessagePromise(
messages.callService(domain, service, serviceData, target)
messages.callService(domain, service, serviceData, target),
);
8 changes: 4 additions & 4 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ComponentLoadedEvent = {

function processComponentLoaded(
state: HassConfig,
event: ComponentLoadedEvent
event: ComponentLoadedEvent,
): Partial<HassConfig> | null {
if (state === undefined) return null;

Expand All @@ -26,11 +26,11 @@ const subscribeUpdates = (conn: Connection, store: Store<HassConfig>) =>
Promise.all([
conn.subscribeEvents(
store.action(processComponentLoaded),
"component_loaded"
"component_loaded",
),
conn.subscribeEvents(
() => fetchConfig(conn).then((config) => store.setState(config, true)),
"core_config_updated"
"core_config_updated",
),
]).then((unsubs) => () => unsubs.forEach((unsub) => unsub()));

Expand All @@ -39,7 +39,7 @@ export const configColl = (conn: Connection) =>

export const subscribeConfig = (
conn: Connection,
onChange: (state: HassConfig) => void
onChange: (state: HassConfig) => void,
): UnsubscribeFunc => configColl(conn).subscribe(onChange);

export const STATE_NOT_RUNNING = "NOT_RUNNING";
Expand Down
67 changes: 35 additions & 32 deletions lib/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ConnectionOptions = {

export type ConnectionEventListener = (
conn: Connection,
eventData?: any
eventData?: any,
) => void;

type Events = "ready" | "disconnected" | "reconnect-error";
Expand Down Expand Up @@ -183,7 +183,7 @@ export class Connection {

fireEvent(eventType: Events, eventData?: any) {
(this.eventListeners.get(eventType) || []).forEach((callback) =>
callback(this, eventData)
callback(this, eventData),
);
}

Expand Down Expand Up @@ -234,7 +234,7 @@ export class Connection {
*/
async subscribeEvents<EventType>(
callback: (ev: EventType) => void,
eventType?: string
eventType?: string,
): Promise<SubscriptionUnsubscribe> {
return this.subscribeMessage(callback, messages.subscribeEvents(eventType));
}
Expand Down Expand Up @@ -301,7 +301,7 @@ export class Connection {
async subscribeMessage<Result>(
callback: (result: Result) => void,
subscribeMessage: MessageBase,
options?: { resubscribe?: boolean }
options?: { resubscribe?: boolean },
): Promise<SubscriptionUnsubscribe> {
if (this._queuedMessages) {
await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -329,7 +329,7 @@ export class Connection {
// No need to unsubscribe if we're disconnected
if (this.connected) {
await this.sendMessagePromise(
messages.unsubscribeEvents(commandId)
messages.unsubscribeEvents(commandId),
);
}
this.commands.delete(commandId);
Expand All @@ -350,7 +350,7 @@ export class Connection {

private _handleMessage = (event: MessageEvent) => {
let messageGroup: WebSocketResponse | WebSocketResponse[] = JSON.parse(
event.data
event.data,
);

if (!Array.isArray(messageGroup)) {
Expand All @@ -368,11 +368,11 @@ export class Connection {
case "event":
if (info) {
(info as SubscribeEventCommmandInFlight<any>).callback(
message.event
message.event,
);
} else {
console.warn(
`Received event for unknown subscription ${message.id}. Unsubscribing.`
`Received event for unknown subscription ${message.id}. Unsubscribing.`,
);
this.sendMessagePromise(messages.unsubscribeEvents(message.id));
}
Expand Down Expand Up @@ -440,33 +440,36 @@ export class Connection {
const options = { ...this.options, setupRetry: 0 };

const reconnect = (tries: number) => {
setTimeout(async () => {
if (this.closeRequested) {
return;
}
if (DEBUG) {
console.log("Trying to reconnect");
}
try {
const socket = await options.createSocket(options);
this._setSocket(socket);
} catch (err) {
if (this._queuedMessages) {
const queuedMessages = this._queuedMessages;
this._queuedMessages = undefined;
for (const msg of queuedMessages) {
if (msg.reject) {
msg.reject(ERR_CONNECTION_LOST);
setTimeout(
async () => {
if (this.closeRequested) {
return;
}
if (DEBUG) {
console.log("Trying to reconnect");
}
try {
const socket = await options.createSocket(options);
this._setSocket(socket);
} catch (err) {
if (this._queuedMessages) {
const queuedMessages = this._queuedMessages;
this._queuedMessages = undefined;
for (const msg of queuedMessages) {
if (msg.reject) {
msg.reject(ERR_CONNECTION_LOST);
}
}
}
if (err === ERR_INVALID_AUTH) {
this.fireEvent("reconnect-error", err);
} else {
reconnect(tries + 1);
}
}
if (err === ERR_INVALID_AUTH) {
this.fireEvent("reconnect-error", err);
} else {
reconnect(tries + 1);
}
}
}, Math.min(tries, 5) * 1000);
},
Math.min(tries, 5) * 1000,
);
};

if (this.suspendReconnectPromise) {
Expand Down
8 changes: 4 additions & 4 deletions lib/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function processEvent(store: Store<HassEntities>, updates: StatesUpdates) {
}
if (toAdd.lc) {
entityState.last_updated = entityState.last_changed = new Date(
toAdd.lc * 1000
toAdd.lc * 1000,
).toISOString();
} else if (toAdd.lu) {
entityState.last_updated = new Date(toAdd.lu * 1000).toISOString();
Expand Down Expand Up @@ -134,7 +134,7 @@ const subscribeUpdates = (conn: Connection, store: Store<HassEntities>) =>

function legacyProcessEvent(
store: Store<HassEntities>,
event: StateChangedEvent
event: StateChangedEvent,
) {
const state = store.state;
if (state === undefined) return;
Expand Down Expand Up @@ -162,7 +162,7 @@ async function legacyFetchEntities(conn: Connection): Promise<HassEntities> {
const legacySubscribeUpdates = (conn: Connection, store: Store<HassEntities>) =>
conn.subscribeEvents<StateChangedEvent>(
(ev) => legacyProcessEvent(store, ev as StateChangedEvent),
"state_changed"
"state_changed",
);

export const entitiesColl = (conn: Connection) =>
Expand All @@ -172,5 +172,5 @@ export const entitiesColl = (conn: Connection) =>

export const subscribeEntities = (
conn: Connection,
onChange: (state: HassEntities) => void
onChange: (state: HassEntities) => void,
): UnsubscribeFunc => entitiesColl(conn).subscribe(onChange);
2 changes: 1 addition & 1 deletion lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function callService(
domain: string,
service: string,
serviceData?: object,
target?: HassServiceTarget
target?: HassServiceTarget,
) {
const message: ServiceCallMessage = {
type: "call_service",
Expand Down
Loading

0 comments on commit cc738c4

Please sign in to comment.