Skip to content

Commit

Permalink
Merge branch 'release/3.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonhochkins committed Nov 21, 2023
2 parents 713910a + c9e8d7a commit f7ba91f
Show file tree
Hide file tree
Showing 12 changed files with 656 additions and 582 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 1.1.1
## create-hakit
- Adjustments to deploy script
- Adjustments to base template

# 3.0.5
## @hakit/components
- BUGFIX - Fixing bug for MediaPlayerCard where groups aren't available it was not rendering the cards

## @hakit/core
- CHANGE - useAreas now has a new returned value called `deviceEntities` which are related children for a matched device. You can merge entities and deviceEntities if you want to display them all.


# 3.0.4
## @hakit/components
Expand Down
26 changes: 23 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hakit/components",
"type": "module",
"version": "3.0.4",
"version": "3.0.5",
"private": false,
"keywords": [
"react",
Expand Down Expand Up @@ -68,7 +68,7 @@
"@emotion/react": ">=10.x",
"@emotion/styled": ">=10.x",
"@fullcalendar/react": "^6.1.9",
"@hakit/core": "^3.0.4",
"@hakit/core": "^3.0.5",
"@use-gesture/react": ">=10.x",
"autolinker": ">=4.x",
"framer-motion": ">=10.x",
Expand Down
12 changes: 3 additions & 9 deletions packages/components/src/Cards/AreaCard/AreaCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Meta, StoryObj } from "@storybook/react";
import { Title, Description, Primary, ArgTypes, Source } from "@storybook/blocks";
import { ThemeProvider, AreaCard, Row, ButtonCard } from "@components";
import type { AreaCardProps } from "@components";
import { useHass } from "@hakit/core";
// @ts-expect-error - Don't have types for jsx-to-string
import jsxToString from "jsx-to-string";
import { HassConnect } from "@hass-connect-fake";
Expand Down Expand Up @@ -70,7 +69,7 @@ function TemplateFull() {
);
}

function UseHashExample() {
const hashExample = `function UseHashExample() {
const { useStore } = useHass();
const setHash = useStore((store) => store.setHash);
return (
Expand All @@ -86,7 +85,7 @@ function UseHashExample() {
/>
</Row>
);
}
}`;

export default {
title: "COMPONENTS/Cards/AreaCard",
Expand All @@ -104,12 +103,7 @@ export default {
You can set the hash programmatically from anywhere and the area will activate! There's a helper hook designed to help with
this!
</p>
<Source
dark
code={jsxToString(UseHashExample(), {
useFunctionCode: true,
})}
/>
<Source dark code={hashExample} />
<h2>Component Props</h2>
<ArgTypes />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ export interface MediaPlayerControlsProps extends ColumnProps {
onStateChange?: (state: string) => void;
}

export const MediaPlayerControls = ({ groupedEntities, allEntityIds, onStateChange, entity, ...rest }: MediaPlayerControlsProps) => {
export const MediaPlayerControls = ({
groupedEntities = [],
allEntityIds = [],
onStateChange,
entity,
...rest
}: MediaPlayerControlsProps) => {
const primaryEntity = useEntity(entity);
const supportsGrouping = supportsFeatureFromAttributes(primaryEntity.attributes, 524288);
// To get proper ordering of speakers, we need to flatten the groupedEntities array while keeping the order of the groups
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hakit/core",
"version": "3.0.4",
"version": "3.0.5",
"private": false,
"type": "module",
"keywords": [
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/hooks/useAreas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface Area {
services: DeviceRegistryEntry[];
/** the entities linked to the area */
entities: HassEntity[];
/** entities related to the matched devices */
deviceEntities: HassEntity[];
}

export function useAreas(): Area[] {
Expand Down Expand Up @@ -52,9 +54,10 @@ export function useAreas(): Area[] {

return useMemo(() => {
return areas.map((area) => {
const matchedEntities = [];
const matchedDevices = [];
const matchedServices = [];
const matchedEntities: HassEntity[] = [];
const matchedDevices: DeviceRegistryEntry[] = [];
const matchedServices: DeviceRegistryEntry[] = [];
const deviceEntities: HassEntity[] = [];

for (const device of devices) {
if (device.area_id === area.area_id) {
Expand All @@ -73,11 +76,11 @@ export function useAreas(): Area[] {
// link the matchedDevices to an entity
for (const device of matchedDevices) {
if (entity.device_id === device.id) {
// first check if matchedEntities contains the entity already
const exists = matchedEntities.find((e) => e.entity_id === entity.entity_id);
// first check if deviceEntities contains the entity already
const exists = deviceEntities.find((e) => e.entity_id === entity.entity_id);
if (!exists) {
if (_entities[entity.entity_id]) {
matchedEntities.push(_entities[entity.entity_id]);
deviceEntities.push(_entities[entity.entity_id]);
}
}
}
Expand All @@ -89,6 +92,7 @@ export function useAreas(): Area[] {
devices: matchedDevices,
services: matchedServices,
entities: matchedEntities,
deviceEntities,
};
});
}, [areas, devices, joinHassUrl, entities, _entities]);
Expand Down
Loading

0 comments on commit f7ba91f

Please sign in to comment.