Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"version": "1.0.0",
"scripts": {
"build": "script/build_frontend",
"lint": "eslint src hassio/src gallery/src test-mocha && tslint -c tslint.json 'src/**/*.ts' 'hassio/src/**/*.ts' 'gallery/src/**/*.ts' 'test-mocha/**/*.ts' && polymer lint && tsc",
"mocha": "node_modules/.bin/mocha --opts test-mocha/mocha.opts",
"lint": "eslint src hassio/src gallery/src && tslint 'src/**/*.ts' 'hassio/src/**/*.ts' 'gallery/src/**/*.ts' 'test-mocha/**/*.ts' && polymer lint && tsc",
"mocha": "node_modules/.bin/ts-mocha -p test-mocha/tsconfig.test.json --opts test-mocha/mocha.opts",
"test": "npm run lint && npm run mocha",
"docker_build": "sh ./script/docker_run.sh build $npm_package_version",
"bash": "sh ./script/docker_run.sh bash $npm_package_version"
Expand Down Expand Up @@ -100,10 +100,12 @@
"@babel/preset-env": "^7.1.0",
"@babel/preset-typescript": "^7.1.0",
"@gfx/zopfli": "^1.0.9",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"babel-eslint": "^10",
"babel-loader": "^8.0.4",
"babel-minify-webpack-plugin": "^0.3.1",
"chai": "^4.1.2",
"chai": "^4.2.0",
"compression-webpack-plugin": "^2.0.0",
"copy-webpack-plugin": "^4.5.2",
"del": "^3.0.0",
Expand All @@ -126,7 +128,6 @@
"husky": "^1.1.0",
"lint-staged": "^8.0.2",
"merge-stream": "^1.0.1",
"mocha": "^5.2.0",
"parse5": "^5.1.0",
"polymer-analyzer": "^3.1.2",
"polymer-bundler": "^4.0.2",
Expand All @@ -135,7 +136,8 @@
"raw-loader": "^0.5.1",
"reify": "^0.18.1",
"require-dir": "^1.0.0",
"sinon": "^7.1.0",
"sinon": "^7.1.1",
"ts-mocha": "^2.0.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-eslint-rules": "^5.4.0",
Expand Down
4 changes: 0 additions & 4 deletions src/common/config/is_component_loaded.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/common/config/is_component_loaded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { HomeAssistant } from "../../types";

/** Return if a component is loaded. */
export default function isComponentLoaded(
hass: HomeAssistant,
component: string
): boolean {
return hass && hass.config.components.indexOf(component) !== -1;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Return if the displaymode is in standalone mode (PWA). */
export default function isPwa() {
export default function isPwa(): boolean {
return window.matchMedia("(display-mode: standalone)").matches;
}
4 changes: 0 additions & 4 deletions src/common/config/location_name.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/common/config/location_name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { HomeAssistant } from "../../types";

/** Get the location name from a hass object. */
export default function computeLocationName(hass: HomeAssistant): string {
return hass && hass.config.location_name;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function durationToSeconds(duration) {
export default function durationToSeconds(duration: string): number {
const parts = duration.split(":").map(Number);
return parts[0] * 3600 + parts[1] * 60 + parts[2];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fecha from "fecha";
import * as fecha from "fecha";

// Check for support of native locale string options
function toLocaleDateStringSupportsOptions() {
Expand All @@ -11,11 +11,10 @@ function toLocaleDateStringSupportsOptions() {
}

export default (toLocaleDateStringSupportsOptions()
? (dateObj, locales) =>
? (dateObj: Date, locales: string) =>
dateObj.toLocaleDateString(locales, {
year: "numeric",
month: "long",
day: "numeric",
})
: // eslint-disable-next-line no-unused-vars
(dateObj, locales) => fecha.format(dateObj, "mediumDate"));
: (dateObj: Date) => fecha.format(dateObj, "mediumDate"));
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fecha from "fecha";
import * as fecha from "fecha";

// Check for support of native locale string options
function toLocaleStringSupportsOptions() {
Expand All @@ -11,13 +11,12 @@ function toLocaleStringSupportsOptions() {
}

export default (toLocaleStringSupportsOptions()
? (dateObj, locales) =>
? (dateObj: Date, locales: string) =>
dateObj.toLocaleString(locales, {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "2-digit",
})
: // eslint-disable-next-line no-unused-vars
(dateObj, locales) => fecha.format(dateObj, "haDateTime"));
: (dateObj: Date) => fecha.format(dateObj, "haDateTime"));
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fecha from "fecha";
import * as fecha from "fecha";

// Check for support of native locale string options
function toLocaleTimeStringSupportsOptions() {
Expand All @@ -11,10 +11,9 @@ function toLocaleTimeStringSupportsOptions() {
}

export default (toLocaleTimeStringSupportsOptions()
? (dateObj, locales) =>
? (dateObj: Date, locales: string) =>
dateObj.toLocaleTimeString(locales, {
hour: "numeric",
minute: "2-digit",
})
: // eslint-disable-next-line no-unused-vars
(dateObj, locales) => fecha.format(dateObj, "shortTime"));
: (dateObj: Date) => fecha.format(dateObj, "shortTime"));
33 changes: 0 additions & 33 deletions src/common/datetime/relative_time.js

This file was deleted.

40 changes: 40 additions & 0 deletions src/common/datetime/relative_time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { LocalizeFunc } from "../../mixins/localize-base-mixin";

/**
* Calculate a string representing a date object as relative time from now.
*
* Example output: 5 minutes ago, in 3 days.
*/
const tests = [60, 60, 24, 7];
const langKey = ["second", "minute", "hour", "day"];

export default function relativeTime(
dateObj: Date,
localize: LocalizeFunc
): string {
let delta = (new Date().getTime() - dateObj.getTime()) / 1000;
const tense = delta >= 0 ? "past" : "future";
delta = Math.abs(delta);

for (let i = 0; i < tests.length; i++) {
if (delta < tests[i]) {
delta = Math.floor(delta);
const timeDesc = localize(
`ui.components.relative_time.duration.${langKey[i]}`,
"count",
delta
);
return localize(`ui.components.relative_time.${tense}`, "time", timeDesc);
}

delta /= tests[i];
}

delta = Math.floor(delta);
const time = localize(
"ui.components.relative_time.duration.week",
"count",
delta
);
return localize(`ui.components.relative_time.${tense}`, "time", time);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const leftPad = (number) => (number < 10 ? `0${number}` : number);
const leftPad = (num: number) => (num < 10 ? `0${num}` : num);

export default function secondsToDuration(d) {
export default function secondsToDuration(d: number) {
const h = Math.floor(d / 3600);
const m = Math.floor((d % 3600) / 60);
const s = Math.floor((d % 3600) % 60);
Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions src/common/entity/attribute_class_names.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/common/entity/attribute_class_names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { HassEntity } from "home-assistant-js-websocket";

export default function attributeClassNames(
stateObj: HassEntity,
attributes: string[]
): string {
if (!stateObj) {
return "";
}
return attributes
.map(
(attribute) =>
attribute in stateObj.attributes ? "has-" + attribute : ""
)
.filter((attr) => attr !== "")
.join(" ");
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { HassEntity } from "home-assistant-js-websocket";

/** Return an icon representing a binary sensor state. */

export default function binarySensorIcon(state) {
var activated = state.state && state.state === "off";
export default function binarySensorIcon(state: HassEntity) {
const activated = state.state && state.state === "off";
switch (state.attributes.device_class) {
case "battery":
return activated ? "hass:battery" : "hass:battery-outline";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default function canToggleDomain(hass, domain) {
import { HomeAssistant } from "../../types";

export default function canToggleDomain(hass: HomeAssistant, domain: string) {
const services = hass.services[domain];
if (!services) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { HassEntity } from "home-assistant-js-websocket";
import canToggleDomain from "./can_toggle_domain";
import computeStateDomain from "./compute_state_domain";
import { HomeAssistant } from "../../types";

export default function canToggleState(hass, stateObj) {
export default function canToggleState(
hass: HomeAssistant,
stateObj: HassEntity
) {
const domain = computeStateDomain(stateObj);
if (domain === "group") {
return stateObj.state === "on" || stateObj.state === "off";
}
if (domain === "climate") {
return !!((stateObj.attributes || {}).supported_features & 4096);
// tslint:disable-next-line
return (stateObj.attributes.supported_features! & 4096) !== 0;
}

return canToggleDomain(hass, domain);
Expand Down
3 changes: 0 additions & 3 deletions src/common/entity/compute_domain.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/common/entity/compute_domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function computeDomain(entityId: string): string {
return entityId.substr(0, entityId.indexOf("."));
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Compute the object ID of a state. */
export default function computeObjectId(entityId) {
export default function computeObjectId(entityId: string): string {
return entityId.substr(entityId.indexOf(".") + 1);
}
84 changes: 0 additions & 84 deletions src/common/entity/compute_state_display.js

This file was deleted.

Loading