diff --git a/package-lock.json b/package-lock.json index 0e25c26..91402d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "mui-tel-input": "^7.0.0", "notistack": "^3.0.1", "openweathermap-ts": "^1.2.10", - "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", + "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#hdc302_component", "query-string": "^9.2.1", "react": "^18.3.1", "react-beautiful-dnd": "^13.1.1", @@ -10953,7 +10953,7 @@ }, "node_modules/protobuf-ts": { "version": "1.0.0", - "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#3f647071f211c4552c2acc23a8ecabb6904a4156", + "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#fd7268ad8f3bea8e6aa7f27104dcd8ccdf52de62", "dependencies": { "protobufjs": "^6.8.8" } diff --git a/package.json b/package.json index fc7a1ac..3520428 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "mui-tel-input": "^7.0.0", "notistack": "^3.0.1", "openweathermap-ts": "^1.2.10", - "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", + "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#hdc302_component", "query-string": "^9.2.1", "react": "^18.3.1", "react-beautiful-dnd": "^13.1.1", diff --git a/src/pbHelpers/AddressTypes/I2C.ts b/src/pbHelpers/AddressTypes/I2C.ts index b6bf585..d2f1733 100644 --- a/src/pbHelpers/AddressTypes/I2C.ts +++ b/src/pbHelpers/AddressTypes/I2C.ts @@ -18,7 +18,8 @@ export const I2C: AddressTypeExtension = { [quack.ComponentType.COMPONENT_TYPE_SEN5X, 0x68], [quack.ComponentType.COMPONENT_TYPE_AIRFLOW, 0x6b], [quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE, 0x70], - [quack.ComponentType.COMPONENT_TYPE_DRAGER_GAS_DONGLE, 0x6c] + [quack.ComponentType.COMPONENT_TYPE_DRAGER_GAS_DONGLE, 0x6c], + [quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, 0x43] ]); const offset = offsets.get(componentType); diff --git a/src/pbHelpers/ComponentType.tsx b/src/pbHelpers/ComponentType.tsx index 03be638..25a0440 100644 --- a/src/pbHelpers/ComponentType.tsx +++ b/src/pbHelpers/ComponentType.tsx @@ -60,6 +60,7 @@ import { LineData, Point } from "charts/measurementCharts/MultiLineGraph"; import moment, { Moment } from "moment"; import { avg } from "utils"; import { Airflow } from "./ComponentTypes/Airflow"; +import { TempHumidity } from "./ComponentTypes/TempHumidity"; const COMPONENT_TYPE_MAP = new Map([ [quack.ComponentType.COMPONENT_TYPE_INVALID, Invalid], @@ -96,7 +97,8 @@ const COMPONENT_TYPE_MAP = new Map([ [quack.ComponentType.COMPONENT_TYPE_SEN5X, Sen5x], [quack.ComponentType.COMPONENT_TYPE_VIBRATION_CHAIN, VibrationCable], [quack.ComponentType.COMPONENT_TYPE_DRAGER_GAS_DONGLE, dragerGasDongle], - [quack.ComponentType.COMPONENT_TYPE_AIRFLOW, Airflow] + [quack.ComponentType.COMPONENT_TYPE_AIRFLOW, Airflow], + [quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, TempHumidity] ]); export interface Subtype { diff --git a/src/pbHelpers/ComponentTypes/TempHumidity.ts b/src/pbHelpers/ComponentTypes/TempHumidity.ts new file mode 100644 index 0000000..50542ed --- /dev/null +++ b/src/pbHelpers/ComponentTypes/TempHumidity.ts @@ -0,0 +1,85 @@ +import TemperatureHumidityDarkIcon from "assets/components/temperatureHumidityDark.png"; +import TemperatureHumidityLightIcon from "assets/components/temperatureHumidityLight.png"; +import { convertedUnitMeasurement } from "models/UnitMeasurement"; +import { + AreaChartData, + ComponentTypeExtension, + GraphFilters, + LineChartData, + simpleAreaChartData, + simpleLineChartData, + simpleMeasurements, + simpleSummaries, + Summary, + unitMeasurementSummaries +} from "pbHelpers/ComponentType"; +import { describeMeasurement } from "pbHelpers/MeasurementDescriber"; +import { pond } from "protobuf-ts/pond"; +import { quack } from "protobuf-ts/quack"; + +export function TempHumidity(subtype: number = 0): ComponentTypeExtension { + let temperature = describeMeasurement( + quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE, + quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, + subtype + ); + let humidity = describeMeasurement( + quack.MeasurementType.MEASUREMENT_TYPE_PERCENT, + quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, + subtype + ); + return { + type: quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, + subtypes: [ + { + key: quack.TempHumiditySubtype.TEMP_HUMIDITY_SUBTYPE_HDC302, + value: "TEMP_HUMIDITY_SUBTYPE_HDC302", + friendlyName: "HDC302" + } + ], + friendlyName: "Temperature/Humidity", + description: "Measures the temperature and humidity", + isController: false, + isSource: true, + isCalibratable: true, + addressTypes: [quack.AddressType.ADDRESS_TYPE_I2C], + interactionResultTypes: [], + states: [], + measurements: simpleMeasurements(temperature, humidity), + measurementSummary: async function(measurement: quack.Measurement): Promise> { + return simpleSummaries(measurement, temperature, humidity); + }, + unitMeasurementSummary: ( + measurements: convertedUnitMeasurement + ): Summary[] => { + return unitMeasurementSummaries( + measurements, + quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, + subtype + ); + }, + areaChartData: ( + measurement: pond.UnitMeasurementsForComponent, + smoothingAverages?: number, + filters?: GraphFilters + ): AreaChartData => { + return simpleAreaChartData(measurement, smoothingAverages, filters); + }, + lineChartData: ( + measurement: pond.UnitMeasurementsForComponent, + smoothingAverages?: number, + filters?: GraphFilters + ): LineChartData => { + return simpleLineChartData( + quack.ComponentType.COMPONENT_TYPE_TEMP_HUMIDITY, + measurement, + smoothingAverages, + filters + ); + }, + minMeasurementPeriodMs: 1000, + icon: (theme?: "light" | "dark"): string | undefined => { + return theme === "light" ? TemperatureHumidityDarkIcon : TemperatureHumidityLightIcon; + } + }; +} diff --git a/src/pbHelpers/DeviceAvailability.ts b/src/pbHelpers/DeviceAvailability.ts index 972c2e2..6ade54b 100644 --- a/src/pbHelpers/DeviceAvailability.ts +++ b/src/pbHelpers/DeviceAvailability.ts @@ -64,7 +64,8 @@ const DefaultAvailability: DeviceAvailabilityMap = new Map