Add Support for Temperature and Humidity Sensors + New Config File Format #12

Merged
Bendodroid merged 0 commits from Bendodroid-envSensors into main 2024-01-14 22:02:03 +01:00
Bendodroid commented 2024-01-13 23:31:58 +01:00 (Migrated from gitlab.hamburg.ccc.de)

This MR adds support for the sensors/temperature and sensors/humidity fields.
Also changes the config file format to include the sensor configuration and a new 3-part structure:

{
  // Configure credentials
  "credentials": {
    "home-assistant": {
      "username": "home-assistant",
      "password": "hamiau"
    },
    "dooris-hauptraum": {
      "username": "dooris-hauptraum",
      "password": "doorimiau"
    }
  },
  // Dynamic inputs
  "dynamic": {
    "sensors": {
      "temperature": [
        {
          "sensor_data": {
            "unit": "C",
            "location": "Hauptraum",
            "name": "Kueche",
            "description": "Sensor im Ofen"
          },
          "allowed_credentials": [
            "home-assistant"
          ]
        }
      ],
      "humidity": [
        // Same here
      ]
    },
    "state": {
      "open": {
        "allowed_credentials": [
          "dooris-hauptraum"
        ]
      }
    }
  },
  // Static parts
  "response": {
     "api_compatibility": [
      "14"
    ],
    // ...
  }
}

Fixes #6

TODOs:

  • Handle Temperature and Humidity sensors
    • Parse dynamic config
    • Generate HTTP endpoints
    • Write to response
    • Save to persistent state
    • Merge old state
This MR adds support for the `sensors/temperature` and `sensors/humidity` fields. Also changes the config file format to include the sensor configuration and a new 3-part structure: ```json { // Configure credentials "credentials": { "home-assistant": { "username": "home-assistant", "password": "hamiau" }, "dooris-hauptraum": { "username": "dooris-hauptraum", "password": "doorimiau" } }, // Dynamic inputs "dynamic": { "sensors": { "temperature": [ { "sensor_data": { "unit": "C", "location": "Hauptraum", "name": "Kueche", "description": "Sensor im Ofen" }, "allowed_credentials": [ "home-assistant" ] } ], "humidity": [ // Same here ] }, "state": { "open": { "allowed_credentials": [ "dooris-hauptraum" ] } } }, // Static parts "response": { "api_compatibility": [ "14" ], // ... } } ``` Fixes #6 TODOs: - [x] Handle Temperature and Humidity sensors - [x] Parse dynamic config - [x] Generate HTTP endpoints - [x] Write to response - [x] Save to persistent state - [x] Merge old state
Bendodroid commented 2024-01-13 23:31:58 +01:00 (Migrated from gitlab.hamburg.ccc.de)

assigned to @Bendodroid

assigned to @Bendodroid
Bendodroid commented 2024-01-13 23:35:31 +01:00 (Migrated from gitlab.hamburg.ccc.de)

changed the description

changed the description
Bendodroid commented 2024-01-14 00:57:48 +01:00 (Migrated from gitlab.hamburg.ccc.de)

marked the checklist item Handle Temperature and Humidity sensors as completed

marked the checklist item **Handle Temperature and Humidity sensors** as completed
Bendodroid commented 2024-01-14 00:57:49 +01:00 (Migrated from gitlab.hamburg.ccc.de)

marked the checklist item Parse dynamic config as completed

marked the checklist item **Parse dynamic config** as completed
Bendodroid commented 2024-01-14 00:57:50 +01:00 (Migrated from gitlab.hamburg.ccc.de)

marked the checklist item Generate HTTP endpoints as completed

marked the checklist item **Generate HTTP endpoints** as completed
Bendodroid commented 2024-01-14 00:57:51 +01:00 (Migrated from gitlab.hamburg.ccc.de)

marked the checklist item Write to response as completed

marked the checklist item **Write to response** as completed
Bendodroid commented 2024-01-14 01:01:45 +01:00 (Migrated from gitlab.hamburg.ccc.de)

changed the description

changed the description
Bendodroid commented 2024-01-14 01:22:14 +01:00 (Migrated from gitlab.hamburg.ccc.de)

marked the checklist item Save to persistent state as completed

marked the checklist item **Save to persistent state** as completed
Bendodroid commented 2024-01-14 02:03:34 +01:00 (Migrated from gitlab.hamburg.ccc.de)

added 7 commits

  • c3f51f2e - Rename "static" to "response" for consistency
  • daac0b3b - Change Sensors field type in config and response to map
  • 6e1a8ac0 - Initialize sensors map with static parts when parsing config
  • 38710484 - Generate HTTP endpoints for environment sensors
  • 42483df7 - Update config-template.json with placeholders for environment sensors
  • 44143c0c - Save sensor values to persistent-state.json
  • 70b2e806 - Only pass State struct pointer to StateOpen, not entire response

Compare with previous version

added 7 commits <ul><li>c3f51f2e - Rename &quot;static&quot; to &quot;response&quot; for consistency</li><li>daac0b3b - Change Sensors field type in config and response to map</li><li>6e1a8ac0 - Initialize sensors map with static parts when parsing config</li><li>38710484 - Generate HTTP endpoints for environment sensors</li><li>42483df7 - Update config-template.json with placeholders for environment sensors</li><li>44143c0c - Save sensor values to persistent-state.json</li><li>70b2e806 - Only pass State struct pointer to StateOpen, not entire response</li></ul> [Compare with previous version](/ccchh/spaceapid/-/merge_requests/4/diffs?diff_id=4159&start_sha=b2f62c7bb04978d5f9154946d160abad7d960529)
Bendodroid commented 2024-01-14 02:05:46 +01:00 (Migrated from gitlab.hamburg.ccc.de)

marked the checklist item Merge old state as completed

marked the checklist item **Merge old state** as completed
Bendodroid commented 2024-01-14 02:09:42 +01:00 (Migrated from gitlab.hamburg.ccc.de)

marked this merge request as ready

marked this merge request as **ready**
Bendodroid commented 2024-01-14 02:09:42 +01:00 (Migrated from gitlab.hamburg.ccc.de)

changed the description

changed the description
Bendodroid commented 2024-01-14 02:10:49 +01:00 (Migrated from gitlab.hamburg.ccc.de)

changed the description

changed the description
june commented 2024-01-14 21:16:47 +01:00 (Migrated from gitlab.hamburg.ccc.de)

Does this also handle sensors without a name properly?

Does this also handle sensors without a name properly?
Bendodroid commented 2024-01-14 21:55:10 +01:00 (Migrated from gitlab.hamburg.ccc.de)

changed this line in version 3 of the diff

changed this line in [version 3 of the diff](/ccchh/spaceapid/-/merge_requests/4/diffs?diff_id=4167&start_sha=70b2e8069b9ba724a0dc53d646656a2ad5bb5fd7#0607f785dfa3c3861b3239f6723eb276d8056461_47_45)
Bendodroid commented 2024-01-14 21:55:11 +01:00 (Migrated from gitlab.hamburg.ccc.de)

added 2 commits

  • 04b7efd7 - Open the persistent file just for writing when saving
  • 0241a506 - Handle sensors that don't have a name, just a location

Compare with previous version

added 2 commits <ul><li>04b7efd7 - Open the persistent file just for writing when saving</li><li>0241a506 - Handle sensors that don&#39;t have a name, just a location</li></ul> [Compare with previous version](/ccchh/spaceapid/-/merge_requests/4/diffs?diff_id=4167&start_sha=70b2e8069b9ba724a0dc53d646656a2ad5bb5fd7)
Bendodroid commented 2024-01-14 21:56:56 +01:00 (Migrated from gitlab.hamburg.ccc.de)

It does now uwu

(At least I think so...)

It does now uwu (At least I think so...)
Bendodroid commented 2024-01-14 21:56:56 +01:00 (Migrated from gitlab.hamburg.ccc.de)

resolved all threads

resolved all threads
Bendodroid commented 2024-01-14 22:02:01 +01:00 (Migrated from gitlab.hamburg.ccc.de)

approved this merge request

approved this merge request
Bendodroid (Migrated from gitlab.hamburg.ccc.de) approved these changes 2024-01-14 22:10:54 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: CCCHH/spaceapid#12
No description provided.