Skip to content

Commit

Permalink
fix(nrplus): use relay name
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Oct 31, 2023
1 parent bfb56d0 commit 542f998
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
55 changes: 29 additions & 26 deletions src/NRPlusGatewayTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Lightbulb,
LightbulbOff,
Lock,
RouterIcon,
Thermometer,
UploadCloud,
X,
Expand Down Expand Up @@ -111,18 +112,19 @@ const Node = ({
}) => {
const [configure, setConfigure] = useState<boolean>(false)
const { send } = useWebsocket()
const [relay, setRelay] = useState<Record<string, string | null>>({})
const [relay, setRelay] = useState<Record<string, boolean>>({})

const viaRelay = (id: string) => (payload: string) => {
const relayVia = relay[id]
const viaRelay = (useRelay: boolean) => (payload: string) => {
const command = `dect beacon_rach_tx -t ${id} -d "${payload}"`
if (relayVia !== undefined)
return `dect client_rach_tx --b_name ${relayVia} -d ${JSON.stringify(
if (useRelay)
return `dect client_rach_tx --b_name relay_node -d ${JSON.stringify(
command,
)}`
return command
}

const temp = node.env?.temp ?? node.env?.modemTemp

return (
<>
<dt>
Expand All @@ -138,9 +140,9 @@ const Node = ({
>
<Lightbulb strokeWidth={1} />
</button>
{node.env !== undefined && (
{temp !== undefined && (
<span>
<Thermometer strokeWidth={1} /> {node.env.temp.toFixed(1)} °C
<Thermometer strokeWidth={1} /> {temp.toFixed(1)} °C
</span>
)}
</span>
Expand All @@ -150,23 +152,20 @@ const Node = ({
<button type="button me-1" onClick={() => setConfigure(false)}>
<X strokeWidth={1} />
</button>
<select
onChange={(e) => {
setRelay((r) => ({
...r,
[id]: (e.target as HTMLSelectElement).value,
}))
}}
>
<option selected={relay[id] === undefined}>no relay</option>
{Object.keys(gateway.state.nodes ?? {})
.filter((otherNodeId) => otherNodeId !== id)
.map((otherNodeId) => (
<option selected={otherNodeId === relay[id]}>
{otherNodeId}
</option>
))}
</select>
<label title={'Use relay'} class="mx-1">
<input
type="checkbox"
checked={relay[id] ?? false}
onInput={(e) => {
setRelay((r) => ({
...r,
[id]: (e.target as HTMLInputElement).checked,
}))
}}
class="me-1"
/>
<RouterIcon strokeWidth={1} />
</label>
{[
{ name: 'REMOTE_CTRL', color: 'white' },
{ name: 'RED', color: 'RED' },
Expand All @@ -178,7 +177,9 @@ const Node = ({
type="button me-1"
style={{ color }}
onClick={() => {
const nrplusCtrl = viaRelay(id)(`LED_${name} ON`)
const nrplusCtrl = viaRelay(relay[id] ?? false)(
`LED_${name} ON`,
)
console.log(`[NR+]`, nrplusCtrl)
send({
deviceId: gateway.id,
Expand All @@ -193,7 +194,9 @@ const Node = ({
type="button me-1"
style={{ color }}
onClick={() => {
const nrplusCtrl = viaRelay(id)(`LED_${name} OFF`)
const nrplusCtrl = viaRelay(relay[id] ?? false)(
`LED_${name} OFF`,
)
console.log(`[NR+]`, nrplusCtrl)
send({
deviceId: gateway.id,
Expand Down
2 changes: 1 addition & 1 deletion src/context/Devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export type NRPlusNode = {
}
env?: {
modemTemp: number
temp: number
temp?: number
ts: number
}
btn?: {
Expand Down

0 comments on commit 542f998

Please sign in to comment.