Skip to content

Commit

Permalink
Added second hot end management
Browse files Browse the repository at this point in the history
  • Loading branch information
repier37 committed Jun 19, 2023
1 parent d75cdb0 commit e31bedb
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/duet-card.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
'sensor.dbot_tool_1_current_temperature' : {
state: 214.7,
attributes: {
unit_of_measurement: "°C"
unit_of_measurement: "°C",
friendly_name: "Coucou"
}
},
'sensor.dbot_tool_2_current_temperature' : {
state: 180.7,
attributes: {
unit_of_measurement: "°C",
friendly_name: "hotend 2"
}
},
'sensor.dbot_tool_bed_current_temperature' : {
Expand Down Expand Up @@ -76,6 +84,7 @@
monitored: [
"Status",
"Hotend",
"Hotend2",
"Bed",
"Elapsed",
"ETA",
Expand Down Expand Up @@ -137,7 +146,7 @@

</style>

<script src='./duetcard.js'></script>
<script src='./duet-card.js'></script>

</head>

Expand All @@ -148,7 +157,7 @@
<duet-card>

</duet-card>
<dueteditor>
<duet-editor>

</duet-editor>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/Components/Stats/TemperatureStat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const temperature = (
temperatureEntity: HassEntity,
config: ThreedyConfig
) => {

if(!temperatureEntity){
return "-";
}
const t: number = parseFloat(temperatureEntity.state);
const u: ThreedyTemperatureUnit = temperatureUnitFromEntity(temperatureEntity);
const tc: number = convertTemperature(t, u, config.temperature_unit || u);
Expand Down
27 changes: 25 additions & 2 deletions src/Components/Stats/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const getEntityName = (
return `${baseName}_time_elapsed`
case 'Hotend':
return `${baseName}_tool_1_current_temperature`
case 'Hotend2':
return `${baseName}_tool_2_current_temperature`
case 'Bed':
return `${baseName}_tool_bed_current_temperature`
case 'Progress':
Expand Down Expand Up @@ -101,14 +103,35 @@ const renderCondition = (
)

case ThreedyCondition.Hotend:
var HotEndEntity = getEntity(hass, getEntityName(config, condition));
var friendlyName = "Hotend";
if(HotEndEntity){
friendlyName = HotEndEntity.attributes.friendly_name;
}

return (
<TemperatureStat
name={"Hotend"}
temperatureEntity={ getEntity(hass,getEntityName(config, condition)) }
name={friendlyName}
temperatureEntity={ HotEndEntity }
config={config}
/>
)

case ThreedyCondition.Hotend2:
var HotEndEntity = getEntity(hass, getEntityName(config, condition));
var friendlyName = "Hotend 2";
console.log("hotend2");
if(HotEndEntity){
friendlyName = HotEndEntity.attributes.friendly_name;
}

return (
<TemperatureStat
name={friendlyName}
temperatureEntity={ HotEndEntity }
config={config}
/>
)

default:
return (
Expand Down
2 changes: 1 addition & 1 deletion src/Configurator/Components/MultiSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {Enum} from "../../../types";

const Item = ({ item, selected, available, reorder, toggle }) => {


console.log("item:", item);
const active = selected.includes(item);
const y = active ? 56 * selected.indexOf(item) : 56 * (selected.length + available.indexOf(item));

Expand Down
20 changes: 18 additions & 2 deletions src/Configurator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ import {

import styles from './styles';
import FewSelector from "./Components/FewSelector";
import {ThreedyCondition, ThreedyPrinter, ThreedyTheme} from '../types';
import {ThreedyCondition, ThreedyConfig, ThreedyPrinter, ThreedyTheme} from '../types';
import { getEntityName } from '../Components/Stats/utils';
import { getEntity } from '../Utils/HomeAssistant';

const HasSecondHotEnd =
(hass, config: ThreedyConfig): boolean =>{
if(!config){
return false;
}

return getEntity(hass, getEntityName(config, ThreedyCondition.Hotend2)) != undefined
}


const Configurator = ({ hass, config, threedy }) => {
Expand All @@ -41,6 +52,9 @@ const Configurator = ({ hass, config, threedy }) => {
updateValue( _updateConfig, key, value);
}

const ShowSecondHotend = HasSecondHotEnd(hass, config);
console.log("second hot end found?", ShowSecondHotend);

if (!config) return (<div/>)

// @ts-ignore
Expand Down Expand Up @@ -75,9 +89,11 @@ const Configurator = ({ hass, config, threedy }) => {
initial={config.name || modifiedConfig.name}
/>


<p style={{ ...styles.Label }}>Monitored</p>
<MultiSelector
items={ ThreedyCondition }
items={ShowSecondHotend ? ThreedyCondition : Object.values(ThreedyCondition).filter(item => item !== ThreedyCondition.Hotend2)}
// items={ ThreedyCondition }
initial={config.monitored}
onChange={selectedValues => _updateValue('monitored', selectedValues)}
/>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum ThreedyCondition {
ETA = "ETA",
Elapsed = "Elapsed",
Hotend = "Hotend",
Hotend2 = "Hotend2",
Bed = "Bed",
Remaining = "Remaining",
Progress = 'Progress'
Expand Down

0 comments on commit e31bedb

Please sign in to comment.